// * Server_ESP32_wifi_for_Processing_client_220119 // * Ce serveur lit 2 sondes de température et envoie leurs valeurs via WiFi // * sur le reseau local où un PC/RPI sour Processing les reçoit et les affiche // * Si aucuner sonde n'est connectée, en general on trouve 127 comme valeur // * Une fois lancé, executer le code client // * "Processing_client_for_ESP32_server220119.pde" // * sur un PC (ou RPI) sur le reseau local et sous Processing /* ref Rui Santos pour le sketch d'origine Complete project details at http://randomnerdtutorials.com Adapté pour deux sondes de température onewire *********/ // Including the ESP8266 WiFi library //#include //Au choix #include "WiFi.h" #include #include // Replace with your network details const char* ssid = "xxxx"; // Identifiant WiFi const char* password = "xxx"; float tempA; float tempB; // Data wire is plugged into pin on the ESP8266 1E - GPIO 2 #define ONE_WIRE_BUS 2 // Setup a oneWire instance to communicate with any OneWire devices (not just Maxim/Dallas temperature ICs) OneWire oneWire(ONE_WIRE_BUS); // Pass our oneWire reference to Dallas Temperature. DallasTemperature DS18B20(&oneWire); String temperatureAString; String temperatureBString; int total_Sensors; // Web Server on port 12345 WiFiServer server(12345); void setup() { // Initializing serial port for debugging purposes Serial.begin(115200); delay(100); // Start up the library DS18B20.begin(); delay(100); // locate devices on the bus Serial.print("Found "); Serial.print(DS18B20.getDeviceCount(), DEC); Serial.println(" devices."); pinMode (2,INPUT); pinMode (5, OUTPUT); delay(10); //DS18B20.begin(); // IC Default 9 bit. If you have troubles consider upping it 12. Ups the delay giving the IC more time to process the temperature measurement // Connecting to WiFi network Serial.println(); Serial.print("Connecting to "); Serial.println(ssid); WiFi.begin(ssid, password); while (WiFi.status() != WL_CONNECTED) { delay(500); Serial.print("."); } Serial.println(""); Serial.println("WiFi connected"); // Starting the web server server.begin(); Serial.println("Web server running. Waiting for the ESP IP..."); delay(10000); // Printing the ESP IP address Serial.println(WiFi.localIP()); } void getTemperature() { total_Sensors = DS18B20.getDeviceCount(); DS18B20.requestTemperatures(); // request to all devices on the bus tempA = DS18B20.getTempCByIndex(0); //dtostrf(tempA, 2, 2, temperatureAString); temperatureAString= String(tempA); tempB = DS18B20.getTempCByIndex(1); temperatureBString= String(tempB); delay(80); //100? } void loop() { // Listenning for new clients digitalWrite ( 05,HIGH); WiFiClient client = server.available(); if (client) { Serial.println("New client"); // bolean to locate when the http request ends boolean blank_line = true; while (client.connected()) { getTemperature(); digitalWrite ( 05,LOW); Serial.println("get temperature"); client.println("A" + temperatureAString); Serial.println("A" + temperatureAString); client.println("B" + temperatureBString); Serial.println("B" + temperatureBString); break; } // closing the client connection delay(1); //client.stop(); Serial.println("Client disconnected."); } } }