ESP32 LoRA SIM800 TinyGSM board connection to Cayenne

Hi All,

I am investigating the usage of a ESP32 Lora-SIM800 enabled board for connecting to Cayenne.

I have done some initial testing using the ready made examples from TinyGSM Library on GitHub and more specifically I have used the following code:

// Your GPRS credentials (leave empty, if missing)
const char apn = “apn”; // Your APN
const char gprsUser = “”; // User
const char gprsPass = “”; // Password
const char simPIN = “0000”; // SIM card PIN code, if any

// TTGO T-Call pin definitions
#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
// Configure TinyGSM library
#define TINY_GSM_MODEM_SIM800 // Modem is SIM800
#define TINY_GSM_RX_BUFFER 1024 // Set RX buffer to 1Kb

// Define the serial console for debug prints, if needed
//#define TINY_GSM_DEBUG SerialMon
//#define DUMP_AT_COMMANDS

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

#include <Wire.h>
#include <TinyGsmClient.h>
#include “utilities.h”

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

// Server details
const char server = “vsh.pp.ua”;
const char resource = “/TinyGSM/logo.txt”;

TinyGsmClient client(modem);
const int port = 80;

void setup() {

SerialAT.begin(115200, SERIAL_8N1, 26, 27);

// Set up the GSM module
pinMode(4, OUTPUT);
pinMode(5, OUTPUT);

digitalWrite(4, LOW);
digitalWrite(5, HIGH);

delay(2000);

// Set console baud rate
SerialMon.begin(115200);
delay(10);

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

// Set-up 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 takes quite some time
// To skip it, call init() instead of restart()
SerialMon.println(“Initializing modem…”);
modem.restart();
// Or, use modem.init() if you don’t need the complete restart

String modemInfo = modem.getModemInfo();
SerialMon.print("Modem: ");
SerialMon.println(modemInfo);

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

void loop() {
SerialMon.print(“Waiting for network…”);
if (!modem.waitForNetwork(240000L)) {
SerialMon.println(" fail");
delay(10000);
return;
}
SerialMon.println(" OK");

if (modem.isNetworkConnected()) {
SerialMon.println(“Network connected”);
}

SerialMon.print(F(“Connecting to APN: “));
SerialMon.print(apn);
if (!modem.gprsConnect(apn, gprsUser, gprsPass)) {
SerialMon.println(” fail”);
delay(10000);
return;
}
SerialMon.println(" OK");

SerialMon.print("Connecting to ");
SerialMon.print(server);

if (!client.connect(server, port)) {
SerialMon.println(" fail");
delay(10000);
return;
}
SerialMon.println(" OK");

// Make a HTTP GET request:
//SerialMon.println(“Performing HTTP GET request…”);
//client.print(String("GET “) + resource + " HTTP/1.1\r\n”);
//client.print(String("Host: ") + server + “\r\n”);
//client.print(“Connection: close\r\n\r\n”);
//client.println();

unsigned long timeout = millis();
while (client.connected() && millis() - timeout < 10000L) {
// Print available data
while (client.available()) {
char c = client.read();
SerialMon.print©;
timeout = millis();
}
}
SerialMon.println();

// Shutdown

client.stop();
SerialMon.println(F(“Server disconnected”));

modem.gprsDisconnect();
SerialMon.println(F(“GPRS disconnected”));

// Do nothing forevermore
while (true) {
delay(1000);
}
}

The code works fine and the dev board connects to the server listed and downloads an image from the server.

I would like to understand what modification is needed as to allow the dev board to connect to Cayenne and upload a sensor’s data? Do I just have to repalce the server name with “mqtt.mydevices.com”, or is it much more complicated than that?

Thank You All
S

we have a GSM example https://github.com/myDevicesIoT/Cayenne-MQTT-Arduino/blob/master/examples/Connections/GSM/GSM.ino which is based on tiny GSM.

Dear Shramik,

Thank you very much for your reply. Unfortunately when i upload the script to my TTGO SIM800 board, I fail to compile due to the #include <CayenneMQTTGSM.h> cannot be satisfied.
i tried locating the mentioned library but with no success I am afraid.

Any ideas on this please?

Thank you very much for your support

Best
Spyros

can you share the entire error you are getting.

Ηι,

Of course…

Arduino: 1.8.11 (Windows 10), Board: “ESP32 Dev Module, Disabled, Default 4MB with spiffs (1.2MB APP/1.5MB SPIFFS), 240MHz (WiFi/BT), QIO, 80MHz, 4MB (32Mb), 921600, None”

In file included from C:\Users…\Desktop\IoT\Jan2020\TTGO SIM800L\TTGO SIM800 CAYENNE SCRIPT\TTGO_SIM800_CAYENNE_SCRIPT\TTGO_SIM800_CAYENNE_SCRIPT.ino:8:0:

C:\Users…\Documents\Arduino\libraries\Cayenne-MQTT-ESP-master\src/CayenneMQTTESP8266.h:21:25: fatal error: ESP8266WiFi.h: No such file or directory

compilation terminated.

exit status 1
Error compiling for board ESP32 Dev Module.

This report would have more information with
“Show verbose output during compilation”
option enabled in File -> Preferences.

can you delete the previous cayenne library, download this library and add it https://github.com/myDevicesIoT/Cayenne-MQTT-Arduino

Dear Shramik,

Thank you very much for your swift reply. I was getting ready to flow the steps you proposed but my TTGO ESP32 SIM800 board failed me for the second time and now all I am getting on the Monitor is addresses of this sort:

load:0x40080400,len:6352

entry 0x400806b8

Wait…

Guru Meditation Error: Core 1 panic’ed (IllegalInstruction). Exception was unhandled.

Memory dump at 0x400d3c5c: 53e52011 ffffffff ffffffff

Core 1 register dump:

PC : 0x400d3c61 PS : 0x00060f30 A0 : 0x80088218 A1 : 0x3ffb1fb0

A2 : 0x3ffc0568 A3 : 0x00000000 A4 : 0x00060023 A5 : 0x3ffb8058

A6 : 0x00000000 A7 : 0x00000000 A8 : 0x00000000 A9 : 0x3ffb1f80

A10 : 0x0001c200 A11 : 0x0800001c A12 : 0x00004e20 A13 : 0x3ffc052c

A14 : 0x00000008 A15 : 0x00000001 SAR : 0x00000016 EXCCAUSE: 0x00000000

EXCVADDR: 0x00000000 LBEG : 0x400014fd LEND : 0x4000150d LCOUNT : 0xffffffff

Backtrace: 0x400d3c61:0x3ffb1fb0 0x40088215:0x3ffb1fd0

Unfortunately this is the 2nd board that fails me within a week and I fell I must not pursue my smart bin sensor plans with this brand.

May I ask if you do have a brand to propose that has proven trustworthy to you?

Best

Spyros

well, you might report this issue with the manufactures and see what they have to say about this issue. there is notting i can do about it.

Hi again,

Of course it is not something that needs attention from you.

I just wanted your feedback on which boards you have found reliable.

Thank you again

Spyros

Λήψη του BlueMail για Android

Στις 19 Φεβ 2020 ,και ώρα 18:37 ,Shramik salgaonkar via myDevices Cayenne Community mydevices@discoursemail.com έγραψε:

i will need much more info on which board shall fit your project. what is the mode of connection, wifi, ethernet or Lora? what is your project application?

Hello again,

LTE and Lora modes of data transmission. The scope of the project is creation of smart bin sensors that detect items in the beam’s path and therefore inform us if the bin is full or not.

At your dispoaal for any furtger info needed.

Λήψη του BlueMail για Android

Στις 19 Φεβ 2020 ,και ώρα 19:49 ,Shramik salgaonkar via myDevices Cayenne Community mydevices@discoursemail.com έγραψε:

you want both on a single board?

Not necessarily

Λήψη του BlueMail για Android

Στις 19 Φεβ 2020 ,και ώρα 20:15 ,Shramik salgaonkar via myDevices Cayenne Community mydevices@discoursemail.com έγραψε:

so it is either lora or LTE.
For lora if you are going for a development board then you can go for the things uno or sodaq explorer or build one from scratch using lora chip.
For LTE. the cayenne library is based on tiny GSM library and all board listed here should work for cayenne (not tested) https://github.com/vshymanskyy/TinyGSM

Dear Shramik,

It seems that letting the board cool down during nighttime did the trick ! :blush:

It is now working again. I did try a test configuration and the board successfully connected to the internet. Unfortunately this did not work with Cayenne’s example configuration as the modem does not initialize nor does it dial up to the internet. I did try deleting all exsting Cayenne MQTT libraries and installed the one you told me.

I also did try another configuration that worked and added the Cayenne.begin and Cayenne.loop commands but I get errors that point to the library used. I tried both the Cayenne-MQTT-Arduino-master.zip as well as the Cayenne-MQTT-ESP-master and the CayenneMQTT, all with no luck I am afraid.

The error message I get points to the CayenneMQTTWiFiClient.h file and other files in the library’s src folder.

Any input from you would be most valuable.

Thank you very much for your support throughout these days.

Best Regards

Spyros

it would be much better if you share the entire error you are getting.

shramik_salgaonkar Community Manager
February 20

it would be much better if you share the entire error you are getting.

Hello,

Apologies for not including it. Please find the error below:

C:\Users\Spiros\Documents\Arduino\libraries\Cayenne-MQTT-ESP-master\src/CayenneMQTTWiFiClient.h:111:7: note: candidate expects 3 arguments, 8 provided

exit status 1

no matching function for call to ‘CayenneMQTTWiFiClient::begin(char [37], char [41], char [37], SoftwareSerial&, const char [9], const char [1], const char [1], const char [5])’

This report would have more information with

“Show verbose output during compilation”

option enabled in File -> Preferences.

The script is also listed here:

#include <SoftwareSerial.h>

SoftwareSerial gsmSerial(2, 3); // RX, TX

#include <CayenneArduinoDefines.h>

#include <CayenneArduinoMQTTClient.h>

#include <CayenneMQTTESP32.h>

//#include <Wire.h>

//#include <TinyGsmClient.h>

//#include <CayenneMQTTGSM.h>

#define CAYENNE_PRINT Serial  // Comment this out to disable prints and save space

// Your GPRS credentials (leave empty, if not needed)

const char apn[]      = "internet"; // 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[]   = "";

// Cayenne authentication info. This should be obtained from the Cayenne Dashboard.

char username[] = "6ef6eee0-7ee8-11e9-beb3-736c9e4bf7d0";

char password[] = "27075a7d55000a07809e76b1286c5c2e52b2b78d";

char clientID[] = "d64dced0-c644-11e9-8221-599f77add412";

// 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

// BME280 pins

#define I2C_SDA_2            18

#define I2C_SCL_2            19

// 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

// Define the serial console for debug prints, if needed

//#define DUMP_AT_COMMANDS

#include <Wire.h>

#include <TinyGsmClient.h>

#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 1000000     /* 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() {

// Set serial monitor debugging window baud rate to 115200

SerialMon.begin(115200);

// Start I2C communication

I2CPower.begin(I2C_SDA, I2C_SCL, 400000);

//  I2CBME.begin(I2C_SDA_2, I2C_SCL_2, 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.restart();

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

}

