A6 Module Connected to ESP-32S

I’m really in need of help with this problem and as most commonly advised, I have researched and researched and researched for days and I can’t figure out what’s wrong…

With that being said, I’m working on a project that uses an ESP-32S (pinout) and an A6 GSM module. (pinout) I’m attempting to get them connected to have the A6 send data to ThingSpeak… My problem is that I can’t get it to work… I have the exact same configuration between the two using an ESP8266 and it connects and works but with the ESP32S it just doesn’t seem to work…

Below is the code I have used to connect the 32 to the A6 and everything says success and pass but it won’t change any ThingSpeak values using any methods…

#define TINY_GSM_MODEM_A6

#include "TinyGsmClient.h"
#include "ThingSpeak.h"


#define SerialMon Serial

HardwareSerial SerialAT(1);

bool modemConeted;

// Your GPRS credentials
// Leave empty, if missing user or pass
const char apn[]  = "wireless.twilio.com";
const char user[] = "";
const char pass[] = "";

bool dataSent = false;

TinyGsm modem(SerialAT);

TinyGsmClient client(modem);

void setup(){
  SerialMon.begin(9600);
  delay(1000);
  gsmModSetup();
}

void gsmModSetup() {

  // Set GSM module baud rate
  SerialAT.begin(9600, SERIAL_8N1, 27, 26, false); //27 and 26 are the pins on the ESP32S connected to the U_Rxd/U_Txd pins of A6
  delay(3000);

  SerialMon.println("Initializing modem...");
  modem.init();
  delay(3000);

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

  SerialMon.println(modemInfo);


  SerialMon.print("Waiting for network...");
  if (!modem.waitForNetwork()) {
    SerialMon.println(" fail");
    delay(10000);
    return;
  }
  SerialMon.println(" OK");
  SerialMon.print("Connecting to ");
  SerialMon.print(apn);
  
  if (!modem.gprsConnect(apn, user, pass)) {
    SerialMon.println(" fail");
    delay(5000);
    return;
  }
  SerialMon.println(" OK");
}

void loop(){
  
}

I’m using a Twilo Sim card that’s loaded with data (as said above it works with esp8266 so not the SIM and not the board) The only part of this code that doesn’t pass is the part that says GPRS connect. it never says pass or fail. It just sits for like five minutes then continues.

After this, I try and post to ThingSpeak and it gives ThingSpeak ERROR-307 which means failed to connect to ThingSpeak…
I have tried 2 different ways

The what I find the easy and normal way

ThingSpeak.setField(1, temp);
ThingSpeak.setField(2, h);
ThingSpeak.setField(3, p);
ThingSpeak.setField(4, pt);
ThingSpeak.writeFields(myChannelNumber, myWriteAPIKey);

and the more complicated way of connecting to the server then sends a GET command with all the values put together with strings.

if (client.connect(thingSpeakAddress, 80))
  {
    client.print("POST /update HTTP/1.1\n");
    client.print("Host: api.thingspeak.com\n");
    client.print("Connection: close\n");
    client.print("X-THINGSPEAKAPIKEY: " + WriteAPIKey + "\n");
    client.print("Content-Type: application/x-www-form-urlencoded\n");
    client.print("Content-Length: ");
    client.print(thingSpeakData.length());
    client.print("\n\n");

    client.print(thingSpeakData);

  }
client.stop();

Yet neither work and I don’t know what to do… My A6 is connected to the 32 using GPIO26 & 27 they’re connected to the A6 U_Rxd/U_Txd pins. All boards share common ground as they should.

Any more guides to read or code to change or libraries to try would be extremely helpful as my days of digging has yielded nothing but frustration as one attempt after another fails. the readers of this really are my last hope in solving this problem that’s hindering my farther progression.

(Any questions about anything on my end, please ask. -Thank you)

Try replacing this line

HardwareSerial SerialAT(1);

by

#define SerialAT Serial1

Post complete code that shows the problem. If above posted code already show the problem, post the output you get in the serial monitor.

I’m having the problem with all code that attempts anything that requires the internet… The most recent sketch is the tinygsm HTTP example sketch. I changed my pins that connect to the A6 to RX2 TX2 on the esp32s

/**************************************************************
 *
 * This sketch connects to a website and downloads a page.
 * It can be used to perform HTTP/RESTful API calls.
 *
 * For this example, you need to install ArduinoHttpClient library:
 *   https://github.com/arduino-libraries/ArduinoHttpClient
 *   or from http://librarymanager/all#ArduinoHttpClient
 *
 * TinyGSM Getting Started guide:
 *   https://tiny.cc/tinygsm-readme
 *
 * For more HTTP API examples, see ArduinoHttpClient library
 *
 * NOTE: This example may NOT work with the XBee because the
 * HttpClient library does not empty to serial buffer fast enough
 * and the buffer overflow causes the HttpClient library to stall.
 * Boards with faster processors may work, 8MHz boards will not.
 **************************************************************/

