#include #include #include #include #include #include #include const byte last_mac = ID; int id = ID; byte mac[] = { 0x02, 0x00, 0x00, 0x7A, 0x38, last_mac }; IPAddress ip (192, 168, 8, 100+id); IPAddress server(SERVEUR_MQTT); uint32_t lastReconnectAttempt = 0; unsigned long check; //Just Header void callback(char* topic, byte* payload, unsigned int length); boolean connection(); EthernetClient ethClient; PubSubClient client(server, PORT, callback, ethClient); struct TopicParametre { String topic; int parametre; int defaut; boolean subscribe; boolean define; }; std::vector topic_parametre; void AddParametre (String topic, int defaut){ String sujet = String(id)+"/"+topic; TopicParametre valeure; valeure.topic = sujet; valeure.subscribe = false; valeure.define = false; valeure.defaut = defaut; topic_parametre.push_back(valeure); Serial.println("add"); } void callback(char* topic, byte* payload, unsigned int length) { Serial.print("Message arrived ["); Serial.print(topic); Serial.print("] "); for (int i=0;i 20000) { ESP.restart(); } if (!client.connected()) { Serial.println("=== MQTT NOT CONNECTED ==="); // Reconnect every 10 seconds uint32_t t = millis(); if (t - lastReconnectAttempt > 10000L) { lastReconnectAttempt = t; if (connection()) { lastReconnectAttempt = 0; } } return false; } //NO-USE - Pour tester la connexion avec la carte ethernet if (Ethernet.linkStatus() == LinkOFF) { } else if (Ethernet.linkStatus() == LinkON) { } else { } } boolean publish(String topic, String msg){ String sujet = String(id)+"/"+topic; return (client.publish(sujet.c_str(),msg.c_str()) == 1); } int ReadParametre (String topic){ //String sujet = String(ID)+"/"+topic; for(auto val:topic_parametre){ String sujet = String(id)+"/"+topic; if(sujet == val.topic){ if(val.define){ return val.parametre; } else { return val.defaut; } } } } void ResetValues (){ for(auto& val:topic_parametre){ val.define = false; } }