vshymanskyy / TinyGSM

A small Arduino library for GSM modules, that just works
GNU Lesser General Public License v3.0
1.91k stars 713 forks source link

### Unhandled: +CIPRXGET: 1,0 in MQTT client #462

Closed imamminer closed 3 years ago

imamminer commented 3 years ago

[ x] Bug or issue with library functionality (ie, sending data over TCP/IP) [ x] Question or request for help

Trying to Connect to broker.hivemq.com and update ledstatus. Connection is successful but the incoming data is not handled correctly and ledstatus does not update.

This code worked fine for many weeks until 3 days ago. Tried deleting library and installing various versions through IDE but to no avail.

Problem Experienced-how to process following incoming data? : '### Unhandled: +CIPRXGET: 1,0 ' Could these foreign characters be an issue for CIPSEND and RXGET(See Serial Monitor Output Below)? Example. '>MQTTGsmClientTest '

Currently working with:

[11660] ### TinyGSM Version: 0.10.9 [11660] ### TinyGSM Compiled Module: TinyGsmClientSIM800 [11844] ### Modem: SIMCOM SIM868 [11844] ### Modem: SIMCOM SIM868 Modem Info: SIM868 R14.18 Main processor board: ESP8266 TinyGSM version: TinyGSM Version: 0.10.9

Code Used: MQTT Client Example Code

`/** *

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

// Set serial for AT commands (to the module) // Use Hardware Serial on Mega, Leonardo, Micro

define SerialAT Serial

// or Software Serial on Uno, Nano //#include //SoftwareSerial SerialAT(2, 3); // RX, TX

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

define GSM_AUTOBAUD_MIN 4800

define GSM_AUTOBAUD_MAX 4800

// 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[] = "unrestricted"; 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

include

// 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 debugger(SerialAT, SerialMon); TinyGsm modem(debugger);

else

TinyGsm modem(SerialAT);

endif

TinyGsmClient client(modem); PubSubClient mqtt(client);

define LED_PIN 5

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 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"); }

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() {

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(); }`

Serial monitor Output:

`[78] Trying baud rate 4800 ... [4167] Modem responded at rate 4800 Initializing modem... AT

OK AT&W

OK AT+CFUN=0

OK AT+CFUN=1,1

OK [13330] ### TinyGSM Version: 0.10.9 [13331] ### TinyGSM Compiled Module: TinyGsmClientSIM800 AT

OK ATE0

OK AT+CMEE=2

OK AT+GMM

SIMCOM_SIM868

OK [13515] ### Modem: SIMCOM SIM868 [13515] ### Modem: SIMCOM SIM868 AT+CLTS=1

OK AT+CBATCHK=1

OK AT+CPIN?

+CME ERROR: SIM busy AT+CPIN?

+CPIN: READY

+CPIN: READY

OK ATI

SIM868 R14.18

OK Modem Info: SIM868 R14.18 AT+CPIN?

+CPIN: READY

OK Waiting for network...AT+CREG?

+CREG: 0,2

OK AT+CREG?

+CREG: 0,2

OK AT+CREG?

Call Ready

+CREG: 0,2

OK AT+CREG?

+CREG: 0,2

OK AT+CREG?

SMS Ready

+CREG: 0,2

OK AT+CREG?

+CREG: 0,2

OK AT+CREG?

+CREG: 0,2

OK AT+CREG?

+CREG: 0,2

OK AT+CREG?

+CREG: 0,2

OK AT+CREG?

+CREG: 0,2

OK AT+CREG?

+CREG: 0,2

OK AT+CREG?

+CREG: 0,2

OK AT+CREG?

+CREG: 0,2

OK AT+CREG?

+CREG: 0,2

OK AT+CREG?

+CREG: 0,2

OK AT+CREG?

+CREG: 0,2

OK AT+CREG?

+CREG: 0,2

OK AT+CREG?

+CREG: 0,2

OK AT+CREG?

+CREG: 0,2

OK AT+CREG?

+CREG: 0,2

OK AT+CREG?

+CREG: 0,2

OK AT+CREG?

+CREG: 0,2

OK AT+CREG?

+CREG: 0,2

OK AT+CREG?

+CREG: 0,2

OK AT+CREG?

+CREG: 0,2

OK AT+CREG?

+CREG: 0,2

OK AT+CREG?

+CREG: 0,2

OK AT+CREG?

+CREG: 0,2

OK AT+CREG?

+CREG: 0,2

OK AT+CREG?

+CREG: 0,2

OK AT+CREG?

+CREG: 0,2

OK AT+CREG?

+CIEV: 10,"65502","Telkom-Stay","Telkom-Stay", 0, 0

+CREG: 0,2

OK AT+CREG?

+CREG: 0,1

OK success AT+CREG?

+CREG: 0,1

OK Network connected Connecting to unrestrictedAT+CIPSHUT

SHUT OK AT+CGATT=0

OK AT+SAPBR=3,1,"Contype","GPRS"

OK AT+SAPBR=3,1,"APN","unrestricted"

OK AT+CGDCONT=1,"IP","unrestricted"

OK AT+CGACT=1,1

OK AT+SAPBR=1,1

OK AT+SAPBR=2,1

+SAPBR: 1,1,"41.144.149.175"

OK AT+CGATT=1

OK AT+CIPMUX=1

OK AT+CIPQSEND=1

OK AT+CIPRXGET=1

OK AT+CSTT="unrestricted","",""

OK AT+CIICR

OK AT+CIFSR;E0

41.144.149.175

OK AT+CDNSCFG="8.8.8.8","8.8.4.4"

OK success AT+CGATT?

+CGATT: 1

OK AT+CIFSR;E0

41.144.149.175

OK GPRS connected AT+CIPRXGET=4,0

+CIPRXGET: 4,0,0

OK AT+CIPSTATUS=0

+CIPSTATUS: 0,,"","","","INITIAL"

OK === MQTT NOT CONNECTED === Connecting to broker.hivemq.comAT+CIPCLOSE=0,1

+CME ERROR: operation not allowed AT+CIPSSL=0

OK AT+CIPSTART=0,"TCP","broker.hivemq.com",1883

OK

0, CONNECT OK AT+CIPSEND=0,27

MQTTGsmClientTest DATA ACCEPT:0,27 AT+CIPRXGET=4,0

+CIPRXGET: 4,0,0

OK AT+CIPSTATUS=0

+CIPSTATUS: 0,0,"TCP","52.57.177.211","1883","CONNECTED"

OK AT+CIPRXGET=4,0

+CIPRXGET: 4,0,0

OK AT+CIPSTATUS=0

+CIPSTATUS: 0,0,"TCP","52.57.177.211","1883","CONNECTED"

OK

+CIPRX[37393] ### Unhandled: +CIPRX GET: 1,0[37409] ### Unhandled: GET: 1,0

AT+CIPRXGET=4,0

+CIPRXGET: 4,0,4

OK AT+CIPRXGET=2,0,4

+CIPRXGET: 2,0,4,0 `

