ESP32 LoRA SIM800 TinyGSM board connection to Cayenne

I just did and got the following:

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”

In file included from C:\Users\Spiros\Desktop\IoT\Jan2020\TTGO SIM800L\VARIOUS TESTS\TTGO SHRAMIK CAYENNE SCRIPT\TTGO_SHRAMIK_CAYENNE_SCRIPT\TTGO_SHRAMIK_CAYENNE_SCRIPT.ino:21:0:

C:\Users\Spiros\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 ESP32 Dev Module.

This report would have more information with

“Show verbose output during compilation”

option enabled in File → Preferences.

Am I missing a library you would say?

/**************************************************************

   This sketch connects to a website and downloads a page.
   It can be used to perform HTTP/RESTful API calls.

   TinyGSM Getting Started guide:
     https://tiny.cc/tinygsm-readme

 **************************************************************/

// Your GPRS credentials (leave empty, if missing)
const char apn[]      = ""; // Your APN
const char gprsUser[] = ""; // User
const char gprsPass[] = ""; // Password
const char simPIN[]   = ""; // 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

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

// Configure TinyGSM library
#define TINY_GSM_MODEM_SIM800      // Modem is SIM800
#define TINY_GSM_RX_BUFFER   1024  // Set RX buffer to 1Kb
#include <CayenneMQTTGSM.h>
char username[] = "MQTT_USERNAME";
char password[] = "MQTT_PASSWORD";
char clientID[] = "CLIENT_ID";

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

#include <Wire.h>
#include <TinyGsmClient.h>


TinyGsm modem(SerialAT);


// Server details
const char server[] = "vsh.pp.ua";
const char resource[] = "/TinyGSM/logo.txt";

const int  port = 80;

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



  // 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);
  }
    Cayenne.begin(username, password, clientID, SerialAT, apn, gprsUser, gprsPass, simPIN);

}

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

// Default function for sending sensor data at intervals to Cayenne.
// You can also use functions for specific channels, e.g CAYENNE_OUT(1) for sending channel 1 data.
CAYENNE_OUT_DEFAULT()
{
  // Write data to Cayenne here. This example just sends the current uptime in milliseconds on virtual channel 0.
  Cayenne.virtualWrite(0, millis());
  // Some examples of other functions you can use to send data.
  //Cayenne.celsiusWrite(1, 22.0);
  //Cayenne.luxWrite(2, 700);
  //Cayenne.virtualWrite(3, 50, TYPE_PROXIMITY, UNIT_CENTIMETER);
}

// Default function for processing actuator commands from the Cayenne Dashboard.
// You can also use functions for specific channels, e.g CAYENNE_IN(1) for channel 1 commands.
CAYENNE_IN_DEFAULT()
{
  CAYENNE_LOG("Channel %u, value %s", request.channel, getValue.asString());
  //Process message here. If there is an error set an error message using getValue.setError(), e.g getValue.setError("Error message");
}

HEllO!!!

I got a Channel 0 in Cayenne, this means it is working right? :blush:)))

I used the Cayenne-MQTT-Arduino-master library!

IS this ok now you would say?

Spyros

congrats. you got it working finally.

this is because of you of these lines:

CAYENNE_OUT_DEFAULT()
{
  // Write data to Cayenne here. This example just sends the current uptime in milliseconds on virtual channel 0.
  Cayenne.virtualWrite(0, millis());
  // Some examples of other functions you can use to send data.
  //Cayenne.celsiusWrite(1, 22.0);
  //Cayenne.luxWrite(2, 700);
  //Cayenne.virtualWrite(3, 50, TYPE_PROXIMITY, UNIT_CENTIMETER);
}

Dear Sir,

Thank you very much for your amazing assistance, it worked!

I will just have to add some commands in order to have feedback on whether the SIM800 has successfully connected to the internet.

Thank you so much!

1 Like

Dear Shramik,

Thank you again for your help in setting up the dev board to connect via LTE to Cayenne.

I have just created a new script that includes the code needed for connecting the board via LTE as well as the s=code needed for controlling the distance sensor, which is a TF Mini Plus Lidar unit.

I cannot get the board to connect to Cayenne I am afraid, do you think there is a problem with the nested loops for Setup and Loop I created?

