/**************************************** Date création : 06/11/2017 Version : 0.5.4 Version IDE Arduino : 1.8.4 Upload speed : 921600 Type de carte dans l'IDE : "Wemos D1 R2 & mini" Carte physique employée : ESP8266 D1 Mini NodeMcu (https://www.amazon.fr/gp/product/B01ELFAF1S/ref=oh_aui_detailpage_o00_s00?ie=UTF8&psc=1) Pin Function ESP-8266 Pin Utilisation locale --------------------------------------------------------------------------------------------- TX TXD TXD RX RXD RXD A0 Analog input, max 3.3V input A0 D0 IO GPIO16 * A tester ! D1 IO, SCL GPIO5 LCD D2 IO, SDA GPIO4 LCD D3 IO,10k Pull-up GPIO0 raccordé à 3.3v pour fonctionnement normal D4 IO, 10k pull-up, BUILTIN_LED GPIO2 Sondes temps D5 IO, SCK GPIO14 Rel1 D6 IO, MISO GPIO12 Rel2 D7 IO, MOSI GPIO13 * A tester ! D8 IO,10k pull-down, SS GPIO15 Bouton G Ground GND 5V 5V – 3V3 3.3V 3.3V RST Reset RST ****************************************/ #include #include "EIoTCloudRestApiV1.0.h" #include #include #include #include // config Telegram #include #include #define BOT_TOKEN "********" // your Bot Token (Get from Botfather) #define CHAT_ID "********" // Chat ID of where you want the message to go (You can use MyIdBot to get the chat ID) WiFiClientSecure sslclient; UniversalTelegramBot bot(BOT_TOKEN, sslclient); String message = ""; // NTP // ----- /!\ ----- Il faut supprimer les fichiers NTPClient.cpp & NTPClient.h du répertoire "esp8266-weather-station-master" (sinon confli de lib ntp) #include #include WiFiUDP ntpUDP; NTPClient LocalTimeClient(ntpUDP, "fr.pool.ntp.org", 7200, 20000); // Weather #include #include const int UPDATE_WEATHER_INTERVAL_MINS = 30; const String WUNDERGRROUND_API_KEY = "f3a6b40f355f4ed8"; const String WUNDERGRROUND_LANGUAGE = "EN"; const String WUNDERGROUND_COUNTRY = "FR"; const String WUNDERGROUND_CITY = "SAINT-MEDARD-EN-JALLES"; long Millis_Last_Download_Weather = millis(); WundergroundClient wunderground(true); // wifi const char AP_SSID[] = "******"; const char AP_PASSWORD[] = "******"; // cloud //EIoTCloudRestApi eiotcloud; #define EIOTCLOUD_USERNAME "******" #define EIOTCLOUD_PASSWORD "******" #define EIOT_CLOUD_ADDRESS "cloud.iot-playground.com" MQTT myMqtt("", EIOT_CLOUD_ADDRESS, 1883); #define TOKEN "******" #define MODULE_ID_TEMPS "2" #define INSTANCE_ID "************" String valueStr(""); // DS18B20 const int UPDATE_TEMPS_INTERVAL_MINS = 10; long lastGetTemps = millis(); OneWire ds(D4); DallasTemperature DS18B20(&ds); DeviceAddress SONDE_PISCINE_ADDRESS = { 0x28, 0x90, 0xF2, 0x1E, 0x00, 0x00, 0x80, 0x2B }; float Temp_Eau = 85.00; String Sonde_Eau_Id= ""; // Relais #define PIN_REL_POMPE D5 void setup(){ Serial.begin(115200); // init IoT //eiotcloud.begin(AP_SSID, AP_PASSWORD); delay(500); //eiotcloud.SetToken(TOKEN); // Get sensors ID // Sonde_Eau_Id= eiotcloud.GetModuleParameterByName(MODULE_ID_TEMPS, "Sensor.Temp_Eau"); // Def client ID String clientName; uint8_t mac[6]; WiFi.macAddress(mac); clientName += macToStr(mac); clientName += "-"; clientName += String(micros() & 0xff, 16); //myMqtt.setClientId((char*) clientName.c_str()); // setup callbacks //myMqtt.onConnected(myConnectedCb); //myMqtt.onDisconnected(myDisconnectedCb); //myMqtt.onPublished(myPublishedCb); //myMqtt.onData(myDataCb); //myMqtt.setUserPwd(EIOTCLOUD_USERNAME, EIOTCLOUD_PASSWORD); //myMqtt.connect(); // Init Output pinMode(PIN_REL_POMPE, OUTPUT); digitalWrite(PIN_REL_POMPE, HIGH); // Init NTP LocalTimeClient.begin(); LocalTimeClient.update(); delay(1000); // Init Weather UpdateWeather(); // Init Temps UpdateTemps(); } void loop() { // NTP set LocalTimeClient.update(); // Weather if (millis() - Millis_Last_Download_Weather > 60000 * UPDATE_WEATHER_INTERVAL_MINS) { UpdateWeather(); Millis_Last_Download_Weather = millis(); } // TEMPS Get & send every 10 minutes if (millis() - lastGetTemps > 60000 * UPDATE_TEMPS_INTERVAL_MINS) { UpdateTemps(); lastGetTemps = millis(); } } // Pump functions void PompeOn(String Source){ digitalWrite(PIN_REL_POMPE, LOW); valueStr = String(1); //myMqtt.publish("/1/Sensor.Parameter1",valueStr, 1, 1); } void PompeOff(String Source){ digitalWrite(PIN_REL_POMPE, HIGH); valueStr = String(0); //myMqtt.publish("/1/Sensor.Parameter1",valueStr, 1, 1); } // Temerature function void UpdateTemps(){ DS18B20.requestTemperatures(); Temp_Eau = DS18B20.getTempC(SONDE_PISCINE_ADDRESS); // if (Temp_Eau != 85.00 && Temp_Eau != (-127.00)) // eiotcloud.SetParameterValue(Sonde_Eau_Id, String(Temp_Eau,1)); } // Weather function void UpdateWeather() { sendTelegramMessage("Test send ..."); sendTelegramMessage(LocalTimeClient.getFormattedTime()); wunderground.updateConditions(WUNDERGRROUND_API_KEY, WUNDERGRROUND_LANGUAGE, WUNDERGROUND_COUNTRY, WUNDERGROUND_CI wunderground.updateForecast(WUNDERGRROUND_API_KEY, WUNDERGRROUND_LANGUAGE, WUNDERGROUND_COUNTRY, WUNDERGROUND_CITY); delay(1000); } //Cloud functions void myDataCb(String& topic, String& data) { if (topic == String("/1/Sensor.Parameter1")) { if (data == String("1")) digitalWrite(PIN_REL_POMPE, LOW); else digitalWrite(PIN_REL_POMPE, HIGH); //myMqtt.publish(topic, data, 1, 1); } } void myConnectedCb() { Serial.println("Connection OK "); subscribe(); } void myDisconnectedCb() { Serial.println("disconnected. try to reconnect..."); delay(500); //myMqtt.connect(); } void myPublishedCb() { Serial.println("published."); } void subscribe(){ //myMqtt.subscribe("/1/Sensor.Parameter1",1); } String macToStr(const uint8_t* mac){ // Convertion adresse MAC en STR String result; for (int i = 0; i < 6; ++i) { result += String(mac[i], 16); if (i < 5) result += ':'; } return result; } void sendTelegramMessage(String Content) { String message = Content; message.concat("\n"); if(bot.sendMessage(CHAT_ID, message, "Markdown")){ Serial.println("TELEGRAM Successfully sent"); } }