Cayenne.begin(username, password, clientID, gsmSerial, apn, gprsUser, gprsPass, simPIN);

// Configure the wake up source as timer wake up

//esp_sleep_enable_timer_wakeup(TIME_TO_SLEEP * uS_TO_S_FACTOR);

}

void loop() {

SerialMon.print("Connecting to APN: ");

SerialMon.print(apn);

if (!modem.gprsConnect(apn, gprsUser, gprsPass)) {

SerialMon.println(" fail");

}

else {

SerialMon.println(" OK");

Cayenne.loop();

// Close client and disconnect

//client.stop();

//SerialMon.println(F("Server disconnected"));

modem.gprsDisconnect();

//SerialMon.println(F("GPRS disconnected"));

}

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

//esp_deep_sleep_start();

}

Thank you once more for your support

Spyros

remove this from the code.

Removed those and after compiling I get:

Arduino: 1.8.11 (Windows 10), Board: “ESP32 Dev Module, Disabled, Default 4MB with spiffs (1.2MB APP/1.5MB SPIFFS), 240MHz (WiFi/BT), QIO, 40MHz, 4MB (32Mb), 921600, None”

C:\Users\Spiros\Desktop\IoT\Jan2020\TTGO SIM800L\VARIOUS TESTS\TTGO_SIM800L_TEST2_19_FEB\TTGO_SIM800L_TEST2_19_FEB.ino: In function ‘void setup()’:

