code edit

This commit is contained in:
Siwat Sirichai 2019-08-21 19:31:52 +07:00
parent feb8decd23
commit 5c7d1b691a
1 changed files with 69 additions and 2 deletions

View File

@ -1,9 +1,76 @@
#include "settings.h"
#include <ESP8266MQTTMesh.h>
#include <FS.h>
#define FIRMWARE_ID 0x1337
#define FIRMWARE_VER "0.1"
wifi_conn networks[] = {WIFI_CONN("ssid 1", NETWORK_PASSWORD, NULL, 0),WIFI_CONN("ssid 2", NETWORK_PASSWORD, NULL, 0),NULL,};
const char* mesh_password = MESH_PASSWORD;
const char* mqtt_server = MQTT_SERVER;
const int mqtt_port = MQTT_PORT;
#if ASYNC_TCP_SSL_ENABLED
const uint8_t *mqtt_fingerprint = MQTT_FINGERPRINT;
bool mqtt_secure = MQTT_SECURE;
#if MESH_SECURE
#include "ssl_cert.h"
#endif
#endif
#ifdef ESP32
String ID = String((unsigned long)ESP.getEfuseMac());
#else
String ID = String(ESP.getChipId());
#endif
unsigned long previousMillis = 0;
const long interval = 5000;
int cnt = 0;
// Note: All of the '.set' options below are optional. The default values can be
// found in ESP8266MQTTMeshBuilder.h
ESP8266MQTTMesh mesh = ESP8266MQTTMesh::Builder(networks, mqtt_server, mqtt_port).setVersion(FIRMWARE_VER, FIRMWARE_ID).setMeshPassword(mesh_password).build();
void callback(const char *topic, const char *msg);
void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
delay(1000); //This is only here to make it easier to catch the startup messages. It isn't required
mesh.setCallback(callback);
mesh.begin();
}
void loop() {
// put your main code here, to run repeatedly:
if (! mesh.connected())
return;
unsigned long currentMillis = millis();
if (currentMillis - previousMillis >= interval) {
String cntStr = String(cnt);
String msg = "hello from " + ID + " cnt: " + cntStr;
mesh.publish(ID.c_str(), msg.c_str());
previousMillis = currentMillis;
cnt++;
}
}
void callback(const char *topic, const char *msg) {
Serial.print(topic);
Serial.print(msg);
}