Thank you very much for your time in Advance

Spyros

Please find the code below:

//#include <CayenneArduinoDefines.h>

//#include <CayenneMQTTWiFi.h>

//#include <CayenneMQTTMKR1010.h>

#define RX  32

#define TX  33

#define CAYENNE_DEBUG

#define CAYENNE_PRINT Serial

#define VIRTUAL_CHANNEL 5

//char ssid[] = "";

//char wifiPassword[]="";

/* For Arduinoboards with multiple serial ports like DUEboard, interpret above two pieces of code and

directly use Serial1 serial port*/

int dist; //actual distance measurements of LiDAR

int strength; //signal strength of LiDAR

float temprature;

int check; //save check value

int i;

int uart[9]; //save data measured by LiDAR

const int HEADER=0x59; //frame header of data package

// Your GPRS credentials (leave empty, if missing)

const char apn[]      = "internet"; // Your APN

const char gprsUser[] = ""; // User

const char gprsPass[] = ""; // Password

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

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

// Configure TinyGSM library

#define TINY_GSM_MODEM_SIM800      // Modem is SIM800

#define TINY_GSM_RX_BUFFER   1024  // Set RX buffer to 1Kb

#include <CayenneMQTTGSM.h>

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

char password[] = "27075a7d55000a07809e76b1286c5c2e52b2b78d";

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

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

//#define TINY_GSM_DEBUG SerialMon

//#define DUMP_AT_COMMANDS

#include <Wire.h>

#include <TinyGsmClient.h>

TinyGsm modem(SerialAT);

void GSM_SETUP() {

// Set console baud rate

SerialMon.begin(115200);

delay(10);

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

Serial.println("SIM Unlocked");

}

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

}

void GSM_LOOP() {

Cayenne.loop();

}

void TFMINI_SETUP() {

Serial.begin(9600); //set bit rate of serial port connecting Arduino with computer

//Serial1.begin(115200); //set bit rate of serial port connecting LiDAR with Arduino

Serial1.begin(115200, SERIAL_8N1, RX, TX);

}

void TFMINI_LOOP() {

//  Cayenne.loop();

if (Serial1.available()) { //check if serial port has data input

//Serial.print("*");

if(Serial1.read() == HEADER) { //assess data package frame header 0x59

uart[0]=HEADER;

if (Serial1.read() == HEADER) { //assess data package frame header 0x59

uart[1] = HEADER;

for (i = 2; i < 9; i++) { //save data in array

uart[i] = Serial1.read();

}

check = uart[0] + uart[1] + uart[2] + uart[3] + uart[4] + uart[5] + uart[6] + uart[7];

if (uart[8] == (check & 0xff)){ //verify the received data as per protocol

dist = uart[2] + uart[3] * 256; //calculate distance value

strength = uart[4] + uart[5] * 256; //calculate signal strength value

temprature = uart[6] + uart[7] *256;//calculate chip temprature

temprature = temprature/8 - 256;

//Serial.print("HEllo5");

Serial.print("dist = ");

Serial.println(dist); //output measure distance value of LiDAR

}

}

}

}

}

// This function is called at intervals to send data to Cayenne.

CAYENNE_OUT(VIRTUAL_CHANNEL)

{

// CAYENNE_LOG("Send data for Virtual Channel %d", VIRTUAL_CHANNEL);

// This command writes the device's uptime in seconds to the Virtual Channel.

Cayenne.virtualWrite(VIRTUAL_CHANNEL, dist);

}

// Default function for sending sensor data at intervals to Cayenne.

// You can also use functions for specific channels, e.g CAYENNE_OUT(1) for sending channel 1 data.

CAYENNE_OUT_DEFAULT()

{

// Write data to Cayenne here. This example just sends the current uptime in milliseconds on virtual channel 0.

//Cayenne.virtualWrite(0, millis());

Cayenne.virtualWrite(VIRTUAL_CHANNEL, dist);

}

// Default function for processing actuator commands from the Cayenne Dashboard.

// You can also use functions for specific channels, e.g CAYENNE_IN(1) for channel 1 commands.

//CAYENNE_IN_DEFAULT()

//{

//  CAYENNE_LOG("Channel %u, value %s", request.channel, getValue.asString());

