Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[M590] LIbrary not working on ESP32 #91

Closed
thomasklingbeil opened this issue Oct 10, 2017 · 14 comments
Closed

[M590] LIbrary not working on ESP32 #91

thomasklingbeil opened this issue Oct 10, 2017 · 14 comments

Comments

@thomasklingbeil
Copy link

thomasklingbeil commented Oct 10, 2017

As already described in issue #81, using HardwareSerial on ESP32 does not work with the library.
If transferring the data "manually" in a simple sketch, everything works fine.

With the TinyGSM library, a lot of random characters show up during the communication, rendering all results unusable.

rst:0x10 (RTCWDT_RTC_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
configsip: 0, SPIWP:0xee
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
mode:DIO, clock div:1
load:0x3fff0010,len:4
load:0x3fff0014,len:588
load:0x40078000,len:0
load:0x40078000,len:9880
entry 0x400789d8
Initializing modem...ATE0

OK
AT&FZE0
 fail
************************
 Is your modem connected properly?
 Is your serial speed (baud rate) correct?
 Is your modem powered on?
 Do you use a good, stable power source?
 Try useing File -> Examples -> TinyGSM -> tools -> AT_Debug to find correct configuration
************************
Waiting for network...AT+CREG?
AT+CREG?
AT+CREG?
AT+CREG?
AT+CREG?
AT+CREG?
AT+CREG?
AT+CREG?
AT+CREG?
AT+CREG?
AT+CREG?
AT+CREG?
AT+CREG?
G: 0,1
�������"]��RAT+CREG?
AT+CREG?
AT+CREG?
AT+CREG?
AT+CREG?
AT+CREG?
AT+CREG?
AT+CREG?
AT+CREG?

m590

Code used:

HardwareSerial mySerial(2);

void setup() {
    // put your setup code here, to run once:
    Serial.begin(115200);
    mySerial.begin(115200, SERIAL_8N1, 32, 33);
    Serial.print("Let's go");
}

void loop() {
  while (mySerial.available() > 0) {
    Serial.write(mySerial.read());
  }
  if (Serial.available()) {
    mySerial.write(Serial.read());
  }
}
@thomasklingbeil
Copy link
Author

thomasklingbeil commented Oct 11, 2017

The problem seems to be related to the implementation of HardwareSerial for ESP32. With the most recent git state, things seems to be better (see also espressif/arduino-esp32#665)

EDIT: Even though, some more things seem to work (i.e. sending commands from my own code), the library still does not work - it seems as if it does not receive the answers from the module.
I have also tried the same thing with an A7 - same problem.

Both modules, connected to an ESP8266 with SoftwareSerial --> Working without any problems... So it seems to have something to do with the ESP32's Serial implementation...

@vshymanskyy
Copy link
Owner

I'll re-check this once I get some spare time. Thanks!

@papawattu
Copy link

papawattu commented Jan 6, 2018

Hi

I am getting a similar issue, I am seeing the following.

image

Jamie.

@papawattu
Copy link

papawattu commented Jan 8, 2018

Looks like my issue was unrelated to this maybe, I am using a Adafruit Huzzah 32. I switched to using UART1 (2nd one). I had to pass the pin numbers and "false" to the begin method call. This works fine now, hope this helps someone else.

HardwareSerial Serial1(1);

#define SerialAT Serial1

TinyGsm modem(SerialAT);
TinyGsmClient client(modem);

void setup() {
  SerialAT.begin(115200,SERIAL_8N1,16,17,false);
  delay(3000);
  modem.restart();
}

Jamie.

@ankgt
Copy link

ankgt commented Mar 10, 2018

@papawattu I'm facing a similar issue, and trying to understand your solution. If you switched to UART1, does that mean you can no longer use the USB port on your board to monitor the program? Thanks!

@abhaysbharadwaj
Copy link

abhaysbharadwaj commented Dec 1, 2018

@papawattu , @vshymanskyy , I can confirm that TinyGSM is working flawlessly on my ESP32.
As per comment, I have added the following before setup():
HardwareSerial gsmSerial(1); // (1) implies serial 1
TinyGsm modem(gsmSerial);
TinyGsmClient client(modem);
PubSubClient mqtt(client);

and in setup:
gsmSerial.begin(115200, SERIAL_8N1, 18, 19, false); // i am remapping serial1 pins to 18 and 19

image

Edit: I have uploaded my working code here:
https://github.com/abhaysbharadwaj/esp32-gsm-gps

@jrutke
Copy link

jrutke commented Dec 9, 2018

I have a problem with gprs connection in my ESP32. Don't find the modem. WIth AT command's its working. Can someone help me?

@abhaysbharadwaj, how did you use?

@vitzaoral
Copy link

vitzaoral commented Dec 9, 2018

I can't connect SIM800L EVB version to my Espressif ESP32-WROOM-32 developer kit. I'm using UART 2 connection (SIM800L TX -> ESP32 TX2, SIM800L RX -> ESP32 RX2, GND is same picture here). I think there is no problem with power supply, I can call to SIM800L, it blinks every 3sec so it's connected to network.

I'm using code as was described above:

HardwareSerial gsmSerial(2);
TinyGsm modem(gsmSerial);

void setup()
{
 // Set GSM module baud rate
  gsmSerial.begin(115200, SERIAL_8N1, 16, 17, false);
....

There is no response from SIM800L. Am I doing something wrong, or is EVB version somehow different from "classic" red SIM800l?
Thank you.

@remenyo
Copy link

remenyo commented Apr 20, 2019

@vitzaoral
You connected RX to RX and TX to TX, but you have to connect RX into TX, and TX into RX.
Wiring and Hardware of UART devices

@MahmoudMohamedAli
Copy link

MahmoudMohamedAli commented Oct 26, 2021

i have problem with gsm a6/ai it can't establish connection to mqtt serve
problem_5
problem2
problem_3
r

@sass00
Copy link

sass00 commented Jan 23, 2022

Hey guys,

Have a problem with my ESP32. Using DevKitC V4 with Wrower. Trying to hook up SIM800L. My unit is connected, i can type AT commands through USB-TTL. Light flashes as its connected to the network.

My device is defined as serial2 on pins 16, 17. When i start my ESP it cant initialize modem. Tried example sketeches of both TinyGSM and FONA library. Works normally directly through serial on arduino (i short RST to GND) so i know the SIM module is working.

#define SerialMon Serial
#define TINY_GSM_MODEM_SIM800
#include <TinyGsmClient.h> //
HardwareSerial SerialGSM(2);
TinyGsm modemGSM(SerialGSM);
const int BAUD_RATE = 9600;
long int millisRefCon, millisUserResp;
bool flagCon = false, flagUserResp = false;
const int relayPin1 = 14, relayPin2 = 12, relayPin3 = 13, relayPin4 = 27, RX_PIN = 16, TX_PIN = 17;
const char *APN = "internet";
const char *USER = "mobitel";

my void setupGSM;
Serial.println("Setup GSM...");
SerialGSM.begin(BAUD_RATE, SERIAL_8N1, 16, 17, false);
delay(2000);
Serial.println(modemGSM.getModemInfo());
Serial.println(modemGSM.getOperator());
Serial.println(modemGSM.testAT());
Serial.println(modemGSM.getModemName());
Serial.println(modemGSM.getSimStatus());
Serial.println(modemGSM.getIMEI());
Serial.println(modemGSM.isNetworkConnected());

My serial monitor output;
Setup GSM...

0
SIMCom SIM800
0

0
Restarting GSM
Modem failed

This is my code. Tried different baud rates, inverting RX/TX pins, different UART, ... nothing works. I'm just using the sim800 to trigger relays and send temp and humidity status.

I am powering my SIM800L from a outer power supply with 3A max. My wiring is GND->GND; TX->17; RX->16; GND->GND. Tried also rreversing RX/TX. I'm using V2 of the SIM800 (EVB version).

I'm a bit depressed allready :)

P.S also tried with;
#define SerialGSM Serial2

@CcKefa
Copy link

CcKefa commented Jan 9, 2024

Was this issue resolved? I'm having the same issue and using UART1 does not solve it.

@live-alchemy
Copy link

live-alchemy commented Feb 23, 2024

@CcKefa @sass00 took me some time to get this working, I'll paste the important parts for reference maybe it helps you as well. I had to instantiate my serial connection to the LTE module as a HardwareSerial and pass it (1) so it would use the Uart1 option. Then later, in the SerialAt.begin() call, I pass the RX & TX pins that map to Uart1 on my device, in this case 18 and 17. Notice in the diagram how these are labelled U1RXD and U1TXD. Maybe that's obvious but for me it was a missing link, the diagrams here helped me as well.

Also, my LTE module uses 115200 baud rate, so I have passed that in as well, but if you are unclear what baud rate your LTE module uses then use this AT_Debug sketch to try and find that first

#define SerialMon Serial
HardwareSerial SerialAT(1);

#define PIN_TX              17
#define PIN_RX              18

#include <TinyGsmClient.h>

TinyGsm        modem(SerialAT);
TinyGsmClient  client(modem);

void setup() {
    SerialMon.begin(115200);
    SerialAT.begin(115200, SERIAL_8N1, PIN_RX, PIN_TX, false);
}

Another detail is that I am supplying power to my LTE module via micro usb plugged in to the wall, so the only connection from my ESP32 to the LTE module is 1 GND connection and the TX/RX. I'm not sure about your ESP32 units, but mine does not output 5V power so I had to supply it elsewhere.

@lukwagohakim
Copy link

lukwagohakim commented Jul 22, 2024

has anyone used a7672e?

is there an issue with its connection to server for both tinyGsm webClient and mqttClient examples?

my connections:

ES32--------->A7672EIMAGE

MRX---------->G17
MTX---------->G16
RI---------->G19
DTR---------->G18
GND--------->GND
POWER THROUGH MICROUSB IN WALL SOCKET
I also tried 5V-------->VIN

below is my mqttClient code

`/**************************************************************
*


  • This example connects to HiveMQ's showcase broker.
  • You can quickly test sending and receiving messages from the HiveMQ webclient
  • available at http://www.hivemq.com/demos/websocket-client/.
  • Subscribe to the topic GsmClientTest/ledStatus
  • Publish "toggle" to the topic GsmClientTest/led and the LED on your board
  • should toggle and you should see a new message published to
  • GsmClientTest/ledStatus with the newest LED status.

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

// 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_SIM7000SSL
// #define TINY_GSM_MODEM_SIM7080
// #define TINY_GSM_MODEM_SIM5360
// #define TINY_GSM_MODEM_SIM7600
#define TINY_GSM_MODEM_A7672X
// #define TINY_GSM_MODEM_UBLOX
// #define TINY_GSM_MODEM_SARAR4
// #define TINY_GSM_MODEM_SARAR5
// #define TINY_GSM_MODEM_M95
// #define TINY_GSM_MODEM_BG95
// #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_ESP32
// #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 <HardwareSerial.h>

HardwareSerial SerialAT(2);

// Define the DTR and RI pins used for hardware flow control
const int dtrPin = 18;
const int riPin = 19;

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

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

// Range to attempt to autobaud
// NOTE: DO NOT AUTOBAUD in production code. Once you've established
// communication, set a fixed baud rate using modem.setBaud(#).
#define GSM_AUTOBAUD_MIN 9600
#define GSM_AUTOBAUD_MAX 115200

// Add a reception delay, if needed.
// This 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.
// This is only needed for this example, not in other code.
#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[] = "internet";
const char gprsUser[] = "";
const char gprsPass[] = "";

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

// MQTT details
const char* broker = "broker.hivemq.com";

const char* topicLed = "GsmClientTest/led";
const char* topicInit = "GsmClientTest/init";
const char* topicLedStatus = "GsmClientTest/ledStatus";

#include <TinyGsmClient.h>
#include <PubSubClient.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);
PubSubClient mqtt(client);

#define LED_PIN 2
int ledStatus = LOW;

uint32_t lastReconnectAttempt = 0;

void mqttCallback(char* topic, byte* payload, unsigned int len) {
SerialMon.print("Message arrived [");
SerialMon.print(topic);
SerialMon.print("]: ");
SerialMon.write(payload, len);
SerialMon.println();

// Only proceed if incoming message's topic matches
if (String(topic) == topicLed) {
ledStatus = !ledStatus;
digitalWrite(LED_PIN, ledStatus);
mqtt.publish(topicLedStatus, ledStatus ? "1" : "0");
}
}

boolean mqttConnect() {
SerialMon.print("Connecting to ");
SerialMon.print(broker);

// Connect to MQTT Broker
boolean status = mqtt.connect("GsmClientTest");

// Or, if you want to authenticate MQTT:
// boolean status = mqtt.connect("GsmClientName", "mqtt_user", "mqtt_pass");

if (status == false) {
SerialMon.println(" fail");
return false;
}
SerialMon.println(" success");
mqtt.publish(topicInit, "GsmClientTest started");
mqtt.subscribe(topicLed);
return mqtt.connected();
}

void setup() {

// Set the DTR and RI pins as outputs and initialize them to HIGH
pinMode(dtrPin, OUTPUT);
digitalWrite(dtrPin, HIGH);
pinMode(riPin, OUTPUT);
digitalWrite(riPin, HIGH);

// Set the DTR pin LOW to signal the SIM7672S module to start sending data
digitalWrite(dtrPin, LOW);

SerialAT.begin(115200, SERIAL_8N1, 16, 17);
//SerialAT.print("ATD+256708542917;\r\n");

delay(10000);

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

pinMode(LED_PIN, OUTPUT);

// !!!!!!!!!!!
// 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(6000);

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

#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"); }
//delay(30000);
#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"); }
#endif

// MQTT Broker setup
mqtt.setServer(broker, 1883);
mqtt.setCallback(mqttCallback);
}

void loop() {
// Make sure we're still registered on the network
if (!modem.isNetworkConnected()) {
SerialMon.println("Network disconnected");
if (!modem.waitForNetwork(180000L, true)) {
SerialMon.println(" fail");
delay(10000);
return;
}
if (modem.isNetworkConnected()) {
SerialMon.println("Network re-connected");
}

#if TINY_GSM_USE_GPRS
// and make sure GPRS/EPS is still connected
if (!modem.isGprsConnected()) {
SerialMon.println("GPRS disconnected!");
SerialMon.print(F("Connecting to "));
SerialMon.print(apn);
if (!modem.gprsConnect(apn, gprsUser, gprsPass)) {
SerialMon.println(" fail");
delay(10000);
return;
}
if (modem.isGprsConnected()) { SerialMon.println("GPRS reconnected"); }
}
#endif
}

if (!mqtt.connected()) {
SerialMon.println("=== MQTT NOT CONNECTED ===");
// Reconnect every 10 seconds
uint32_t t = millis();
if (t - lastReconnectAttempt > 10000L) {
lastReconnectAttempt = t;
if (mqttConnect()) { lastReconnectAttempt = 0; }
}
delay(100);
return;
}

mqtt.loop();
}
`

the output is:

Wait...
Initializing modem...
[20347] ### Unhandled: *ATREADY: 1
0
[21347] ### Unhandled: ATI

Manufacturer: INCORPORATED
Model: A7672E-FASE
Revision: A7672M7_V1.11.1
IMEI: ***************
Modem Info:
Waiting for network...[23689] ### Unhandled: SMS DONE
[24939] ### Unhandled: <@x +XpxAT+CR
[26189] ### Unhandled: AT+CREG?

ERROR
[27444] ### Unhandled: ~
success
Network connected
Connecting to internet[88498] ### Unhandled: AT+CGACT=1,1

OK

PB DONE
success
GPRS connected
=== MQTT NOT CONNECTED ===
Connecting to broker.hivemq.com[92567] ### Unhandled: AT+CIPACK=0

+IP ERRO
fail

best regards
Lukwago

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests