ESP32 LoRA SIM800 TinyGSM board connection to Cayenne

Hi All,

I am trying to set an ESP32 board that connects to Cayenne to sleep for at least 12 hours using the code shown below:

#define uS_TO_S_FACTOR 1000000 /* Conversion factor for micro seconds to seconds /
#define TIME_TO_SLEEP 43000 /
Time ESP32 will go to sleep (in seconds) */

The board wakes up in less than an hour and I read somewhere that it has something to do with the fact that the timer value is expressed in 32bit format and that does not do the trick.

Has anyone gone through the same problem?

Thank you

can you share the link for this.

there is a solution mentioned in the link.

I could not interpret the solution. I did find though that someone used the following expression "#define uS_TO_S_FACTOR 1000000ULL " and I am testing it as we speak.
The thing is I have not understood the nature of the 32 or 64 bit representation mentioned and I am now going through documentation of ESP32

here is another solution TimerWakeUp sample wake up time (int) and (uint64_t) · Issue #2735 · espressif/arduino-esp32 · GitHub

Dear All,

Anyone getting this watchdog message? Is it valid that this crash behavior is caused by code running in loops?

Guru Meditation Error: Core 1 panic’ed (Interrupt wdt timeout on CPU1)
Core 1 register dump:
PC : 0x400813b9 PS : 0x00050034 A0 : 0x40084a8c A1 : 0x3ffbe7a0
A2 : 0x3ffbec60 A3 : 0x00000000 A4 : 0x00000001 A5 : 0x4008aa54
A6 : 0x00000004 A7 : 0x3ffb8614 A8 : 0x0000000a A9 : 0x3ff40000
A10 : 0x00000000 A11 : 0x0000025c A12 : 0x00000000 A13 : 0x3ffb1db0
A14 : 0x3ffb8000 A15 : 0xbaad5678 SAR : 0x0000001f EXCCAUSE: 0x00000006
EXCVADDR: 0x00000000 LBEG : 0x4000c46c LEND : 0x4000c477 LCOUNT : 0x00000000
Core 1 was running in ISR context:
EPC1 : 0x4000bff0 EPC2 : 0x00000000 EPC3 : 0x00000000 EPC4 : 0x400813b9

Backtrace: 0x400813b9:0x3ffbe7a0 0x40084a89:0x3ffbe7d0 0x4000bfed:0x3ffb1e00 0x40089581:0x3ffb1e10 0x400d9733:0x3ffb1e30 0x400d9789:0x3ffb1e70 0x400d634d:0x3ffb1ea0 0x400d643b:0x3ffb1ec0 0x400d6812⸮

Thank you in advance

you can answer to this in esp8266 forum.

Hi,
you mean search for relevant posts there or post it again?

https://www.esp8266.com/viewforum.php?f=165

Thank you,

Does it not matter that I am using an ESP32 SIM800 board?

sorry for esp32 forum https://www.esp32.com/

Thank you once more

Hello, I’m new to esp32 800l board, but i have some experience on esp8266 Wich I used to control LEDs on internet, but the problem I faced is that it could not connect to WiFi routers otherwise I use my phone to provide Wi-Fi, I came across with this board(esp32 800l) which I think will be more good for me since I will insert a sim card and the board will have to use the mbs from the sim card, but till now I have no any idea from the scratch on how can I make it possible from including the board to the Arduino ide till connecting it to the cayenne dashboard that I should be able to access my LEDs anywhere through internet, can you help please.

you will need to do the following change [M590] LIbrary not working on ESP32 · Issue #91 · vshymanskyy/TinyGSM · GitHub

Thanks dear friend for your help, as face challenges I shall share them.

Hi,
I’m new to ESP32 SIM800L board, just working on a project where I need to send and receive data from thingspeak.com, I’m getting this error while uploading the code.

In file included from C:\Users\win-10\OneDrive\Documents\Arduino\ESP32\ESP32.ino:3:0:
C:\Users\win-10\OneDrive\Documents\Arduino\libraries\TinyGSM\src/TinyGsmClient.h:117:4: error: #error “Please define GSM modem model”
#error “Please define GSM modem model”
^
exit status 1
Error compiling for board DOIT ESP32 DEVKIT V1.

Someone help me with this, I have tried many things but didn’t got any luck resolving it.

Here’s the code,

//#include <WiFi.h>
#include <Wire.h>
#include <TinyGsmClient.h>
//#include “secrets.h”
#include “ThingSpeak.h” // always include thingspeak header file after other header files and custom macros
#include “max6675.h”

int thermoDO = 4;
int thermoCS = 2;
int thermoCLK = 15;
int r = 5;

// Your GPRS credentials (leave empty, if not needed)
const char apn = “airtelgprs.com”; // APN (example: internet.vodafone.pt) use https://wiki.apnchanger.org
const char gprsUser = “”; // GPRS User
const char gprsPass = “”; // GPRS Password

// SIM card PIN (leave empty, if not defined)
const char simPIN = “”;

//char ssid = “SNGCONTROL”; // your network SSID (name)
//char pass = “Sngcontrol@123”; // your network password
//int keyIndex = 0; // your network key Index number (needed only for WEP)
WiFiClient client;

// TTGO T-Call pins
#define MODEM_RST 5
#define MODEM_PWKEY 4
#define MODEM_POWER_ON 23
#define MODEM_TX 27
#define MODEM_RX 26
#define I2C_SDA 21
#define I2C_SCL 22

// Weather station channel details
unsigned long weatherStationChannelNumber = 1476526;
unsigned long weatherStationChannelNumber1 = 1519040;
unsigned long myChannelNumber = 1519011;
const char* myWriteAPIKey = “5ZIPSAB1MJMMKZER”;
unsigned int targettemp = 2;
unsigned int manualcontrol = 1;
float val = 0.0;

