I am trying to have a mesh network which one of them is Gateway and it need to be connect to WIFI and internet to transfer data by MQTT. I am using PainlessMesh to create the mesh.
Issue I have When I am adding IotWebConf setting as minimal version to start with, some times it isn't showing any access point, some times showing ESP-xxxx, if AP name show up in wifi list in PC. I couldn't understand why it is not connecting to WIFI
My simplified code is here, please let me know what can be wrong
`
include
include
include
include
include
include
define MESH_PREFIX "whateverYouLike"
define MESH_PASSWORD "somethingSneaky"
define MESH_PORT 5555
define STATION_SSID "stTest"
define STATION_PASSWORD "StTestPass"
define HOSTNAME "MQTT_Bridge"
define STATUS_PIN LED_BUILTIN
// -- Initial name of the Thing. Used e.g. as SSID of the own Access Point.
const char thingName[] = "testThing";
// -- Initial password to connect to the Thing, when it creates an own Access Point.
const char wifiInitialApPassword[] = "123456";
// -- Initializing the configuration.
//iotWebConf.setStatusPin(STATUS_PIN);
iotWebConf.init();
mqttClient.setServer(mqtt_server, 1883);//connecting to mqtt server
mqttClient.setCallback(mqttCallback);
mesh.setDebugMsgTypes( ERROR | STARTUP | CONNECTION ); // set before init() so that you can see startup messages
// Channel set to 6. Make sure to use the same channel for your mesh and for you other
// network (STATION_SSID)
mesh.init( MESH_PREFIX, MESH_PASSWORD, MESH_PORT, WIFI_STA, 6 );
mesh.onReceive(&receivedCallback);
mesh.onNewConnection(&newConnectionCallback);
mesh.onChangedConnections(&changedConnectionCallback);
mesh.onNodeTimeAdjusted(&nodeTimeAdjustedCallback);
mesh.onDroppedConnection([](auto nodeId) {
// Do something with the event
Serial.println("------Droped node "+String(nodeId));
Serial.printf("--> Droped: \n", mesh.subConnectionJson().c_str());
// Bridge node, should (in most cases) be a root node. See the wiki for some background
mesh.setRoot(true);
// This node and all other nodes should ideally know the mesh contains a root, so call this on all nodes
mesh.setContainsRoot(true);
// -- Set up required URL handlers on the web server.
server.on("/", handleRoot);
server.on("/config", []{ iotWebConf.handleConfig(); });
server.onNotFound([](){ iotWebConf.handleNotFound(); });
Serial.println("Ready.!!!!!!!!!!!!!!!!!!!!!");
}
void loop() {
// -- doLoop should be called as frequently as possible.
iotWebConf.doLoop();
mesh.update();
mqttClient.loop();
// if(myIP != getlocalIP()){
// myIP = getlocalIP();
// Serial.println("My IP is " + myIP.toString());
Handle web requests to "/" path.
*/
void handleRoot()
{
// -- Let IotWebConf test and handle captive portal requests.
if (iotWebConf.handleCaptivePortal())
{
// -- Captive portal request were already served.
return;
}
String s = "<!DOCTYPE html><html lang=\"en\">
<meta name=\"viewport\" content=\"width=device-width, initial-scale=1, user-scalable=no\"/>";
s += "IotWebConf 01 Minimal";
s += "Go to configure page to change settings.";
s += "
I am trying to have a mesh network which one of them is Gateway and it need to be connect to WIFI and internet to transfer data by MQTT. I am using PainlessMesh to create the mesh. Issue I have When I am adding IotWebConf setting as minimal version to start with, some times it isn't showing any access point, some times showing ESP-xxxx, if AP name show up in wifi list in PC. I couldn't understand why it is not connecting to WIFI My simplified code is here, please let me know what can be wrong
`
include
include
include
include
include
include
define MESH_PREFIX "whateverYouLike"
define MESH_PASSWORD "somethingSneaky"
define MESH_PORT 5555
define STATION_SSID "stTest"
define STATION_PASSWORD "StTestPass"
define HOSTNAME "MQTT_Bridge"
define STATUS_PIN LED_BUILTIN
// -- Initial name of the Thing. Used e.g. as SSID of the own Access Point. const char thingName[] = "testThing";
// -- Initial password to connect to the Thing, when it creates an own Access Point. const char wifiInitialApPassword[] = "123456";
// Prototypes void handleRoot(); void receivedCallback( const uint32_t &from, const String &msg ); void newConnectionCallback(uint32_t nodeId); void changedConnectionCallback(); void nodeTimeAdjustedCallback(int32_t offset);
void mqttCallback(char topic, byte payload, unsigned int length); String splitStringByIndex(String data, char separator, int index); int countAttributes(String data, char separator);
IPAddress getlocalIP();
IPAddress myIP(0,0,0,0);
const char* mqtt_server = "MQTT_Server_Address"; //mqtt server
painlessMesh mesh; WiFiClient wifiClient; PubSubClient mqttClient(wifiClient);
DNSServer dnsServer; WebServer server(80);
IotWebConf iotWebConf(thingName, &dnsServer, &server, wifiInitialApPassword);
void setup() { Serial.begin(115200); Serial.println(); Serial.println("Starting up...");
// -- Initializing the configuration. //iotWebConf.setStatusPin(STATUS_PIN); iotWebConf.init();
mqttClient.setServer(mqtt_server, 1883);//connecting to mqtt server mqttClient.setCallback(mqttCallback);
mesh.setDebugMsgTypes( ERROR | STARTUP | CONNECTION ); // set before init() so that you can see startup messages
// Channel set to 6. Make sure to use the same channel for your mesh and for you other // network (STATION_SSID) mesh.init( MESH_PREFIX, MESH_PASSWORD, MESH_PORT, WIFI_STA, 6 ); mesh.onReceive(&receivedCallback); mesh.onNewConnection(&newConnectionCallback); mesh.onChangedConnections(&changedConnectionCallback); mesh.onNodeTimeAdjusted(&nodeTimeAdjustedCallback); mesh.onDroppedConnection([](auto nodeId) { // Do something with the event Serial.println("------Droped node "+String(nodeId)); Serial.printf("--> Droped: \n", mesh.subConnectionJson().c_str());
// mesh.stationManual(STATION_SSID, STATION_PASSWORD); // mesh.setHostname(HOSTNAME);
// Bridge node, should (in most cases) be a root node. See the wiki for some background mesh.setRoot(true); // This node and all other nodes should ideally know the mesh contains a root, so call this on all nodes mesh.setContainsRoot(true);
// -- Set up required URL handlers on the web server. server.on("/", handleRoot); server.on("/config", []{ iotWebConf.handleConfig(); }); server.onNotFound([](){ iotWebConf.handleNotFound(); });
Serial.println("Ready.!!!!!!!!!!!!!!!!!!!!!");
}
void loop() {
// -- doLoop should be called as frequently as possible. iotWebConf.doLoop();
mesh.update(); mqttClient.loop();
// if(myIP != getlocalIP()){ // myIP = getlocalIP(); // Serial.println("My IP is " + myIP.toString());
// if (mqttClient.connect("helix")) { // Serial.println("########## mqttClient Connected ############"); // //mqttClient.publish("/iot/Mesh/attrs/","Ready!"); // //mqttClient.subscribe("/iot/Mesh/attrs/#"); // } // } }
/**
Handle web requests to "/" path. */ void handleRoot() { // -- Let IotWebConf test and handle captive portal requests. if (iotWebConf.handleCaptivePortal()) { // -- Captive portal request were already served. return; } String s = "<!DOCTYPE html><html lang=\"en\">
<meta name=\"viewport\" content=\"width=device-width, initial-scale=1, user-scalable=no\"/>"; s += "