Merge pull request #279 from PhirePhly/esp8266_example_fixes
ESP8266 example fixes
This commit is contained in:
commit
7dd2ff90a9
@ -29,8 +29,9 @@ const char* mqtt_server = "broker.mqtt-dashboard.com";
|
|||||||
|
|
||||||
WiFiClient espClient;
|
WiFiClient espClient;
|
||||||
PubSubClient client(espClient);
|
PubSubClient client(espClient);
|
||||||
long lastMsg = 0;
|
unsigned long lastMsg = 0;
|
||||||
char msg[50];
|
#define MSG_BUFFER_SIZE (50)
|
||||||
|
char msg[MSG_BUFFER_SIZE];
|
||||||
int value = 0;
|
int value = 0;
|
||||||
|
|
||||||
void setup_wifi() {
|
void setup_wifi() {
|
||||||
@ -115,11 +116,11 @@ void loop() {
|
|||||||
}
|
}
|
||||||
client.loop();
|
client.loop();
|
||||||
|
|
||||||
long now = millis();
|
unsigned long now = millis();
|
||||||
if (now - lastMsg > 2000) {
|
if (now - lastMsg > 2000) {
|
||||||
lastMsg = now;
|
lastMsg = now;
|
||||||
++value;
|
++value;
|
||||||
snprintf (msg, 50, "hello world #%ld", value);
|
snprintf (msg, MSG_BUFFER_SIZE, "hello world #%ld", value);
|
||||||
Serial.print("Publish message: ");
|
Serial.print("Publish message: ");
|
||||||
Serial.println(msg);
|
Serial.println(msg);
|
||||||
client.publish("outTopic", msg);
|
client.publish("outTopic", msg);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user