TTGO_SIM800L_TEST2_19_FEB:150:3: error: ‘Cayenne’ was not declared in this scope

Cayenne.begin(username, password, clientID, gsmSerial, apn, gprsUser, gprsPass, simPIN);

^

C:\Users\Spiros\Desktop\IoT\Jan2020\TTGO SIM800L\VARIOUS TESTS\TTGO_SIM800L_TEST2_19_FEB\TTGO_SIM800L_TEST2_19_FEB.ino: In function ‘void loop()’:

TTGO_SIM800L_TEST2_19_FEB:165:6: error: ‘Cayenne’ was not declared in this scope

Cayenne.loop();

^

exit status 1

‘Cayenne’ was not declared in this scope

This report would have more information with

“Show verbose output during compilation”

option enabled in File -> Preferences.

try this code:

// TTGO T-Call pin definitions
#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


#include <TinyGsmClient.h>

#include <Wire.h>

// Set serial for debug console (to the Serial Monitor, default speed 115200)
#define SerialMon Serial

// Hardware Serial on Mega, Leonardo, Micro
#define gsmSerial Serial1

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


// GSM connection info.
char apn[] = ""; // Access point name. Leave empty if it is not needed.
char gprsLogin[] = ""; // GPRS username. Leave empty if it is not needed.
char gprsPassword[] = ""; // GPRS password. Leave empty if it is not needed.
char pin[] = ""; // SIM pin number. Leave empty if it is not needed.


