PlatformIO Community

Do I need hardware to debug?

I want to learn to debug. I have two programs that need it.

Do I need to buy the ESP- Prog?
I keep waiting for something to appear in the Debug Console.

This is my .ini:

[env:esp32dev]

platform = espressif32

board = esp32dev

framework = arduino

monitor_filters = esp32_exception_decoder

debug_tool = esp-prog

debug_init_break = tbreak setup

lib_deps =

    esp_now

    WiFi

    FS

    ottowinter/ESPAsyncWebServer-esphome@^1.2.7

    https://github.com/arduino-libraries/Arduino_JSON.git

    https://github.com/adafruit/Adafruit_Sensor.git

    https://github.com/adafruit/Adafruit_BME680.git

    https://github.com/adafruit/Adafruit_SGP30.git

    arduino-libraries/NTPClient@^3.2.1

Technically there is the possiility of a UART-stub so that the USB-to-UART converter built-in on most boards suffices, but this is not yet supported by PlatformIO. So the only possibility for live-debugging is with a debug probe.Low-cost ESP32 In-circuit Debugging | by Manuel Bl. | Medium is an excellent article on that.

Dude, a simple “Yes” would have technically answered my question perfectly, but you gave me a placeholder for something I can learn (UART-USB) and a scholarly article that made everything real, practical. This is a high-quality response. I really appreciate it.
I should get the ESP-Prog in almost four weeks.($11.88 + $4 on Ali)

It’s going to show me conflicts in the code, but not offer me solutions, right?

I have an ongoing situation with my ESP Now senders. I see evidence of code running in the first few lines from serial monitor, but none of that format is correct, and then into a formatted backtrace-looking block.

One of the senders has the BME 680, SGP30 and MQ-6 sensors, plus another sensor that does analog CO, NO2, NH3. So I have 4 analog reads and 2 I2Cs happening, and then the data gets collected by ESP Now for transmission. (The R32 has 6 analog pins, A0 and A1 are used by the radio.)

My STRUCT has 16 items, but messing around with that showed me that you can really screw it up without harming the data or the transmission.

You will be able to step line-by-line through the code execution and see the value of variables along the way, which may help you find a bug during runtime. It does not help you with compile-time errors.

Then I should be going in the right direction. These scripts are building and uploading, but they work wrong- I fiddled until they broke, I guess.

Everything in the code looks right. I hardly wrote any of it by myself, mostly pasted from elsewhere.
Only the sensor test works. If the sensor isn’t connected, I get the serial message. But when it’s reconnected the program just goes to heck.

The error message says the ESP Now peer is invalid. I didn’t do anything to that stuff.

(2299) ESPNOW: Peer interface is invalid - ESP32 Forum says you may have missed initialized the peer datastracture.

There were Struct elements out of order, so I corrected the order. Didn’t fix it.

Two of the items in the struct section were initialized to 0. In the SEND section, I have them set to 0, so I deleted those initializations. That didn’t do anything either.

