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(c);
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