vshymanskyy / TinyGSM

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

PyCom GPy/LTE ... success & question #579

Open pottendo opened 2 years ago

pottendo commented 2 years ago

hi,

upfront I can report, that I've managed to get PyCom's GPy working with a LTE NB-IoT SIM Card both with/without using GPRS within the Arduino framework. ...at least with the simple MQTT example. Haven't tried too much more yet. Some people report here and elsewhere to have troubles with PyComs, so I thought to share my experience here.

My setup:

Using the mqtt example I needed to adjust the setup function slightly:

define SerialAT Serial2

void setup() { [...] // Set LTE modem Serial SerialAT.begin(LTE_BAUD, SERIAL_8N1, LTE_RX, LTE_TX); pinMode(LTE_RTS, OUTPUT); digitalWrite(LTE_RTS, LOW);

// remove the TinyGsmAutoBaud(... line and add mode.setBaud(LTE_BAUD); [...] (note that the proper LTE_xxx macros are provided by the BSP within the platformIO)

First the setup didn't connect properly and activating the stream debugger I found that the protocol failed when trying to use PDP context 3 when trying to get the IP address: e.g. in TinyGsmClientSequansMonarch.h [...] String getLocalIPImpl() { sendAT(GF("+CGPADDR=3")); if (waitResponse(10000L, GF("+CGPADDR: 3,\"")) != 1) { return ""; } String res = stream.readStringUntil('\"'); waitResponse(); [...] here I changed to CGPADDR=1 and in the response respectively and the I got a valid IP address.

Consequently I've changed here [...] bool gprsConnectImpl(const char apn, const char user = NULL, const char* pwd = NULL) { gprsDisconnect(); // Define the PDP context (This uses context #3!) sendAT(GF("+CGDCONT=3,\"IPV4V6\",\""), apn, '"'); waitResponse(); [...] to "...CGDCONT=1..." here and some more places in this function.

Ultimately this brought a successful GPRS connection, finally it needed also some tweaking when configuring a socket: [...] bool modemConnect(const char* host, uint16_t port, uint8_t mux, bool ssl = false, int timeout_s = 75) { ... // Socket configuration // AT+SQNSCFG:, , , , , // = Connection ID = mux // = PDP context ID = 3 - this is number set up above in the // GprsConnect function // = Packet Size, used for online data mode only = 300 (default) // = Max timeout in seconds = 90 (default) // = Connection timeout in hundreds of milliseconds // = 600 (default) // = Data sending timeout in hundreds of milliseconds, // used for online data mode only = 50 (default) sendAT(GF("+SQNSCFG="), mux, GF(",3,300,90,600,50")); waitResponse(5000L); [...] change to 'sendAT(...GF(",1,300,90...

I'm not an expert at all, so I may have tweaked the wrong things - however, it seems to work (I've exchanged some MQTT messages via a public broker)

I can't say why this changes are needed - find attached a sample log before the changes. Any hints to 'fix' this correctly are appreciated.

bye, pottendo

tgsm.log

EdmondFurax commented 1 year ago

Hi, I lost 2 days to arrive at the same conclusion with FiPy on arduino (didn't see this thread). It seems that roaming in France with a 1nce subscription, PDP context 3 cannot be accessed . Using context 1 did the trick (changing the same lines), so I guess it would be nice to be able to adda a method to specify pdp context. tinyGSM is a great library. Cheers Edmond