— Miniterm on COM19 9600,8,N,1 —
— Quit: Ctrl+C | Menu: Ctrl+T | Help: Ctrl+T followed by Ctrl+H —
Rۑ`6e��5qq�}c��-�Mode: STA
Channel: 1
SSID (12): TP-Link_7C28
Passphrase (8): 64411811
BSSID set: 0
Mode: STA
Channel: 2
SSID (12): TP-Link_7C28
Passphrase (8): 64411811
BSSID set: 0
E (4994) ESPNOW: Peer interface is invalid
Failed to add peer
Carbon Monoxide Detected!
Guru Meditation Error: Core 1 panic’ed (LoadProhibited). Exception was
unhandled.

Core 1 register dump:
PC : 0x40132f5b PS : 0x00060430 A0 : 0x800d616a A1
: 0x3ffb2740
A2 : 0x00000000 A3 : 0x3ffb27aa A4 : 0x00000002 A5
: 0x00000001
A6 : 0x00000000 A7 : 0x00000000 A8 : 0x800dd099 A9
: 0x3ffb26f0
A10 : 0x3ffc3338 A11 : 0x00060223 A12 : 0x00060220 A13
: 0x00060223
A14 : 0x007bdc68 A15 : 0x003fffff SAR : 0x0000001e EXCCAUSE: 0x0000001c
EXCVADDR: 0x0000000c LBEG : 0x40089c21 LEND : 0x40089c31 LCOUNT : 0xffffffff

Backtrace:0x40132f58:0x3ffb27400x400d6167:0x3ffb2760 0x400d62fd:0x3ffb27a0 0x400d29c1:0x3ffb27d0 0x400d8135:0x3ffb2820
#0 0x40132f58:0x3ffb27400 in Adafruit_I2CDevice::write(unsigned char
const*, unsigned int, bool, unsigned char const*, unsigned int) at .pio/libdeps/esp32dev/Adafruit BusIO/Adafruit_I2CDevice.cpp:73

This is the similar mess I get with the other sender, this one a WeMos D1/32.
The D32 error mentions Adafruit 12C, but the second calls out Wire. So this feels like an I2C conflict?

— Miniterm on COM27 9600,8,N,1 —
— Quit: Ctrl+C | Menu: Ctrl+T | Help: Ctrl+T followed by Ctrl+H —
I%M/�`<
�=a>ii�\mdGd�55�BME680 test

Brownout detector was triggered

�DL�l�P�z+�����BE�BME680 test
Mode: STA
Channel: 1
SSID (12): TP-Link_7C28
Passphrase (8): 64411811
BSSID set: 0
Mode: STA
Channel: 2
SSID (12): TP-Link_7C28
Passphrase (8): 64411811
BSSID set: 0
E (2737) ESPNOW: Peer interface is invalid
Failed to add peer
Guru Meditation Error: Core 1 panic’ed (LoadProhibited). Exception was
unhandled.

Core 1 register dump:
PC : 0x400d499e PS : 0x00060630 A0 : 0x800d4b08 A1
: 0x3ffb2770
A2 : 0x00000000 A3 : 0x00000039 A4 : 0x00000001 A5
: 0x00000001
A6 : 0x00000100 A7 : 0x00000000 A8 : 0x800d7ab8 A9
: 0x3ffb2770
A10 : 0x0000003f A11 : 0x3ffbf148 A12 : 0x00000040 A13
: 0x3ffb2680
A14 : 0x00000000 A15 : 0x00000000 SAR : 0x00000015 EXCCAUSE: 0x0000001c
EXCVADDR: 0x00000134 LBEG : 0x40089630 LEND : 0x40089646 LCOUNT : 0x00000000

Backtrace:0x400d499b:0x3ffb27700x400d4b05:0x3ffb27b0 0x400d6171:0x3ffb27d0 0x400d287f:0x3ffb27f0 0x400d8269:0x3ffb2820
#0 0x400d499b:0x3ffb27700 in TwoWire::requestFrom(unsigned short, unsigned int, bool) at C:/Users/joema/.platformio/packages/framework-arduinoespressif32/libraries/Wire/src/Wire.cpp:359

ELF file SHA256: 0000000000000000

Rebooting…

Can you show exactly how you call esp_now_add_peer() and how all the data structures for that are initialiized?

These are the last lines of setup():

// Init ESP-NOW
  if (esp_now_init() != ESP_OK)
  {
    Serial.println("Error initializing ESP-NOW");
    return;
  }
delay(50);

  // 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;
  }
 
  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 
  
  uv.begin(VEML6070_1_T);  

}

This is the struct:

typedef struct struct_message
{
  int id;
  float temperature;
  float humidity;
  float pressure;
  float LPG;
  float CO;
  float smoke;
  float UV;
  float CO2;
  float NH3;
  float NO2;
  float VOC;
  float TVOC;
  float H2;
  float EtOH;
  int readingId;
} struct_message;

