#include #include #include #include #include #include // REPLACE WITH THE RECEIVER S MAC Address uint8_t broadcastAddress[] = {0x30, 0xAE, 0xA4, 0xDF, 0x5A, 0x54}; const int broche_DT = 5; const int broche_SCK = 2; // GPIO where the DS18B20 is connected to const int oneWireBus = 4; #define DHTPIN 14 // Digital pin connected to the DHT sensor #define DHTTYPE DHT11 // DHT 11 #define uS_TO_S_FACTOR 1000000 /* Conversion factor for micro seconds to seconds */ #define TIME_TO_SLEEP 900 /* Time ESP32 will go to sleep (in seconds) */ // Structure example to send data // Must match the receiver structure typedef struct struct_message { char a[32]; int ID; float Poids; float Temp1; float Temp2; float Humidite; } struct_message; // Create a struct_message called myData struct_message myData; HX711 balance; // callback when data is sent void OnDataSent(const uint8_t *mac_addr, esp_now_send_status_t status) { Serial.print("\r\nLast Packet Send Status:\t"); Serial.println(status == ESP_NOW_SEND_SUCCESS ? "Delivery Success" : "Delivery Fail"); } // Setup a oneWire instance to communicate with any OneWire devices OneWire oneWire(oneWireBus); // Pass our oneWire reference to Dallas Temperature sensor DallasTemperature sensors(&oneWire); DHT dht(DHTPIN, DHTTYPE); void setup() { // Init Serial Monitor Serial.begin(115200); delay(2000); // Set device as a Wi-Fi Station WiFi.mode(WIFI_STA); Serial.println ("Slave"); // Init ESP-NOW if (esp_now_init() != ESP_OK) { Serial.println("Error initializing ESP-NOW"); return; } // Once ESPNow is successfully Init, we will register for Send CB to // get the status of Trasnmitted packet esp_now_register_send_cb(OnDataSent); // Register peer esp_now_peer_info_t peerInfo; memcpy(peerInfo.peer_addr, broadcastAddress, 6); peerInfo.channel = 0; peerInfo.encrypt = false; // Add peer if (esp_now_add_peer(&peerInfo) != ESP_OK){ Serial.println("Failed to add peer"); return; } Serial.println("Initialisation de la balance..."); balance.begin(broche_DT, broche_SCK); while (!balance.is_ready()) { ; } balance.set_scale(11.7); //calibration: le paramètre dépend de votre cellule de charge. balance.tare(); //ajustement du zéro Serial.println("La balance est prete!"); // Start the DS18B20 sensor sensors.begin(); dht.begin(); delay(1000); esp_sleep_enable_timer_wakeup(TIME_TO_SLEEP * uS_TO_S_FACTOR); delay(2000); sensors.requestTemperatures(); // Set values to send strcpy(myData.a, "Ruche 1"); myData.ID = 1; myData.Poids=balance.get_units(10); myData.Temp1 = sensors.getTempCByIndex(0); myData.Temp2 = dht.readTemperature(); myData.Humidite = dht.readHumidity(); Serial.println(myData.Humidite); // Send message via ESP-NOW esp_err_t result = esp_now_send(broadcastAddress, (uint8_t *) &myData, sizeof(myData)); if (result == ESP_OK) { Serial.println("Sent with success"); } else { Serial.println("Error sending the data"); } //Serial.println("Configured all RTC Peripherals to be powered down in sleep"); esp_deep_sleep_start(); } void loop() { }