Skip to content
This repository was archived by the owner on Jan 6, 2023. It is now read-only.

Commit ffff171

Browse files
authored
Set LED_BUILTIN for generic modules (#81)
* Update Esp32-lwmqtt.ino * Update Esp8266-lwmqtt.ino
1 parent de457a8 commit ffff171

File tree

2 files changed

+83
-75
lines changed

2 files changed

+83
-75
lines changed
Lines changed: 41 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,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-
}
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+
}
3842
}
Lines changed: 42 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,43 @@
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 "esp8266_mqtt.h"
16-
17-
void setup() {
18-
// put your setup code here, to run once:
19-
Serial.begin(115200);
20-
setupCloudIoT(); // Creates globals for MQTT
21-
pinMode(LED_BUILTIN, OUTPUT);
22-
startMQTT();
23-
}
24-
25-
unsigned long lastMillis = 0;
26-
void loop() {
27-
mqttClient->loop();
28-
delay(10); // <- fixes some issues with WiFi stability
29-
30-
if (!mqttClient->connected()) {
31-
connect();
32-
}
33-
34-
// publish a message roughly every second.
35-
if (millis() - lastMillis > 1000) {
36-
lastMillis = millis();
37-
publishTelemetry(getDefaultSensor());
38-
}
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 "esp8266_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+
setupCloudIoT(); // Creates globals for MQTT
25+
pinMode(LED_BUILTIN, OUTPUT);
26+
startMQTT();
27+
}
28+
29+
unsigned long lastMillis = 0;
30+
void loop() {
31+
mqttClient->loop();
32+
delay(10); // <- fixes some issues with WiFi stability
33+
34+
if (!mqttClient->connected()) {
35+
connect();
36+
}
37+
38+
// publish a message roughly every second.
39+
if (millis() - lastMillis > 1000) {
40+
lastMillis = millis();
41+
publishTelemetry(getDefaultSensor());
42+
}
3943
}

0 commit comments

Comments
 (0)