Description
I am setting up a new Arduino ESP32 Feather board with BME680 sensor. The sample sketches I tried are working, and I have started to adapt the sample code.
My code compiles fine, but crashes with the following output:
ets Jun 8 2016 00:22:57
rst:0xc (SW_CPU_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
configsip: 0, SPIWP:0xee
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
mode:DIO, clock div:1
load:0x3fff0018,len:4
load:0x3fff001c,len:1044
load:0x40078000,len:8896
load:0x40080400,len:5816
entry 0x400806ac
/home/runner/work/esp32-arduino-lib-builder/esp32-arduino-lib-builder/esp-idf/components/freertos/queue.c:1442 (xQueueGenericReceive)- assert failed!
abort() was called at PC 0x40089019 on core 1
Backtrace: 0x4008cc18:0x3ffb1db0 0x4008ce49:0x3ffb1dd0 0x40089019:0x3ffb1df0 0x4014780a:0x3ffb1e30 0x40147ae6:0x3ffb1e50 0x40136708:0x3ffb1e70 0x40136771:0x3ffb1e90 0x4013dcc9:0x3ffb1eb0 0x4013dcee:0x3ffb1ed0 0x40136567:0x3ffb1ef0 0x400d6bb7:0x3ffb1f10 0x400d14ac:0x3ffb1f80 0x400d7483:0x3ffb1fb0 0x4008932d:0x3ffb1fd0
Rebooting...
I installed the Exception Decoder in the Arduino IDE and get the following:
Decoding stack results
0x4008cc18: invoke_abort at /home/runner/work/esp32-arduino-lib-builder/esp32-arduino-lib-builder/esp-idf/components/esp32/panic.c line 155
0x4008ce49: abort at /home/runner/work/esp32-arduino-lib-builder/esp32-arduino-lib-builder/esp-idf/components/esp32/panic.c line 170
0x40089019: xQueueGenericReceive at /home/runner/work/esp32-arduino-lib-builder/esp32-arduino-lib-builder/esp-idf/components/freertos/queue.c line 1442
0x4014780a: sys_mutex_lock at /home/runner/work/esp32-arduino-lib-builder/esp32-arduino-lib-builder/esp-idf/components/lwip/port/esp32/freertos/sys_arch.c line 78
0x40147ae6: sys_arch_protect at /home/runner/work/esp32-arduino-lib-builder/esp32-arduino-lib-builder/esp-idf/components/lwip/port/esp32/freertos/sys_arch.c line 469
0x40136708: do_memp_malloc_pool at /home/runner/work/esp32-arduino-lib-builder/esp32-arduino-lib-builder/esp-idf/components/lwip/lwip/src/core/memp.c line 302
0x40136771: memp_malloc at /home/runner/work/esp32-arduino-lib-builder/esp32-arduino-lib-builder/esp-idf/components/lwip/lwip/src/core/memp.c line 398
0x4013dcc9: udp_new at /home/runner/work/esp32-arduino-lib-builder/esp32-arduino-lib-builder/esp-idf/components/lwip/lwip/src/core/udp.c line 1145
0x4013dcee: udp_new_ip_type at /home/runner/work/esp32-arduino-lib-builder/esp32-arduino-lib-builder/esp-idf/components/lwip/lwip/src/core/udp.c line 1177
0x40136567: sntp_init at /home/runner/work/esp32-arduino-lib-builder/esp32-arduino-lib-builder/esp-idf/components/lwip/lwip/src/apps/sntp/sntp.c line 547
0x400d6bb7: configTime at /Users/awsjames/Library/Arduino15/packages/esp32/hardware/esp32/1.0.4/cores/esp32/esp32-hal-time.c line 55
0x400d14ac: setup() at /Users/awsjames/Desktop/IoT Downloads/bme680test/bme680test.ino line 93
0x400d7483: loopTask(void*) at /Users/awsjames/Library/Arduino15/packages/esp32/hardware/esp32/1.0.4/cores/esp32/main.cpp line 14
0x4008932d: vPortTaskWrapper at /home/runner/work/esp32-arduino-lib-builder/esp32-arduino-lib-builder/esp-idf/components/freertos/port.c line 143
Here is the current code:
//INCLUDES FOR ESP32 FEATHER + BME680 TEST TO FUNCTION PROPERLY
#include <Wire.h>
#include <SPI.h>
#include <Adafruit_Sensor.h>
#include "Adafruit_BME680.h"
//ADDITIONAL INCLUDES FOR AWS IOT INTEGRATION
//#include <WiFiAP.h> //Code won't compile with this include file...
#include <WiFiMulti.h>
#include <WiFiUdp.h>
#include <WiFiScan.h>
#include <ETH.h>
#include <WiFiClient.h>
#include <WiFiSTA.h>
#include <WiFiServer.h>
#include <WiFiType.h>
#include <WiFiGeneric.h>
#include <ArduinoJson.h>
#include <AWS_IOT.h>
#include <WiFi.h>
#include "time.h"
#include <string.h>
//CONFIGURATION FOR BME680 SENSOR USING SPI
#define BME_SCK 5
#define BME_MISO 19
#define BME_MOSI 18
#define BME_CS 21
struct tm timeinfo;
#define SEALEVELPRESSURE_HPA (1013.25)
Adafruit_BME680 bme(BME_CS); // hardware SPI
AWS_IOT sensor;
//Defining parameters for connecting to Wifi and AWS
char WIFI_SSID[]="";
char WIFI_PASSWORD[]="";
char HOST_ADDRESS[]="*****";
char CLIENT_ID[]= "testclient";
char TOPIC_NAME[]= "iot/test";
char curtime [50];
//timer
int status = WL_IDLE_STATUS;
int tick=0,msgCount=0,msgReceived = 0;
char payload[512];
char rcvdPayload[512];
//Defining Time variables
const char* ntpServer = "pool.ntp.org";
const long gmtOffset_sec = -28800;
const int daylightOffset_sec = 3600;
//Air quality variable
float hum_weighting = 0.25; // so hum effect is 25% of the total air quality score
float gas_weighting = 0.75; // so gas effect is 75% of the total air quality score
float hum_score, gas_score;
float gas_reference = 250000;
float hum_reference = 40;
int getgasreference_count = 0;
void mySubCallBackHandler (char *topicName, int payloadLen, char *payLoad)
{
strncpy(rcvdPayload,payLoad,payloadLen);
rcvdPayload[payloadLen] = 0;
msgReceived = 1;
}
void GetGasReference(){
// Now run the sensor for a burn-in period, then use combination of relative humidity and gas resistance to estimate indoor air quality as a percentage.
Serial.println("Getting a new gas reference value");
int readings = 10;
for (int i = 0; i <= readings; i++){ // read gas for 10 x 0.150mS = 1.5secs
gas_reference += bme.readGas();
}
gas_reference = gas_reference / readings;
}
void setup() {
Serial.begin(115200);
while (!Serial);
delay(2000);
if (!bme.begin()) {
Serial.println("Could not find a valid BME680 sensor, check wiring!");
while (1);
}
//init and get the time
configTime(gmtOffset_sec, daylightOffset_sec, ntpServer);
// Set up oversampling and filter initialization
bme.setTemperatureOversampling(BME680_OS_2X);
bme.setHumidityOversampling(BME680_OS_2X);
bme.setPressureOversampling(BME680_OS_2X);
bme.setIIRFilterSize(BME680_FILTER_SIZE_3);
bme.setGasHeater(320, 150); // 320*C for 150 ms
while (status != WL_CONNECTED)
{
Serial.print("Attempting to connect to SSID: ");
Serial.println(WIFI_SSID);
// Connect to WPA/WPA2 network. Change this line if using open or WEP network:
status = WiFi.begin(WIFI_SSID, WIFI_PASSWORD);
// wait 5 seconds for connection:
delay(5000);
}
Serial.println("Connected to wifi");
if(sensor.connect(HOST_ADDRESS,CLIENT_ID)== 0)
{
Serial.println("Connected to AWS");
delay(1000);
if(0==sensor.subscribe(TOPIC_NAME,mySubCallBackHandler))
{
Serial.println("Subscribe Successfull");
}
else
{
Serial.println("Subscribe Failed, Check the Thing Name and Certificates");
while(1);
}
}
else
{
Serial.println("AWS connection failed, Check the HOST Address");
while(1);
}
delay(2000);
}
void loop() {
if (! bme.performReading()) {
Serial.println("Failed to perform reading :(");
return;
}
//Calculate humidity contribution to IAQ index
float current_humidity = bme.readHumidity();
if (current_humidity >= 38 && current_humidity <= 42)
hum_score = 0.25*100; // Humidity +/-5% around optimum
else
{ //sub-optimal
if (current_humidity < 38)
hum_score = 0.25/hum_reference*current_humidity*100;
else
{
hum_score = ((-0.25/(100-hum_reference)*current_humidity)+0.416666)*100;
}
}
//Calculate gas contribution to IAQ index
float gas_lower_limit = 5000; // Bad air quality limit
float gas_upper_limit = 50000; // Good air quality limit
if (gas_reference > gas_upper_limit) gas_reference = gas_upper_limit;
if (gas_reference < gas_lower_limit) gas_reference = gas_lower_limit;
gas_score = (0.75/(gas_upper_limit-gas_lower_limit)*gas_reference -(gas_lower_limit*(0.75/(gas_upper_limit-gas_lower_limit))))*100;
//Combine results for the final IAQ index value (0-100% where 100% is good quality air)
float air_quality_score = hum_score + gas_score;
StaticJsonBuffer<1000> JSONbuffer;
JsonObject& JSONencoder = JSONbuffer.createObject();
if(tick >= 15) // publish to topic every 15seconds
{
tick=0;
if(!getLocalTime(&timeinfo)){
Serial.println("Failed to obtain time");
}
strftime(curtime, sizeof(curtime), "%B %d %Y %H:%M:%S", &timeinfo);
JSONencoder["DeviceID"] = "NYC001";
JSONencoder["Date"] = curtime;
JSONencoder["AQI"] = int((100 - air_quality_score) * 5);
JSONencoder["Temperature"] = bme.temperature;
JSONencoder["Pressure"] = bme.pressure / 100.0;
JSONencoder["Humidity"] = bme.humidity;
JSONencoder["Gas"] = bme.gas_resistance / 1000.0;
char JSONmessageBuffer[1000];
JSONencoder.printTo(JSONmessageBuffer, sizeof(JSONmessageBuffer));
Serial.println("Sending message to MQTT topic..");
Serial.println(JSONmessageBuffer);
if(sensor.publish(TOPIC_NAME,JSONmessageBuffer) == 0)
{
Serial.print("Publish Message:");
Serial.println(JSONmessageBuffer);
}
else
{
Serial.println("Publish failed");
tick = 15;
}
}
vTaskDelay(1000 / portTICK_RATE_MS);
tick++;
}
I am not a developer and am trying to hack my way through fixing this. Any help would greatly be appreciated!