|
1 |
| -/****************************************************************************** |
2 |
| - * Copyright 2018 Google |
3 |
| - * Licensed under the Apache License, Version 2.0 (the "License"); |
4 |
| - * you may not use this file except in compliance with the License. |
5 |
| - * You may obtain a copy of the License at |
6 |
| - * |
7 |
| - * http://www.apache.org/licenses/LICENSE-2.0 |
8 |
| - * |
9 |
| - * Unless required by applicable law or agreed to in writing, software |
10 |
| - * distributed under the License is distributed on an "AS IS" BASIS, |
11 |
| - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
12 |
| - * See the License for the specific language governing permissions and |
13 |
| - * limitations under the License. |
14 |
| - *****************************************************************************/ |
15 |
| -#include "esp32-mqtt.h" |
16 |
| - |
17 |
| -#ifndef LED_BUILTIN |
18 |
| - #define LED_BUILTIN 13 |
19 |
| -#endif |
20 |
| - |
21 |
| -void setup() { |
22 |
| - // put your setup code here, to run once: |
23 |
| - Serial.begin(115200); |
24 |
| - pinMode(LED_BUILTIN, OUTPUT); |
25 |
| - setupCloudIoT(); |
26 |
| -} |
27 |
| - |
28 |
| -unsigned long lastMillis = 0; |
29 |
| -void loop() { |
30 |
| - mqttClient->loop(); |
31 |
| - delay(10); // <- fixes some issues with WiFi stability |
32 |
| - |
33 |
| - if (!mqttClient->connected()) { |
34 |
| - connect(); |
35 |
| - } |
36 |
| - |
37 |
| - // publish a message roughly every second. |
38 |
| - if (millis() - lastMillis > 1000) { |
39 |
| - lastMillis = millis(); |
40 |
| - publishTelemetry(getDefaultSensor()); |
41 |
| - } |
42 |
| -} |
| 1 | +/****************************************************************************** |
| 2 | + * Copyright 2018 Google |
| 3 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | + * you may not use this file except in compliance with the License. |
| 5 | + * You may obtain a copy of the License at |
| 6 | + * |
| 7 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | + * |
| 9 | + * Unless required by applicable law or agreed to in writing, software |
| 10 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | + * See the License for the specific language governing permissions and |
| 13 | + * limitations under the License. |
| 14 | + *****************************************************************************/ |
| 15 | +#include "esp32-mqtt.h" |
| 16 | + |
| 17 | +void setup() { |
| 18 | + // put your setup code here, to run once: |
| 19 | + Serial.begin(115200); |
| 20 | + pinMode(LED_BUILTIN, OUTPUT); |
| 21 | + setupCloudIoT(); |
| 22 | +} |
| 23 | + |
| 24 | +unsigned long lastMillis = 0; |
| 25 | +void loop() { |
| 26 | + mqttClient->loop(); |
| 27 | + delay(10); // <- fixes some issues with WiFi stability |
| 28 | + |
| 29 | + if (!mqttClient->connected()) { |
| 30 | + connect(); |
| 31 | + } |
| 32 | + |
| 33 | + // publish a message roughly every second. |
| 34 | + if (millis() - lastMillis > 1000) { |
| 35 | + lastMillis = millis(); |
| 36 | + publishTelemetry(getDefaultSensor()); |
| 37 | + } |
| 38 | +} |
0 commit comments