This is the data stuff:


    myData.temperature = (bme.temperature);

    myData.humidity = (bme.humidity);

    myData.pressure = (bme.pressure * .00029355);

    myData.smoke = smoke;

    myData.LPG = 0;

    myData.UV = UV;

    myData.CO = 0;

    myData.CO2 = 0;

    myData.NH3 = 0;

    myData.NO2 = 0;

    myData.VOC = VOC;

    myData.TVOC = 0;

    myData.H2 = 0;

    myData.EtOH = 0;

    myData.readingId = readingId++;

Can you replace this chunk of code with


  // Register peer
  esp_now_peer_info_t peerInfo;
  memset(&peerInfo, 0, sizeof(peerInfo));
  memcpy(peerInfo.peer_addr, broadcastAddress, 6);
  peerInfo.encrypt = false;

?

Sender 2, the WeMos Mini works now.
What did you fix? Why?

Sender 1, the R32 still fails:

Rebooting…
09��L01�))))� �����Mode: STA
Channel: 1
SSID (12): TP-Link_7C28
Passphrase (8): 64411811
BSSID set: 0
Mode: STA
Channel: 2
SSID (12): TP-Link_7C28
Passphrase (8): 64411811
BSSID set: 0
LPG Gas Detected!
Carbon Monoxide Detected!
Ammonia Detected!
Guru Meditation Error: Core 1 panic’ed (LoadProhibited). Exception was
unhandled.

Core 1 register dump:
PC : 0x401331ff PS : 0x00060430 A0 : 0x800d626e A1
: 0x3ffb2740
A2 : 0x00000000 A3 : 0x3ffb27aa A4 : 0x00000002 A5
: 0x00000001
A6 : 0x00000000 A7 : 0x00000000 A8 : 0x800dd331 A9
: 0x3ffb26f0
A10 : 0x3ffc3338 A11 : 0x00060223 A12 : 0x00060220 A13
: 0x00060223
A14 : 0x007bdc68 A15 : 0x003fffff SAR : 0x0000001e EXCCAUSE: 0x0000001c
EXCVADDR: 0x0000000c LBEG : 0x40089c21 LEND : 0x40089c31 LCOUNT : 0xffffffff

Backtrace:0x401331fc:0x3ffb27400x400d626b:0x3ffb2760 0x400d6401:0x3ffb27a0 0x400d2a31:0x3ffb27d0 0x400d83cd:0x3ffb2820
#0 0x401331fc:0x3ffb27400 in Adafruit_I2CDevice::write(unsigned char
const*, unsigned int, bool, unsigned char const*, unsigned int) at .pio/libdeps/esp32dev/Adafruit BusIO/Adafruit_I2CDevice.cpp:73

ELF file SHA256: 0000000000000000

If you don’t 0-initialize a variable on the stack, its contents will be random. peerInfo has more members than just peer_adr and encrypt, and you set the value of those, but the others will be implicitly random.

That’s a different crash now. I would need to see the full code.

Here’s the R32 Sender code. Uses BME 680, SGP30, MQ-6 and a little sensor that gives analog CO, NO2, NH3.

#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"

Adafruit_SGP30 sgp;
Adafruit_BME680 bme;

#define BOARD_ID 1

//MAC Address of the receiver
uint8_t broadcastAddress[] = {0x3C,0x61,0x05,0x12,0x84,0x28};