//Process message here. If there is an error set an error message using getValue.setError(), e.g getValue.setError("Error message");

//}

void setup() {

GSM_SETUP();

TFMINI_SETUP();

}

void loop() {

GSM_LOOP();

TFMINI_LOOP();

}

image002.jpg

the MKR is not supported currently with the cayenne code, as it many users have reported issues with it.

Hi,

Thanks for replying. It is disabled by ?? comments.

I opened the Sereial monitor and at 115200 I get commnets from Cayenne and the boards does connect to Cayenne. When I switch the settings to 9600 at the Serial Monitor I do not get measurements from the sensor as I usually do.

Any ideas on this?

Spyros

image002.jpg

image002.jpg

well, if you have mention in the code the baud rate to 115200 then you will get output in the serial monitor only on that baud rate.

Hello,

In the code regarding the operationof the GSM part which you helped me to complete, the seriasl monitor is set at 115200.

The serial interface for the lidar sensor is also set at 115200and the serial.begin is at 960 for the serial 1 interface(default USB) connection.

Is there a way that I can use 115200 for driving the GSM and sensor but receive all data at 9660 in my USB serial connection?

As to the library you mentioned earlier, it is not used in the config. Do you and hunch on why the cayenne does not receive the millis of operation value, as described in the code?

Best

Spyr

IS t

image002.jpg

in your code you have define this:

#define SerialMon Serial
#define SerialAT Serial1

and in the setup you have:

void GSM_SETUP() {
SerialMon.begin(115200);
SerialAT.begin(115200, SERIAL_8N1, MODEM_RX, MODEM_TX);
}

which same as in another setup:

void TFMINI_SETUP() {
Serial.begin(9600); //set bit rate of serial port connecting Arduino with computer
Serial1.begin(115200, SERIAL_8N1, RX, TX);
}

You arew very right my friend, I am so wrong in these commands.

Do ou think I should change SerialMon Serial to SerialMon Serial2 and

SerialAT Serial1 to Serial AT Serial2 respectively,

As to avoid blocking the Serial(9600) command I have put for the Lidar’s begin?

Also I have tried to change the Serial(9600) command to Serial(115200) and I had no results unfortunately

Thank you again

Spyros

image002.jpg

you need to understand what each Serial pin are doing and change them accordingly. Just dont use one pin for two things.

Shramik,

Once again thank you very much for your support.

I will am mend accordingly and see what happens.

Best

Spyros

image002.jpg

1 Like

You were veery right once again…

I changed the value of the SerialMon.begin(115200) to SerialMon.begin(9600); and I started receiving all GPRS/Cayenne debug messages on 9600 Serial Monitor.

Although I am on 9600 I still cannot receive any messages from the sensor. I also changed the Serial interface of the sensor to Serial2 so as to avoid any conflicts with Serial1 THE GSM module uses.

Apologies for the frequent asking of questions.

SPyros

image002.jpg

can you share the code.

//#include <CayenneArduinoDefines.h>

//#include <CayenneMQTTWiFi.h>

//#include <CayenneMQTTMKR1010.h>

#define RX 32

#define TX 33

#define CAYENNE_DEBUG

#define CAYENNE_PRINT Serial

#define VIRTUAL_CHANNEL 0

//char ssid = “”;

//char wifiPassword=“”;

/* For Arduinoboards with multiple serial ports like DUEboard, interpret above two pieces of code and

directly use Serial1 serial port*/

int dist; //actual distance measurements of LiDAR

int strength; //signal strength of LiDAR

float temprature;

int check; //save check value

int i;

int uart[9]; //save data measured by LiDAR

const int HEADER=0x59; //frame header of data package

// Your GPRS credentials (leave empty, if missing)

const char apn = “internet”; // Your APN

const char gprsUser = “”; // User

const char gprsPass = “”; // Password

const char simPIN = “6317”; // 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

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

// Configure TinyGSM library

#define TINY_GSM_MODEM_SIM800 // Modem is SIM800

#define TINY_GSM_RX_BUFFER 1024 // Set RX buffer to 1Kb

#include <CayenneMQTTGSM.h>

char username = “6ef6eee0-7ee8-11e9-beb3-736c9e4bf7d0”;