// Select your modem:
//#define TINY_GSM_MODEM_SIM800
// #define TINY_GSM_MODEM_SIM808
// #define TINY_GSM_MODEM_SIM868
// #define TINY_GSM_MODEM_SIM900
// #define TINY_GSM_MODEM_SIM7000
// #define TINY_GSM_MODEM_SIM5360
// #define TINY_GSM_MODEM_SIM7600
// #define TINY_GSM_MODEM_UBLOX
// #define TINY_GSM_MODEM_SARAR4
// #define TINY_GSM_MODEM_M95
// #define TINY_GSM_MODEM_BG96
 #define TINY_GSM_MODEM_A6
// #define TINY_GSM_MODEM_A7
// #define TINY_GSM_MODEM_M590
// #define TINY_GSM_MODEM_MC60
// #define TINY_GSM_MODEM_MC60E
// #define TINY_GSM_MODEM_ESP8266
// #define TINY_GSM_MODEM_XBEE
// #define TINY_GSM_MODEM_SEQUANS_MONARCH

// Set serial for debug console (to the Serial Monitor, default speed 115200)
#define SerialMon Serial
#include <ThingSpeak.h>
// Set serial for AT commands (to the module)
// Use Hardware Serial on Mega, Leonardo, Micro
//#define SerialAT Serial1

// or Software Serial on Uno, Nano
#include <SoftwareSerial.h>
SoftwareSerial SerialAT(16, 17); // RX, TX

unsigned long ChannelNumber = 1024154;            //Channel Number
const char * WriteAPIKey = "2JOLM8D3WUUJMCBC";    //Write API Key


// Increase RX buffer to capture the entire response
// Chips without internal buffering (A6/A7, ESP8266, M590)
// need enough space in the buffer for the entire response
// else data will be lost (and the http library will fail).
#if !defined(TINY_GSM_RX_BUFFER)
#define TINY_GSM_RX_BUFFER 650
#endif

// See all AT commands, if wanted
// #define DUMP_AT_COMMANDS

// Define the serial console for debug prints, if needed
#define TINY_GSM_DEBUG SerialMon
// #define LOGGING  // <- Logging is for the HTTP library

// Range to attempt to autobaud
#define GSM_AUTOBAUD_MIN 9600
#define GSM_AUTOBAUD_MAX 115200

// Add a reception delay - may be needed for a fast processor at a slow baud rate
// #define TINY_GSM_YIELD() { delay(2); }

// Define how you're planning to connect to the internet
#define TINY_GSM_USE_GPRS true
#define TINY_GSM_USE_WIFI false

// set GSM PIN, if any
#define GSM_PIN ""

// Your GPRS credentials, if any
const char apn[]  = "api.thingspeak.com";
const char gprsUser[] = "";
const char gprsPass[] = "";

// Your WiFi connection credentials, if applicable
const char wifiSSID[]  = "YourSSID";
const char wifiPass[] = "YourWiFiPass";

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

#include <TinyGsmClient.h>
#include <ArduinoHttpClient.h>

// Just in case someone defined the wrong thing..
#if TINY_GSM_USE_GPRS && not defined TINY_GSM_MODEM_HAS_GPRS
#undef TINY_GSM_USE_GPRS
#undef TINY_GSM_USE_WIFI
#define TINY_GSM_USE_GPRS false
#define TINY_GSM_USE_WIFI true
#endif
#if TINY_GSM_USE_WIFI && not defined TINY_GSM_MODEM_HAS_WIFI
#undef TINY_GSM_USE_GPRS
#undef TINY_GSM_USE_WIFI
#define TINY_GSM_USE_GPRS true
#define TINY_GSM_USE_WIFI false
#endif

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

TinyGsmClient client(modem);
HttpClient http(client, server, port);

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

  // !!!!!!!!!!!
  // Set your reset, enable, power pins here
  // !!!!!!!!!!!

  SerialMon.println("Wait...");

  // Set GSM module baud rate
  // TinyGsmAutoBaud(SerialAT,GSM_AUTOBAUD_MIN,GSM_AUTOBAUD_MAX);
  SerialAT.begin(9600);
  delay(3000);

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

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

#if TINY_GSM_USE_GPRS
  // Unlock your SIM card with a PIN if needed
  if ( GSM_PIN && modem.getSimStatus() != 3 ) {
    modem.simUnlock(GSM_PIN);
  }
#endif
}