//Structure example to send data
//Must match the receiver structure
typedef struct struct_message
{
  int id;
  float temperature;
  float humidity;
  float pressure;
  float LPG;
  float CO;
  float smoke;
  float UV;
  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);

  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)
      ;
  }
  }

  // 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;
  memset(&peerInfo, 0, sizeof(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

  pinMode(38, INPUT);
  pinMode(34, INPUT);
  pinMode(36, INPUT);
  pinMode(39, INPUT);
  }

void loop()
{// read analog sensors
  float COValue = 0;
  float COVolts = 0;
  float LPGValue = 0;
  float LPGVolts = 0;
  float NH3Value = 0;
  float NH3Volts = 0;
  float NO2Value = 0;
  float NO2Volts = 0;
  float CO2 = sgp.eCO2;
  float H2 = sgp.rawH2;
  float EtOH = sgp.rawEthanol;
  float VOC = bme.gas_resistance/1000;
  float TVOC = sgp.TVOC;
  
  for (int i = 0; i < 100; i++)
  {
    LPGValue = LPGValue + analogRead(36);
  }
  LPGValue = LPGValue / 100;        // get average reading
  LPGVolts = LPGValue / 1024 * 5.0; // convert to voltage

  float LPG = LPGVolts / 20;
  if (LPGVolts > 1.0)
  {
    Serial.println("LPG Gas Detected!");
  }
 
  for (int i = 0; i < 100; i++)
  {
      COValue = COValue + analogRead(39);
  }
    COValue = COValue / 100;        // get average reading
    COVolts = COValue / 1024 * 5.0; // convert to voltage
    
  float CO = COVolts/20;
  if (COVolts > 1.0)
  {
      Serial.println("Carbon Monoxide Detected!");
  }

  for (int i = 0; i < 100; i++)
  {
    NH3Value = NH3Value + analogRead(34);
  }
  NH3Value = NH3Value / 100;      // get average reading
  NH3Volts = NH3Value / 1024 * 5.0; // convert to voltage

  float NH3 = NH3Volts / 20;
  if (NH3Volts > 1.0)
  {
    Serial.println("Ammonia Detected!");
  }

  for (int i = 0; i < 100; i++)
  {
    NO2Value = NO2Value + analogRead(38);
  }
  NO2Value = NO2Value / 100;        // get average reading
  NO2Volts = NO2Value / 1024 * 5.0; // convert to voltage

  float NO2 = NO2Volts / 20;
  if (NO2Volts > 1.0)
  {
    Serial.println("Nitrate  Detected!");
  }

 
    uint16_t TVOC_base, eCO2_base;
  if (!sgp.getIAQBaseline(&eCO2_base, &TVOC_base))
  {
      Serial.println("Failed to get TVOC, CO2 baseline readings");
      return;
  }

  if (!bme.endReading())
  {
        Serial.println(F("BME Measurement failed :("));
        return;
  }

  if (!sgp.IAQmeasure())
  {
        Serial.println("SGP Measurement failed :(");
        return;
  }
     delay(50);
      // Set values to send
      myData.id = BOARD_ID;
      myData.temperature = (bme.temperature);
      myData.humidity = (bme.humidity);
      myData.pressure = (bme.pressure * .00029355);
      myData.LPG = LPG;
      myData.CO = CO;
      myData.smoke = 0;
      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");
      }
    
    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.print(F("Pressure = "));
    Serial.print(bme.pressure*.00029355 );
    Serial.println(F(" in Hg"));
    Serial.print(F("LPG = "));
    Serial.print(LPG, 0);
    Serial.println(F(" PPM"));

    delay(5000);
  }

Which of your sensors works via I2C? Can you test that sensor separately and see if it fails with the same error?

Can you also delete the .pio folder so that it re-downloads the latest versions of the libraries?

When you look in the compilation log, does it show Espressif 32 platform 4.x.x instead of 3.5.0? This is the new Arduino core which might introduce some incompatibilities with older code. You can try doing platform = espressif32@3.5.0 in the platformio.ini to rollback.

Sender 1 has BME 680 and SGP30 on I2C.
Sender 2 has BME 680 and VEMLxxx Uv chip.

I actually got sender 2 and Receiver working together, then got sender 1 sending, but it was sending zeros- all data = 0 on serial (and on the receiver).

So now I’ve gotten both senders screwed up.
Can’t imagine how, but the guru error is gone for now. My ESP-Prog has been shipped. If it comes from CA, I’ll get it in a week.