// Counting channel details
unsigned long counterChannelNumber = 1476526;
const char * myCounterReadAPIKey = “PASLJUBX9AIFBOCA” ;
unsigned int counterFieldNumber = 1;

MAX6675 thermocouple(thermoCLK, thermoCS, thermoDO);

// Set serial for debug console (to Serial Monitor, default speed 115200)
#define SerialMon Serial
// Set serial for AT commands (to SIM800 module)
#define SerialAT Serial1

// Configure TinyGSM library
#define TINY_GSM_MODEM_SIM800 // Modem is SIM800
#define TINY_GSM_RX_BUFFER 1024 // Set RX buffer to 1Kb

#ifdef DUMP_AT_COMMANDS
#include <StreamDebugger.h>
StreamDebugger debugger(SerialAT, SerialMon);
TinyGsm modem(debugger);
#else
TinyGsm modem(SerialAT);
#endif

// I2C for SIM800 (to keep it running when powered from battery)
TwoWire I2CPower = TwoWire(0);

// TinyGSM Client for Internet connection
TinyGsmClient client(modem);

//#define uS_TO_S_FACTOR 1000000UL /* Conversion factor for micro seconds to seconds /
//#define TIME_TO_SLEEP 3600 /
Time ESP32 will go to sleep (in seconds) 3600 seconds = 1 hour */

#define IP5306_ADDR 0x75
#define IP5306_REG_SYS_CTL0 0x00

bool setPowerBoostKeepOn(int en){
I2CPower.beginTransmission(IP5306_ADDR);
I2CPower.write(IP5306_REG_SYS_CTL0);
if (en) {
I2CPower.write(0x37); // Set bit1: 1 enable 0 disable boost keep on
} else {
I2CPower.write(0x35); // 0x37 is default reg value
}
return I2CPower.endTransmission() == 0;
}

void setup() {
SerialMon.begin(115200);

while (!Serial) {
; // wait for serial port to connect. Needed for Leonardo native USB port only
}

// Start I2C communication
I2CPower.begin(I2C_SDA, I2C_SCL, 400000);

// Keep power when running from battery
bool isOk = setPowerBoostKeepOn(1);
SerialMon.println(String("IP5306 KeepOn ") + (isOk ? “OK” : “FAIL”));

// Set modem reset, enable, power pins
pinMode(MODEM_PWKEY, OUTPUT);
pinMode(MODEM_RST, OUTPUT);
pinMode(MODEM_POWER_ON, OUTPUT);
digitalWrite(MODEM_PWKEY, LOW);
digitalWrite(MODEM_RST, HIGH);
digitalWrite(MODEM_POWER_ON, HIGH);

// Set GSM module baud rate and UART pins
SerialAT.begin(115200, SERIAL_8N1, MODEM_RX, MODEM_TX);
delay(3000);

// Restart SIM800 module, it takes quite some time
// To skip it, call init() instead of restart()
SerialMon.println(“Initializing modem…”);
modem.init();
// use modem.init() if you don’t need the complete restart

// Unlock your SIM card with a PIN if needed
if (strlen(simPIN) && modem.getSimStatus() != 3 )
{
modem.simUnlock(simPIN);
}

digitalWrite(21,HIGH);
digitalWrite(22,LOW);
WiFi.mode(WIFI_STA);
ThingSpeak.begin(client); // Initialize ThingSpeak

// Configure the wake up source as timer wake up  

//esp_sleep_enable_timer_wakeup(TIME_TO_SLEEP * uS_TO_S_FACTOR);

}

void loop() {

val = thermocouple.readCelsius();

int statusCode = 0;

// Connect or reconnect to WiFi
if(WiFi.status() != WL_CONNECTED){
SerialMon.print(“Attempting to connect to SSID: “);
SerialMon.println(ssid);
while(WiFi.status() != WL_CONNECTED){
WiFi.begin(ssid, pass); // Connect to WPA/WPA2 network. Change this line if using open or WEP network
SerialMon.print(”.”);
delay(5000);
}
SerialMon.println(“\nConnected”);
}

int x = ThingSpeak.writeField(myChannelNumber, 1,val, myWriteAPIKey);
if(x == 200){
SerialMon.println(“Channel update successful.”);
}

// Read in field 1 of the public channel recording the temperature
float target = ThingSpeak.readFloatField(weatherStationChannelNumber, targettemp);

// Check the status of the read operation to see if it was successful
statusCode = ThingSpeak.getLastReadStatus();
if(statusCode == 200){
SerialMon.println(“Target Temperature: " + String(target) + " deg C”);
}
else{
SerialMon.println("Problem reading channel. HTTP error code " + String(statusCode));
}

// Read in field 1 of the public channel recording the temperature

float mc = ThingSpeak.readFloatField(weatherStationChannelNumber1, manualcontrol);

// Check the status of the read operation to see if it was successful
statusCode = ThingSpeak.getLastReadStatus();
if(statusCode == 200){
SerialMon.println("Manual_control: " + String(mc));
}
else{
SerialMon.println("Problem reading channel. HTTP error code " + String(statusCode));
}

pinMode(r, OUTPUT);

if(mc == 0)
{
digitalWrite(r,LOW);
}

else if(val>= target)
{
digitalWrite(r,LOW);
}

else
{
digitalWrite(r,HIGH);
}

delay(2000); // No need to read the temperature too often.

SerialMon.println("Actual temperature: " + String(val));

delay(5000); // No need to read the counter too often.

// Put ESP32 into deep sleep mode (with timer wake up)
//esp_deep_sleep_start();
}

@vs69819 is this something related to cayenne?