imamminer commented 3 years ago

Hi

Could someone possibly assist with this? Having a difficult time trying to resolve.

SRGDamia1 commented 3 years ago

Try using the TINY_GSM_YIELD.

imamminer commented 3 years ago

Hi

Try using the TINY_GSM_YIELD.

Hi

Thanks for this suggestion. It appears to have resolved the issue!

regards

SRGDamia1 commented 3 years ago

Great!

imamminer commented 3 years ago

Hi

is it possible to re open this thread as the solution seems intermittent?

the mqtt broker connects successfully but the gsm rxget data is not read correctly possibly because of some foreign characters the square box characters "" or question marks. so the result is that i do not receive MQTT topic "Message Arrived" data and the LED does not turn on or off.

`+CIPSTATUS: 0,,"","","","INITIAL"

OK AT+CIPCLOSE=0,1

+CME ERROR: operation not allowed AT+CIPSSL=0

OK AT+CIPSTART=0,"TCP","broker.hivemq.com",1883

OK

0, CONNECT OK AT+CIPSEND=0,27

MQTTGsmClientTest DATA ACCEPT:0,27 AT+CIPRXGET=4,0

+CIPRXGET: 4,0,0

OK AT+CIPSTATUS=0

+CIPSTATUS: 0,0,"TCP","18.197.64.250","1883","CONNECTED"

OK

+CIPRXGET: 1,0 AT+CIPRXGET=4,0

+CIPRXGET: 4,0,4

OK AT+CIPRXGET=2,0,4

+CIPRXGET: 2,0,4,0 OK success AT+CIPRXGET=4,0

+CIPRXGET: 4,0,0

OK AT+CIPSTATUS=0

+CIPSTATUS: 0,0,"TCP","18.197.64.250","1883","CONNECTED"

OK AT+CIPSEND=0,43

0)GsmClientTest/initGsmClientTest started DATA ACCEPT:0,43 AT+CIPRXGET=4,0

+CIPRXGET: 4,0,0

OK AT+CIPSTATUS=0

+CIPSTATUS: 0,0,"TCP","18.197.64.250","1883","CONNECTED"

OK AT+CIPSEND=0,24

⸮GsmClientTest/led DATA ACCEPT:0,24 AT+CIPRXGET=4,0

+CIPRXGET: 4,0,0

OK AT+CIPSTATUS=0

+CIPSTATUS: 0,0,"TCP","18.197.64.250","1883","CONNECTED"

OK

+CIPRXGET: 1,0 AT+CIPRXGET=4,0

+CIPRXGET: 4,0,5

OK AT+CIPRXGET=2,0,5

+CIPRXGET: 2,0,5,0 ⸮ OK AT+CIPRXGET=4,0

+CIPRXGET: 4,0,0

OK AT+CIPSTATUS=0

+CIPSTATUS: 0,0,"TCP","18.197.64.250","1883","CONNECTED"

OK AT+CIPRXGET=4,0

+CIPRXGET: 4,0,0

OK AT+CIPSTATUS=0

+CIPSTATUS: 0,0,"TCP","18.197.64.250","1883","CONNECTED"

OK AT+CIPRXGET=4,0

+CIPRXGET: 4,0,0

OK AT+CIPSTATUS=0

+CIPSTATUS: 0,0,"TCP","18.197.64.250","1883","CONNECTED"

OK AT+CIPRXGET=4,0

+CIPRXGET: 4,0,0

OK AT+CIPSTATUS=0

+CIPSTATUS: 0,0,"TCP","18.197.64.250","1883","CONNECTED"

OK AT+CIPRXGET=4,0 `