char password = “27075a7d55000a07809e76b1286c5c2e52b2b78d”;

char clientID = “d64dced0-c644-11e9-8221-599f77add412”;

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

//#define TINY_GSM_DEBUG SerialMon

//#define DUMP_AT_COMMANDS

#include <Wire.h>

#include <TinyGsmClient.h>

TinyGsm modem(SerialAT);

void GSM_SETUP() {

// Set console baud rate

SerialMon.begin(9600);

delay(10);

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

Serial.println(“SIM Unlocked”);

}

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

}

void GSM_LOOP() {

Cayenne.loop();

}

void TFMINI_SETUP() {

Serial.begin(9600); //set bit rate of serial port connecting Arduino with computer

//Serial1.begin(115200); //set bit rate of serial port connecting LiDAR with Arduino

Serial2.begin(115200, SERIAL_8N1, RX, TX);

}

void TFMINI_LOOP() {

// Cayenne.loop();

if (Serial2.available()) { //check if serial port has data input

//Serial.print(“*”);

if(Serial2.read() == HEADER) { //assess data package frame header 0x59

uart[0]=HEADER;

if (Serial2.read() == HEADER) { //assess data package frame header 0x59

uart[1] = HEADER;

for (i = 2; i < 9; i++) { //save data in array

uart[i] = Serial2.read();

}

check = uart[0] + uart[1] + uart[2] + uart[3] + uart[4] + uart[5] + uart[6] + uart[7];

if (uart[8] == (check & 0xff)){ //verify the received data as per protocol

dist = uart[2] + uart[3] * 256; //calculate distance value

strength = uart[4] + uart[5] * 256; //calculate signal strength value

temprature = uart[6] + uart[7] *256;//calculate chip temprature

temprature = temprature/8 - 256;

//Serial.print(“HEllo5”);

Serial.print("dist = ");

Serial.println(dist); //output measure distance value of LiDAR

}

}

}

}

}

// This function is called at intervals to send data to Cayenne.

//CAYENNE_OUT(VIRTUAL_CHANNEL)

//{

// CAYENNE_LOG(“Send data for Virtual Channel %d”, VIRTUAL_CHANNEL);

// This command writes the device’s uptime in seconds to the Virtual Channel.

// Cayenne.virtualWrite(VIRTUAL_CHANNEL, dist);

//}

CAYENNE_OUT_DEFAULT()

{

// Write data to Cayenne here. This example just sends the current uptime in milliseconds on virtual channel 0.

//Cayenne.virtualWrite(0, millis());

Cayenne.virtualWrite(VIRTUAL_CHANNEL, dist);

}

// Default function for processing actuator commands from the Cayenne Dashboard.

// You can also use functions for specific channels, e.g CAYENNE_IN(1) for channel 1 commands.

//CAYENNE_IN_DEFAULT()

//{

// CAYENNE_LOG(“Channel %u, value %s”, request.channel, getValue.asString());

//Process message here. If there is an error set an error message using getValue.setError(), e.g getValue.setError(“Error message”);

//}

void setup() {

GSM_SETUP();

TFMINI_SETUP();

}

void loop() {

GSM_LOOP();

TFMINI_LOOP();

}

image002.jpg

you are still doing the same, you have two Serial.begin()

Hi,

I am afraid I am not that knowledgeable in this and have to burden you with questions…

I did the following ammendemnt, is this what you are referring to ?

void TFMINI_SETUP() {

//Serial.begin(9600); //set bit rate of serial port connecting Arduino with computer

//Serial1.begin(115200); //set bit rate of serial port connecting LiDAR with Arduino

Serial2.begin(115200, SERIAL_8N1, RX, TX);

}

image002.jpg

My dear Shramik,

It worked and I did disable the first Serial.begin as below:

void TFMINI_SETUP() {

//Serial.begin(9600); //set bit rate of serial port connecting Arduino with computer

//Serial1.begin(115200); //set bit rate of serial port connecting LiDAR with Arduino

Serial2.begin(115200, SERIAL_8N1, RX, TX);

The only issue observed is that he board is slow in making the distance calculations. Does this seem awkward to you?

Thank you again for your support

SPyros

image002.jpg