TinyGsm modem(gsmSerial);

char username[] = "MQTT_USERNAME";
char password[] = "MQTT_PASSWORD";
char clientID[] = "CLIENT_ID";

void setup()
{
  // Set console baud rate
  SerialMon.begin(115200);
  delay(10);

  // Keep power when running from battery
  Wire.begin(I2C_SDA, I2C_SCL);
  bool   isOk = setPowerBoostKeepOn(1);
  SerialMon.println(String("IP5306 KeepOn ") + (isOk ? "OK" : "FAIL"));

  // Set-up 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
  gsmSerial.begin(115200, SERIAL_8N1, MODEM_RX, MODEM_TX);
  delay(3000);

  // Restart takes quite some time
  // To skip it, call init() instead of restart()
  SerialMon.println("Initializing modem...");
  modem.restart();

  String modemInfo = modem.getModemInfo();
  SerialMon.print("Modem: ");
  SerialMon.println(modemInfo);

  // Unlock your SIM card with a PIN
  //modem.simUnlock("1234");

  SerialMon.print("Waiting for network...");
  if (!modem.waitForNetwork(240000L)) {
    SerialMon.println(" fail");
    delay(10000);
    return;
  }
  SerialMon.println(" OK");

  if (modem.isNetworkConnected()) {
    SerialMon.println("Network connected");
  }

  SerialMon.print(F("Connecting to APN: "));
  SerialMon.print(apn);
  if (!modem.gprsConnect(apn, user, pass)) {
    SerialMon.println(" fail");
    delay(10000);
    return;
  }
  SerialMon.println(" OK");

  Cayenne.begin(username, password, clientID, gsmSerial, apn, gprsLogin, gprsPassword, pin);
}

void loop()
{
  Cayenne.loop();
}