void loop() {

#if TINY_GSM_USE_WIFI
  // Wifi connection parameters must be set before waiting for the network
  SerialMon.print(F("Setting SSID/password..."));
  if (!modem.networkConnect(wifiSSID, wifiPass)) {
    SerialMon.println(" fail");
    delay(10000);
    return;
  }
  SerialMon.println(" success");
#endif

#if TINY_GSM_USE_GPRS && defined TINY_GSM_MODEM_XBEE
  // The XBee must run the gprsConnect function BEFORE waiting for network!
  modem.gprsConnect(apn, gprsUser, gprsPass);
#endif

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

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

#if TINY_GSM_USE_GPRS
  // GPRS connection parameters are usually set after network registration
    SerialMon.print(F("Connecting to "));
    SerialMon.print(apn);
    if (!modem.gprsConnect(apn, gprsUser, gprsPass)) {
      SerialMon.println(" fail");
      delay(10000);
      return;
    }
    SerialMon.println(" success");

    if (modem.isGprsConnected()) {
      SerialMon.println("GPRS connected");
    }

    int val = 100;
    ThingSpeak.writeField(ChannelNumber, 1,val, WriteAPIKey); //Update in ThingSpeak

    
#endif

  SerialMon.print(F("Performing HTTP GET request... "));
  int err = http.get(resource);
  if (err != 0) {
    SerialMon.println(F("failed to connect"));
    delay(10000);
    return;
  }

  int status = http.responseStatusCode();
  SerialMon.print(F("Response status code: "));
  SerialMon.println(status);
  if (!status) {
    delay(10000);
    return;
  }

  SerialMon.println(F("Response Headers:"));
  while (http.headerAvailable()) {
    String headerName = http.readHeaderName();
    String headerValue = http.readHeaderValue();
    SerialMon.println("    " + headerName + " : " + headerValue);
  }

  int length = http.contentLength();
  if (length >= 0) {
    SerialMon.print(F("Content length is: "));
    SerialMon.println(length);
  }
  if (http.isResponseChunked()) {
    SerialMon.println(F("The response is chunked"));
  }

  String body = http.responseBody();
  SerialMon.println(F("Response:"));
  SerialMon.println(body);

  SerialMon.print(F("Body length is: "));
  SerialMon.println(body.length());

  // Shutdown

  http.stop();
  SerialMon.println(F("Server disconnected"));

#if TINY_GSM_USE_WIFI
    modem.networkDisconnect();
    SerialMon.println(F("WiFi disconnected"));
#endif
#if TINY_GSM_USE_GPRS
    modem.gprsDisconnect();
    SerialMon.println(F("GPRS disconnected"));
#endif

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

It would get to the part where it attempts the HTTP request and would fail so I added a line that posts a value to thingspeak and now it crashes with this output

Initializing modem...
[6125] ### TinyGSM Version: 0.10.1
[6125] ### TinyGSM Compiled Module:  TinyGsmClientA6
[12064] ### Modem: Ai Thinker Co.LTD A6
[12064] ### Modem: Ai Thinker Co.LTD A6
Modem Info: ^CINIT: 8, 2048, 1  Ai Thinker Co.LTD A6  V03.03.20161229019H03
Waiting for network... success
Network connected
Connecting to api.thingspeak.com success
GPRS connected
Guru Meditation Error: Core  1 panic'ed (LoadProhibited). Exception was unhandled.
Core 1 register dump:
PC      : 0x400d12b8  PS      : 0x00060130  A0      : 0x800d2ca0  A1      : 0x3ffb1f30  
A2      : 0x3ffc0468  A3      : 0x000fa09a  A4      : 0x3ffb1f80  A5      : 0x3f401384  
A6      : 0x00000000  A7      : 0x00000000  A8      : 0x800d511a  A9      : 0x3ffb1f10  
A10     : 0x00000000  A11     : 0x3ffb1f74  A12     : 0x00000050  A13     : 0x0000000a  
A14     : 0x3ffb1f74  A15     : 0xff000000  SAR     : 0x00000010  EXCCAUSE: 0x0000001c  
EXCVADDR: 0x00000000  LBEG    : 0x4000c46c  LEND    : 0x4000c477  LCOUNT  : 0xffffffff  
Backtrace: 0x400d12b8:0x3ffb1f30 0x400d2c9d:0x3ffb1f50 0x400d5761:0x3ffb1fb0 0x400884d9:0x3ffb1fd0

I used the exception decoder and got this as an output from that tool

PC: 0x400d12b8: ThingSpeakClass::writeRaw(unsigned long, String, char const*) at E:\Users\Koby_2\Documents\Arduino\sketchbook ofline\libraries\ThingSpeak\src/ThingSpeak.h line 1521
EXCVADDR: 0x00000000
Decoding stack results
0x400d12b8: ThingSpeakClass::writeRaw(unsigned long, String, char const*) at E:\Users\Koby_2\Documents\Arduino\sketchbook ofline\libraries\ThingSpeak\src/ThingSpeak.h line 1521
0x400d2c9d: loop() at E:\Users\Koby_2\Documents\Arduino\sketchbook ofline\libraries\ThingSpeak\src/ThingSpeak.h line 282
0x400d5761: loopTask(void*) at E:\Users\Koby_2\AppData\Local\Arduino15\packages\esp32\hardware\esp32\1.0.4\cores\esp32\main.cpp line 19
0x400884d9: vPortTaskWrapper at /home/runner/work/esp32-arduino-lib-builder/esp32-arduino-lib-builder/esp-idf/components/freertos/port.c line 143

On line 208 of your code you use the Thingspeak library although you don't have a WiFi connection set up. Remove that line, it cannot work in your setup.