I got my ESP Now Receiver working, trying to fire up the sender.
Using WeMos D1 Mini/ESP32.
I’m getting this error (seen it before, but the script was working when I put it away):
Rebooting...
!�͂DU�����TV�agJ1@�Ζ␙��BME680 test
SGP30 test
Guru Meditation Error: Core 1 panic'ed (LoadProhibited). Exception was unhandled.
Core 1 register dump:
PC : 0x40081065 PS : 0x00060330 A0 : 0x800d092c A1 : 0x3ffb1f30
A2 : 0x00000007 A3 : 0x00000001 A4 : 0x00000001 A5 : 0x00000020
A6 : 0x00000003 A7 : 0x00000000 A8 : 0x3f4016ac A9 : 0xffffffff
A10 : 0xffffffff A11 : 0x00000064 A12 : 0x08000000 A13 : 0x3ffb1f2e
A14 : 0xffffffff A15 : 0x3ffb1ef0 SAR : 0x0000001a EXCCAUSE: 0x0000001c
EXCVADDR: 0xffffffff LBEG : 0x4000c2e0 LEND : 0x4000c2f6 LCOUNT : 0x00000000
ELF file SHA256: 0000000000000000
Backtrace: 0x40081065:0x3ffb1f30 0x400d0929:0x3ffb1f50 0x400d559e:0x3ffb1fb0 0x4008a0f6:0x3ffb1fd0
LoadProhibited- what does that mean?
One sensor is 5V, but it isn’t I2C. Output is analog.
BME 680 and SGP30 are 3V.
Code:
#include <Arduino.h>
/*
Rui Santos
Complete project details at https://RandomNerdTutorials.com/esp32-esp-now-wi-fi-web-server/
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files.
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
*/
#include <esp_now.h>
#include <esp_wifi.h>
#include <WiFi.h>
#include <Adafruit_Sensor.h>
#include "Adafruit_BME680.h"
#include "Adafruit_SGP30.h"
#define SEALEVELPRESSURE_HPA (1013.25)
Adafruit_SGP30 sgp;
Adafruit_BME680 bme; // I2C
// Set your Board ID (ESP32 Sender #1 = BOARD_ID 1, ESP32 Sender #2 = BOARD_ID 2, etc)
#define BOARD_ID 1
//MAC Address of the receiver
uint8_t broadcastAddress[] = {0xFC, 0xF5, 0xC4, 0x2F, 0xA1, 0x04};
//Structure example to send data
//Must match the receiver structure
typedef struct struct_message
{
int id;
float temperature;
float humidity;
float pressure;
float altitude;
float LPG;
float UV;
float CO;
float CO2;
float NH3;
float NO2;
float VOC;
float TVOC;
float H2;
float EtOH;
int readingId;
} struct_message;
//Create a struct_message called myData
struct_message myData;
unsigned long previousMillis = 0; // Stores last time temperature was published
const long interval = 10000; // Interval at which to publish sensor readings
unsigned int readingId = 0;
// Insert your SSID
constexpr char WIFI_SSID[] = "TP-Link_7C28";
int32_t getWiFiChannel(const char *ssid)
{
if (int32_t n = WiFi.scanNetworks())
{
for (uint8_t i = 0; i < n; i++)
{
if (!strcmp(ssid, WiFi.SSID(i).c_str()))
{
return WiFi.channel(i);
}
}
}
return 0;
}
// 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");
}
void setup()
{
Serial.begin(9600);
//Init Serial Monitor
while (!Serial)
;
Serial.println(F("BME680 test"));
if (!bme.begin())
{
Serial.println(F("BME680 not found"));
while (1)
;
}
Serial.println("SGP30 test");
if (!sgp.begin())
{
Serial.println("SGP30 not found :(");
while (1)
;
}
pinMode(0, INPUT);
pinMode(5, INPUT);
pinMode(6, INPUT);
pinMode(7, INPUT);
// Set device as a Wi-Fi Station and set channel
WiFi.mode(WIFI_STA);
int32_t channel = getWiFiChannel(WIFI_SSID);
WiFi.printDiag(Serial); // Uncomment to verify channel number before
esp_wifi_set_promiscuous(true);
esp_wifi_set_channel(channel, WIFI_SECOND_CHAN_NONE);
esp_wifi_set_promiscuous(false);
WiFi.printDiag(Serial); // Uncomment to verify channel change after
//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.encrypt = false;
//Add peer
if (esp_now_add_peer(&peerInfo) != ESP_OK)
{
Serial.println("Failed to add peer");
return;
}
// Set up oversampling and filter initialization
bme.setTemperatureOversampling(BME680_OS_8X);
bme.setHumidityOversampling(BME680_OS_2X);
bme.setPressureOversampling(BME680_OS_4X);
bme.setIIRFilterSize(BME680_FILTER_SIZE_3);
bme.setGasHeater(320, 150); // 320*C for 150 ms
}
void loop()
{ float LPG = analogRead(35);
float NH3 = analogRead(34);
float NO2 = analogRead(36);
float CO = analogRead(39);
float CO2 = sgp.eCO2;
float VOC = bme.gas_resistance/10000;
float TVOC = sgp.TVOC;
float H2 = sgp.rawH2;
float EtOH = sgp.rawEthanol;
float altitude = bme.readAltitude(SEALEVELPRESSURE_HPA);
float pressure = (bme.pressure / 3386);
float UV = 0;
Serial.print(F("Temperature = "));
Serial.print(bme.temperature, 0);
Serial.println(F(" *C"));
Serial.print(F("Humidity = "));
Serial.print(bme.humidity, 0);
Serial.println(F(" %"));
Serial.println("Yes, it's working.");
//Set values to send
myData.id = BOARD_ID;
myData.temperature = bme.temperature;
myData.humidity = bme.humidity;
myData.pressure = pressure;
myData.altitude = altitude;
myData.LPG = 1 / LPG;
myData.CO = CO;
myData.UV = 0;
myData.CO2 = CO2;
myData.NH3 = NH3;
myData.NO2 = NO2;
myData.VOC = VOC;
myData.TVOC = TVOC;
myData.H2 = H2;
myData.EtOH = EtOH;
myData.readingId = readingId++;
//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");
}
delay(5000);
}