Closed Brunno93 closed 10 months ago
@Brunno93 Could you share your code on the get-started example
const unsigned long eventInterval = 1000; unsigned long previousTime = 0;
float Temp; float Hum;
DHT dht(DHTPIN, DHTTYPE);
typedef struct message { float temperature; float humidity; };
struct message myMessage;
void onDataReceiver(const uint8_t mac, const uint8_t incomingData, int len) { Serial.println("Message received."); // We don't use mac to verify the sender // Let us transform the incomingData into our message structure memcpy(&myMessage, incomingData, sizeof(myMessage)); Serial.println("=== Data ==="); Serial.print("Mac address: "); for (int i = 0; i < 6; i++) { Serial.print("0x"); Serial.print(mac[i], HEX); Serial.print(":"); }
Serial.print("\n\nTemperature: "); Serial.println(myMessage.temperature); Serial.print("\nHumidity: "); Serial.println(myMessage.humidity); Serial.println(); }
void setup() { Serial.begin(115200); WiFi.mode(WIFI_STA);
// Get Mac Add Serial.print("Mac Address: "); Serial.print(WiFi.macAddress()); Serial.println("ESP32 ESP-Now Broadcast");
// Initializing the ESP-NOW if (esp_now_init() != 0) { Serial.println("Problem during ESP-NOW init"); return; } esp_now_register_recv_cb(onDataReceiver); }
void loop() {
Hum = dht.readHumidity(); Temp = dht.readTemperature();
unsigned long currentTime = millis(); if (currentTime - previousTime >= eventInterval) {
Serial.print(F("Humidity: ")); Serial.print(h); Serial.print(F("% Temperature: ")); Serial.print(t);
previousTime = currentTime;
} }
@Brunno93 There is some issues need check from the code:
loop
function which read Humidity and Temperature from DHT11?onDataReceiver
function only receive both Humidity and Temperature from the other esp-now
device, it didn't have read option.pin14
to another pin? eg: https://docs.espressif.com/projects/esp-idf/zh_CN/latest/esp32/api-reference/peripherals/gpio.html?highlight=gpioThanks for help I put the espnow.h at the top and review some lines of code about espasyncwerver.h
I've connected a dht11 do pin 14 and a had the readings, but when I simply add a esp_now.h line in the code it stopped reading the sensor values.
Can anyone help. Pls!