Git Product home page Git Product logo

mkrnb's Introduction

MKRNB Library for Arduino

Compile Examples Status Spell Check Status

This library enables an Arduino MKR NB 1500 board to connect to the internet over a NarrowBand IoT or LTE Cat M1 network.

For more information about this library please visit us at https://www.arduino.cc/en/Reference/MKRNB

License

Copyright (c) 2018 Arduino SA. All rights reserved.

This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version.

This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA

mkrnb's People

Contributors

aentinger avatar baender avatar ccorrado avatar cptholzschnauz avatar dependabot[bot] avatar facchinm avatar giulcioffi avatar janakelarsson avatar jscott304 avatar karlsoderby avatar patrick-mcguire avatar per1234 avatar rocketct avatar sandeepmistry avatar ubidefeo avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

mkrnb's Issues

MKR NB1500 - mqttClient.connect(broker, port) retry failed

Hi all,

Iam actually testing the project:
Arduino_Cloud_Provider_Examples -> Azure IoT Hub -> Azure_IoT_Hub_NB

In the most cases the "mqttClient.connectError()" returns the value "3".
Error-Code for: "MQTT_SERVER_UNAVAILABLE "

Out 1 of 100 tests to connect the mqttClient works fine. Then the connection to the azure-hub is successfully and I can do what I want to send datas to the Azure-Hub.
But if I start the sketch again, the mqttclint.connect() shows an error (MQTT_SERVER_UNAVAILABLE) again and then the NB 1500 crashed and hangs up during the loop.

while (!mqttClient.connect(broker, 8883))
 {
    // failed, retry
    Serial.print(".");
    Serial.println(mqttClient.connectError());
    delay(5000);
  } 

It seems like a problem in the mqttClient.connect(broker,8883).
After debugging the sourcecode of NBSSLClient.cpp and NBClient.cpp it shows, that the retry of the loop doesn't work, because the connectio over the SIM-Network cant connect to mqtt-broker or the communication of the network is too slow. (presumable)

It's rather strange that it works once and then never again.

The problem can you see in the following pictures:
ERRORCODE 3
59689623-44885d00-91e0-11e9-953b-5284b3244652
Successfully connect with mqtt to Azure-Hub
59689624-4520f380-91e0-11e9-9ea6-15e6aaae2e49

Changes in NBClient.cpp:
MODEM.sendf("AT+USOCO=%d,"%s","%d",%d", _socket, _host, _port, 1);
This change helps to retry after connection failed.

Serial-Output:

CLIENT_STATE_CONNECT, socket: 0
CLIENT_STATE_CONNECT, host: RadarIOT.azure-devices.net
CLIENT_STATE_CONNECT, port: 8883
AT+USOCO=0,"RadarIOT.azure-devices.net","8883",1
OK
AT+USOWR=0,229,"message"
ERROR
.0 (int returnValue = mqttClient.connect(broker, 8883);) returns 0 if not connected
3 (mqttClient.connectError() returns 3 if server unavailable
Retry

After this change you can see the retry still working but the connect still does not work...

measuring buildung:

  • MKR NB 1500
  • Antenna
  • LiPo 3,7V

Thanks in advance.

Greetings Splitout

Network led

I noticed that the network led is not blinking when the board is connected to the network. Is this "by design"?

For instance, in this sketch for the MKR GSM 1400 the network led is always flashing. However, in this sketch for the MKR NB 1500 the network led has never come on, even though, it's posting it's json data every hour, or if you like every 3 min, etc.

Unpredictable +CME ERROR after hours of AT+USOWR

Hi

I'm able to send data over a socket with AT+USOWR for hours and hours and out of the blue i get a
+CME ERROR: Operation not allowed
and after that, the modem is totally paralized and does not react at all anymore, only a hardware reset brings it back to live.
Reproduced on 3 different MKRs, all within the timeouts, the other side does not disconnect, the payload is ok, the buffer is correct (The AT+USOWR is formated right). As i said before, the same command works well for hours.
After the failure, the modems Internal TCP/UDP/IP stack class error codes (Get Socket Error +USOER)
is 65 EEOF - End of file.

  • I know bugs like these are very hard to track down, any hints?
  • Wouldn't it be nice to have an error handler to handle this?

Logs:
For hours:

AT+USOWR=1,310,"Here are 620 bytes, i just delete for better readability"
-> +USOWR: 1,310
->
-> OK

And then, sometimes after minutes, sometimes after hours:
19:31:14.010 -> AT+USOWR=1,310,"Here are 620 bytes, i just delete for better readability"
19:31:20.182 -> +CME ERROR: Operation not allowed
and the modem does not answer anymore until a hard reset.

New SIM card initialization? (CAT-M1)

If the SIM card is brand new it seems some sort of initialization is required to get a carrier. I have reproduced this with two different SIM:s from different carriers. Inserting it directly to the MKR1500 do not work. However, putting the SIM in a phone then back in MKR1500 fixes it.
Anyone ideas what is going on?

Apparent conflict with I2C Wire library

I have not been able to connect to I2C devices on a MKR1500. The I2C device seems to stop responding after the MKRNB library is added to the sketch. I used a TCS34725 I2C light sensor to test, and tested with the Adafruit TCS34725 lib and Hideaki Tai's library.

Steps to test:

  1. attach sensor to board via A4 and A5
  2. run basic example sketches from sensor libraries (this one and this one). Both libraries gave sensor data
  3. Confirm MKRNB is working with this sketch
  4. Add MKRNB library and basic connection header to sketch (lines 18, 26-28 and 48-46 of this sketch)

After adding the MKRNB lines on step 4, neither I2C library would get past the sensor .begin() line. I was able to duplicate the error by loading a blank sketch on the board and repeating steps 1-4 for both sensors, but I didn't get further than that. Sadly, I had no other I2C sensors in the house to test with.

detachGPRS

It seems like detachGPRS does not work. The function sets

_state = GPRS_STATE_DEATTACH;

and calls the ready function to fire the AT command AT+CGATT=0.
The ready function waits till there is a response (GPRS_STATE_WAIT_DEATTACH_RESPONSE) and sets _status to IDLE if everything was fine. Because in this state ready is never set to 1 again, the ready function stays in an infinite loop, because the function returns zero at the beginning of the function (if (ready == 0)).

Can't read data from socket because MKRNB creates multiple UDP sockets.

It took us some time to figure out, but sockets doesn't always gracefully close, making it impossible to read data from a socket.

Our software creates a UDP Socket on setup and listen to the data it receives. However, when the device is not shutdown for a proper amount of time (5s), the socket is never closed, making it impossible to read the data that the socket receive because it creates a new socket and the library only listens to the second socket.

This might be a SARA-R4 specific issue, but we realized that we needed to clear every socket on boot to make sure a SINGLE UDP socket is connected and being listened to.

The NBSSLWebClient.ino example works only on webhook.site and aftenposten.no, but not on most other HTTPS sites

When I run examples/NBSSLWebClient/NBSSLWebClient.ino, the simple example for connecting to an HTTPS/SSL web server, it only works on a few sites.

It works on:

It does not work on:

If i enable debugging mode (change line 28 from NB nbAccess; to NB nbAccess(true)), I get the following error:

00:33:42.216 -> AT+USOSEC=0,1,0
00:33:42.216 -> OK
00:33:42.406 -> AT+USECPRF=0,0,1
00:33:42.406 -> OK
00:33:42.616 -> AT+USOCO=0,"letsencrypt.org",443
00:33:42.909 -> ERROR
00:33:43.016 -> +UUSORD: 0,0
00:33:43.016 -> +UUSORD: 0,0
00:33:43.016 -> +UUSOCL: 0
00:33:43.125 -> AT+USOCL=0
00:33:43.125 -> ERROR
00:33:43.125 -> connection failed

For webhook.site, which works fine, I get

00:34:17.097 -> AT+USOSEC=0,1,0
00:34:17.097 -> OK
00:34:17.282 -> AT+USECPRF=0,0,1
00:34:17.282 -> OK
00:34:17.504 -> AT+USOCO=0,"webhook.site",443
00:34:18.797 -> OK
00:34:18.797 -> connected

I tried to change NBClient.cpp line 128 from MODEM.send("AT+USECPRF=0,0,1"); to MODEM.send("AT+USECPRF=0,0,0"); like Issue 90 suggested, but this did not work.

I don't have any clue what the issue can be about. webhook.site uses Let's encrypt and Nginx, but the web site of Let's encrypt and Nginx (which I guess use their own newest technology) does not work. It might be that webhook.site uses an older Nginx version, but this is hard to verify. aftenposten.no uses Let's Encrypt and Varnish and has a u89-varnish-abo-01 header. But vg.no, another major Norwegian news site, owned by the same parent company, also uses Varnish (it has a u89-varnish-01 header), but this site does not work. I also tired to see if their was any commonality between the certificate issuer or the signature algorithm for the sites that worked, but I always find an other sites with the same factor that did not work.

missing error handler after writing data in the socket crashes the baseband and the mkr heavy

With certain conditions that I do not understand the writing of data into a socket ends with a crash.
After that crash the modem can't recover sometimes and needs a hardware pin reset or does not answer for hours.

Info:
15:27:11.253 -> ATI
15:27:11.253 -> Manufacturer: u-blox
15:27:11.253 -> Model: SARA-R410M-02B
15:27:11.253 -> Revision: L0.0.00.00.05.12 [Oct 08 2020 15:00:01]
15:27:11.253 -> SVN: 07
15:27:11.253 -> IMEI: xxxx
15:27:11.253 -> OK

This was the operation went wrong:

15:08:06.724 -> AT+USOWR=0,256,"30D10200042F62736728276D6B7231353030272C2027302E3030303030303030272C2027302E3030303030303030272C20272D272C202731322E3138272C202731322E3135272C202732322E3735272C202732322E3639272C202732322E3536272C2027302E3030272C2027302E3030272C2027302E3030272C202732322E3036272C202732322E3530272C202732322E3530272C202732332E3235272C202732322E3434272C202732322E3632272C2027302E3030272C2027302E3030272C2027302E3030272C2027302E3030272C2027302E3030272C2027302E3030272C2027302E3030272C2027302E3030272C2027302E3030272C2027302E3030272C"

15:08:19.743 -> +CME ERROR: Operation not allowed

Here's the modem log:

OK
15:37:46.909 -> AT+USOER

15:37:46.909 -> +USOER: 65
15:37:46.909 ->
15:37:46.909 -> OK

ublox AT command page 403 :

65 EEOF - End of file

Remarks:

  • The same operation went well dozens of times before

Questions:

Wtf EEOF?
Why it comes to a heavy crash ?
Here's the code segement from NBClient.cpp

MODEM.send(command);
if (_writeSync) {
String response;
int status = MODEM.waitForResponse(10000, &response);
if ( status != 1) {
if (status == 4 && response.indexOf("Operation not allowed") != -1 ) {
stop();
break;
} else {
break;
}
}
}

Any hints, ideas?

Thx

Apparent complete crash after network side TCP close

We have some networking problems with out test 5G network, basically
causing the network to close TCP connections more or less randomly.
This causes the MKR NB 1500 to completely crash, including the USB
host connection, until reset. As we don't have any SWD debugging
capability (as of yet), it is very hard to pinpoint the real cause.

Setup

Libraries: PubSubClient, MKRNB
Sketch: https://github.com/iothon/docker-compose-mqtt-influxdb-grafana/tree/master/03-arduino_mqtt/mkr_nb_1500_mqtt

To repeat

  1. Have a NB-IoT SIM card, modify and flash the sketch (from above),
    wait until the sketch connects to your MQTT server.

  2. Cause a network side TCP connection termination, e.g. pull the
    Ethernet from your server, kill your Mosquitto, or something
    similar. Sometimes a regular TCP close also seems to cause the
    same problem.

Symptoms

In NBClient.cpp, if the AT+USORD=0,512 call, used to receive
incoming packets, returns +CEM ERROR: ..., this causes the NBClient
to close the socket, due to PubSubClient calling _client->stop().

Some time after the NBClient::stop() method has returned, the
sketch crashes so badly that the virtual TTY is no longer visible
through USB. The board seems to stay in that stage until it is
reset with the reset button, or if it is disconnected, it runs out
of battery.

AT+USOCO and AT+USOCL returning ERROR constantly when trying to connect to Firebase server

It has been a couple of weeks since we found our issue, but essentially it was a one liner fix...

Background: The Arduino MKR NB 1500 was running with no issue for quite some time during testing. After about a week or two, we were unable to connect to the Firebase server anymore. We found that the sockets were not being created, opened, or closed. Then, every new MKR we tested had the same issue. After not finding solutions online, we read through the SARA-R4 datasheet and enabled Modem debug AT commands.

Fix: Long story short, in the NBClient.cpp, (line 128ish) we change MODEM.send("AT+USECPRF=0,0,1"); to MODEM.send("AT+USECPRF=0,0,0"); and the sockets are now functioning correctly. We have GET/POST thousands of requests with <1% failure to connect rate.

During our troubleshooting and Googling, we realize many others have had this issue or at least, the same symptoms so we felt the need to post here for others. Hope this helps!

"`error: 'SerialSARA' was not declared in this scope`"

When I try to use the library, in the "NBWebClient" example, I get the same error from the Modem.cpp file.

..\libraries\MKRNB\src\Modem.cpp:383:18: error: 'SerialSARA' was not declared in this scope
 ModemClass MODEM(SerialSARA, 115200, SARA_RESETN, SARA_PWR_ON, SARA_VINT);
                  ^~~~~~~~~~
..\libraries\MKRNB\src\Modem.cpp:383:18: note: suggested alternative: 'SerialUSB'
 ModemClass MODEM(SerialSARA, 115200, SARA_RESETN, SARA_PWR_ON, SARA_VINT);
                  ^~~~~~~~~~
                  SerialUSB
..\libraries\MKRNB\src\Modem.cpp:383:38: error: 'SARA_RESETN' was not declared in this scope
 ModemClass MODEM(SerialSARA, 115200, SARA_RESETN, SARA_PWR_ON, SARA_VINT);
                                      ^~~~~~~~~~~
..\MKRNB\src\Modem.cpp:383:38: note: suggested alternative: 'GSM_RESETN'
 ModemClass MODEM(SerialSARA, 115200, SARA_RESETN, SARA_PWR_ON, SARA_VINT);
                                      ^~~~~~~~~~~
                                      GSM_RESETN
..\libraries\MKRNB\src\Modem.cpp:383:51: error: 'SARA_PWR_ON' was not declared in this scope
 ModemClass MODEM(SerialSARA, 115200, SARA_RESETN, SARA_PWR_ON, SARA_VINT);
                                                   ^~~~~~~~~~~
..\libraries\MKRNB\src\Modem.cpp:383:51: note: suggested alternative: 'SARA_VINT_ON'
 ModemClass MODEM(SerialSARA, 115200, SARA_RESETN, SARA_PWR_ON, SARA_VINT);
                                                   ^~~~~~~~~~~
                                                   SARA_VINT_ON

exit status 1

Compilation error: exit status 1

This is using the NBWebClient.ino example file, no changes made, and MKRNB version 1.5.1.

Library use of POWER_ON and RESET_N

After some erratic behavior of the NB and finally a bricked device I looked in the system integration manual and found differences between the use of the POWER_ON and RESET_N pins in the manual and in the library.

(The circuitry on the board makes high output on the microcontroller result in a low level on the modem pins, I'll just describe what happens on the modem below.)

The library pulls down POWER_ON permanently, and uses RESET_N to reset the modem.

The modem expects a low pulse (length 150-3200 ms) on the POWER_ON pin for startup, and another pulse (length at least 1500 ms) for powerdown. It also advises against using the RESET_N pin at all.

I suspect I have bricked one device by using the library restart function too liberally, and that the erratic behavior was caused by an earlier unexpected forced restart using RESET_N at the wrong moment.

I have tried a rewritten variant of the library on a new device, following the SARA-R4 datasheet and systems integration manuals, and it seems to work. I would prefer to remove the use of RESET_N even from the arduino core used, in variant.cpp, I have used that in my tests too.

The systems integration manual recommends monitoring the V_INT pin to detect if the modem is on or not. Unfortunately, this is not connected to the microcontroller on the NB. I am considering options for that.

I can submit a pull request on the rewritten library. Should I?

How to write more that 512 bytes to a socket

From what I seeing this library writes data to a socket using HEX. Doing this limits the modem to write 512 bytes. I'm trying to write a JSON message that is 570 bytes to AWS. Is there any way to change this limitation?

nbAccess.begin fails on second loop of TestGPRS example sketch

arduino model: MKR NB 1500
modem model: SARA-R410M rev. 02B-00
modem firmware: 05.08
MKRNB library version: 1.5.1

with the example sketch TestGPRS, the modem will not complete more than one loop unless line 58 is changed from these values:

if (nbAccess.begin("") != NB_READY) {
....

to these values:

if (nbAccess.begin("", false, true) != NB_READY) {
....

this occurs in all versions since MKRNB v1.4.0, and appears to be related to fix #55

Mike

nbAccess.status() doesn't change after removal of antenna

Hi all,

For a project I need to get the MKNBR connected to a Azure cloud server and yes, I did it! But then I started making it bulletproof. To simulate a loss of communication I just disconnect the antenna and check the signal strength via the nbScanner class. That seems to work and the unit stays operational and on the debug serial issues the problem with signal loss. But then just now and then the signal is up again for no apparent reason, the antenna is still disconnected. All the time the antenna is disconnect I keep on calling the ready() function and status() keeps returning value 3 -> READY. How is that possible? The signal is totally lost. What am I missing?
Then the MQTT client wants to send data and the unit freezes and a WDT occurs.
So, how do I tell the MQTT the connection has dropped and how to get the nbAccess to 'reset' when signal strength is lost.

Endless loop in detachGPRS()

When using detachGPRS() the program gets caught in an endless loop. While looking a bit into it, I found that the ready() function would not break the loop after case GPRS_STATE_WAIT_DEATTACH_RESPONSE was reached.
In analogy to case GPRS_STATE_WAIT_CHECK_ATTACHED_RESPONSE and case READY_STATE_WAIT_CHECK_REGISTRATION_RESPONSE (in NB.cpp) ready should be set to 1 to leave the function. This is missing for the case of detachGPRS(). After adding this line, the GPRS functions did work properly.
I will add pull request #69 for this issue.

Failed MQTT Connection Error Code 3

Hi,
i tried to send data with MKR NB to a MQTT Broker with following components:

  • MKR NB 1500
  • 1NCE card with active data plan
    and used MKRNB and ArduinoMqttClient Librarys.

When I try to connect the MKR NB to the MQTT broker, I get ERROR-CODE 3 = Server unavailable. With the MKR 1010 Wifi the connection to the broker always works. Even with the program MQTT.fx and the same access data, the connection to the broker works without problems and data can be sent. The connection with the MKR NB has already worked and now it gives the error without changes in the code again. When I run the NBWebClient example sketch, I get the http request without any problems.

Any help or hints or additional questions?
Thanks

+CME ERROR: Operation not allowed - randomly

Hi,

Using my Arduino MKR 1500 sending UDP messages results in randomly giving an error: "+CME ERROR: Operation not allowed". I use the example program (see below). Sometimes I get this message after 24hrs successfully sending messages, sometimes after sending a few messages.

  • What causes this error message?
  • Since I keep receiving this error message once I received it the first time (I have to reset my Arduino), should I create a function to reconnect e.g. this in a function:
void connect() { 
  while (!connected) {
      if ((nbAccess.begin("","xxx.yyy") == NB_READY) && (gprs.attachGPRS() == GPRS_READY)) {
        connected = true;
        String carrier = nbScanner.getCurrentCarrier();
        Serial.print("Connected to ");
        Serial.print(carrier);
        Serial.println(" network");
      }
      else {
        Serial.println("Not connected");
        delay(1000);
      } 
    }
    Serial.println("\nStarting connection to server...");
    udp.begin(localPort);
  }
}

Example sketch:

#include <MKRNB.h>

unsigned int localPort = 3000;          // local port to listen for UDP packets

IPAddress awsServer(x, xxx, xxx, xx); 

const int UDP_MESSAGE_SIZE = 10;

byte packetBuffer[UDP_MESSAGE_SIZE];    //buffer to hold the outgoing messages

// Initialize the library instance
NBClient client;
GPRS gprs;
NB nbAccess(1);
NBScanner nbScanner;

// An UDP instance to let us send and receive packets over UDP
NBUDP udp;

void setup() {
  // Open serial communications and wait for port to open
  Serial.begin(9600);
  while (!Serial) {
    ; // wait for serial port to connect. Needed for native USB port only
  }

  // Connection state
  boolean connected = false;

  // After starting the modem with NB.begin()
  // attach the shield to the GPRS network with the APN, login and password
  while (!connected) {
    if ((nbAccess.begin("","xxx.yyy") == NB_READY) && (gprs.attachGPRS() == GPRS_READY)) {
      connected = true;
      String carrier = nbScanner.getCurrentCarrier();
      Serial.print("Connected to ");
      Serial.print(carrier);
      Serial.println(" network");
    }
    else {
      Serial.println("Not connected");
      delay(1000);
    } 
  }
  Serial.println("\nStarting connection to server...");
  udp.begin(localPort);

  //sendUDPMessage(awsServer);
  //delay(60000);
}

void loop() {
  sendUDPMessage(awsServer);
  delay(900000);
}

// send an UDP message to the Amazon AWS UDP server at the given address
unsigned long sendUDPMessage(IPAddress& address)
{
  // set all bytes in the buffer to 0
  memset(packetBuffer, 0, UDP_MESSAGE_SIZE);
  //packetBuffer[0]  = 0x62;
  packetBuffer[0]  = 98;
  packetBuffer[1]  = 98;
  packetBuffer[2]  = 97;
  packetBuffer[3]  = 106;
  packetBuffer[4]  = 107;
  packetBuffer[5]  = 108;
         
  udp.beginPacket(address, 1200); //UDP messages are to port 1200
  udp.write(packetBuffer, UDP_MESSAGE_SIZE);
  udp.endPacket();
}

Extra MODEM.poll() in NB.cpp

Hi, in NB.cpp on line 153 I find int ready = MODEM.ready();, this calls MODEM.poll() internally to update the internal state, then reads and returns the state. What is the reason for the extra MODEM.poll();on line 159?

I have commented it out in my copy of the library. The code runs fine without it, and it is not present in the parallel library for MKR 1400 GSM.

MKR NB1500 doesn't work with AWS MQTT

Hi,

I'm using ArduinoBearSSL. I am able to get MKR1000 to work with AWS MQTT server, and MKR NB 1500 to work with Google MQTT server. However, I am unable to get MR NB 1500 to work with AWS MQTT server using the "AWS IoT NB" example. It is stuck at AT+USOCO=0,"XXX.iot.us-east-2.amazonaws.com",8883 and timeout after 5 minutes:

Attempting to connect to MQTT broker: XXX.iot.us-east-2.amazonaws.com
AT+USOCR=6
+USOCR: 0

OK
AT+USOCO=0,"XXX.iot.us-east-2.amazonaws.com",8883
ERROR

+UUSOCL: 0
AT+USOCL=0
ERROR
0000-00-00T00:00:00Z MQTT connect error: -2

Any ideas? Thanks

The NB socket buffer is too short for NB1500 http, causing overwrite and crash

I use an NB1500 and sends a http request to fetch a web page. The response is larger than 512 byte. This causes a SW crash. The bug has been identified in NBSocketBuffer.cpp;

  • In NBSocketBuffer.cpp a 512 byte read buffer is allocated: <malloc(NB_SOCKET_BUFFER_SIZE)>.
  • The a read of 512 byte is requested: <MODEM.sendf("AT+USORD=%d,%d", socket, NB_SOCKET_BUFFER_SIZE);>.
  • The library has previously set HEX mode with <AT+UDCONF=1,1>.
  • The modem returns two characters per byte - up to 1024 bytes. The library does not check the length causing overrun and SW crash,

Changing the USORD command line to <MODEM.sendf("AT+USORD=%d,%d", socket, NB_SOCKET_BUFFER_SIZE/2);> is one way to correct the error.

Missing handler for socket error/dead caused by weak signal strength

What:
A created socket can 'die' out of a sudden when the server does simply not answer anymore without closing the socket.
Then a +USOWR command can stop in the middle of the write process and the modem answer with +CME Error 3 (Operation not allowed). A error readout with +USOER says "65 EEOF - End of file."

The client wants to write data into a dead socket, the bytestream is blocked because the server does simple not read anymore.

Result: The board freezes because the NbClient can't handle that error.

Remedy: these processes take place on the baseband and cannot be influenced or predicted. however, the nbclient must be able to handle the error message of the modem cleanly.

NB::getLocalTime() and NB::getTime() Incorrectly Assumes Local Time From CCLK Command

We're testing with the MKRNB 1500 and the Telstra network in Australia (in AEDT/AEST timezone; currently +11) and the CCLK command in the get time functions of the MKRNB libraries actually return GMT time rather than an assumed local time by the looks of things.

In the NB::getTime() function, it converts the CCLK value with an offset of -11, which when the CCLK command returns GMT in our case, it is actually offset by -22 hours from current local time (GMT time minus -11).

For example we got this response at 2111 on the 23/10 (+44 in this case is +11hrs which gets subtracted from the time in the code to produce "GMT", when in actual fact it's already GMT and now the value is GMT minus 11):

+CCLK: "19/10/23,10:11:41+44"

In the NB::getLocalTime() function, it doesn't change the value based on the TZ value, so in our case it returns GMT.

Looking at the SARA R4 AT commands, it doesn't specify what time format the CCLK value actually returns in, so we can never actually assume it's the current local time (with GMT offset applied). Also it states that TZ is network dependent and might not actually return a TZ.

With all this in mind, it seems like there's 4 different network time formats depending on the provider, neither of which can be determined with the information from the radio alone:

  1. CCLK returns GMT +/- TZ
  2. CCLK returns GMT without TZ
  3. CCLK returns local time +/- TZ
  4. CCLK returns local time without TZ

So the NB::getLocalTime() shouldn't really be used as it "might" not actually apply the correct offset. getTime should be used instead, but to solve the above ambiguity, you need to provide your own smarts based on which network provider you are using and which values are returning (i.e. a lookup table based on provider and location to determine what your time should actually be).

Unless there's an AT command I'm missing that might solve this problem? Or does the code incorrectly assume that the value returned is local time and should it always parse it as GMT?

Arduino mkrNB 1500 send sms not working

My new mkr nb 1500 cannot send sms is not working. But if the number to send the sms to has previously sent a message to the mkr 1500 than it works. It seems that the mkr 1500 remembers the path or so to send an sms if it previously has received one from the sender.

I use the example send sms provided by the Arduino editor version 1.8.12. Examples / examples from libraries / mkrNB / tools / send sms.

Receiving SMS works fine using the Examples / examples from libraries / mkrNB / tools / receiving sms: works fine of Arduino IDE 1.8.12. If I change the code of this sketch and write the same commandos to send an sms as in the "Examples / examples from libraries / mkrNB / tools / send sms". sketch, then the sms can be sent:
sms.beginSMS(senderNumber);
sms.print(txtMsg);
sms.endSMS();

MKR NB 1500 Not working with AWS

This similar to another post here but a little different. I have no problem connecting to AZURE but never completes connecting with AWS MQTT. I've followed the suggestions that I've found but with no success. I created the csr on the 1500 and copied to AWS. Maybe this is a firmware issue as was mentioned. Any help will be appreciated. Very likely something that I'm missing as I'm not as young as I used to be. Attached is a file showing what is happening. The sequence shown repeats over and over. Appears that it's close to connecting. I haven't found any logs on AWS that might help, I'm still looking, ignorance isn't always bliss.

awsconnect2.txt

MKR NB1500 - example SMS receive sketch still does not work

On the MKR NB1500, the MKRNB library has a fault in it such that the example sketch for SMS Receive does not work. If there are pending messages when it boots, those messages will be shown. But subsequent messages sent will not be shown until the board is restarted.
This behavior has been confirmed with both T-mobile and Verizon networks.

Update firmware on mkr1500 UBLOX SARA-R410M-02B

Hi,

I recently bought a Arduino mkr1500 but it came with obsolete firmware on the UBLOX SARA-R410M-02B.

firmware version: L0.0.00.00.05.06 [Feb 03 2018 13:00:41]

I'd like to update the firmware to the latest and was wondering how to do this? Is there some more info on how to achieve this?

Thx

Missing timeout argument in NBUDP::endPacket(), default value of 200ms sometimes too low

I ran into timing issues while using NBUDP, specifically using endPacket(). Sometimes it returned true (successful) sometimes false (not successful).

After some debugging I realized, that the call MODEM.waitForResponse() does not use any argument, so it takes the default value of 200ms from ModemClass.

This is too low in my case. While sometimes it takes the modem only around 20-40ms to respond to AT+USOST, sometimes it reaches 210-240ms, resulting in a timeout, even though the packet has been sent.

The setTimeout method does not help in this case, as the value is not used as an argument when calling waitForResponse().

As a simple solution I hard-coded a value >200 into the call in endPacket(). Obvisouly it would be better if it had already a realistic value such as in all other calls of waitForResponse() in that file (begin(), stop(), parsePacket()).

Edit: The ublox manual for the SARA-R4 says on page 446 that +USOST should take less than 11s. That sounds like a lot. For now I use 1000ms and it works fine.

Cheers and thanks a lot for this wonderful library.

MKR1500 AT Serial Commands only work from time to time...frustration

Hi,
i've an MKR1500, i installed the passthrough sketch which from time to time works so that AT results in an OK. A lot is written in the internet about unstable behavior but i could not find any solution and its highly frustrating as from 50 tries maybe it works once that AT commands result in reaction. Looks like the modem is not reached at all.

As a lot of other people have the same issues i'm surprised that this is not any open issue here....i hoped that there needs to be done a slightly change (delay,...) in the sketch to make it work stable.....

I did already add a LiPo Battery,...nothing improved the bad experience i have right now. Thanks a lot Norbert

UDP.available() calculates the buffer incorrectly.

I was making some tests with the Arduino MKR 1500 and a Python UDP server running on my machine (network via 1NCE VPN).

Sending data to the server did work, but when the server responded (returning message in all caps), the number of bytes available was around 4.294.967.290 (0xFFFF FFFA). So I figured that the subtraction used in NBUdp.cpp line 262 is reversed. After changing it I always got the correct number of bytes.
The solution is an educated guess, perhaps someone with more in-depth knowledge wants to have a look into that. However, I will post a Pull Request.

Missing AmazonRootCA1 ?

Hi
I see that this commit
7891975
removed the AmazonRootCA1 from the NBRootCerts.h file.
Will that break connections to AWS IoT if the MKR NB 1500 trys to connect to AWS IoT core over SSL ?
I'm trying to debug one at the moment (logs not available, will have them in the next few days) and it's not connection to AWS IoT core, the MQTT connection is not coming up.
Why was the Amazon root cert removed ?

NBSocketBuffer.h tries to read data out of the socket when there is none

If there is data in the socket to read, the modem sends
+UUSORD: 0,310
Then the lib reads out the socket with
AT+USORD=0,512 (The size is not correct? Shouldn't it be AT+USORD=0,310 ??)
The modem sends the data
+USORD: 0,310,"{PAYLOAD DATA}"

So far, so good.

The issue is that the lib is sending a lot of
AT+USORD=0,512
without a signal from the modem saying there is data in a socket to get.

So there are a lot of:
08:45:36.624 -> AT+USORD=0,512
08:45:36.624 -> +USORD: 0,""
08:45:36.624 ->
08:45:36.624 -> OK

This is triggered by the call to update the socket in NBClient.cpp, 351:

  if (NBSocketBuffer.available(_socket) < 0 || (_ssl && !_connected)) {
    stop();
    return 0;
  }

The problem is that the modem is occupied for no reason and this command can colide with another AT command which can lead to a flaky behaviour.

IMHO there is no reason to ask the modem active with AT+USORD=0,512, just read out the data when the modem sends
a +UUSORD is enough. So this call is unnecessary!?! I commented it out and enlarged the send buffer as requested in
#75 and have much more stabilty and less AT command traffic.
Maybe im totally wrong.
THX

Reading a 4 byte packet from UDP server returns extra unknown characters. �&

While trying to read a from a UDP socket, I received some unknown characters when the packet is exactly 4 byte long.

int packetSize = server.parsePacket();
if (packetSize) {
        char packet[packetSize];
        server.read(packet, packetSize);
       Serial.println(packet);
       
       // prints  open�&
}

However, the AT commands cleary return only "open"

+USORF: 0,"10.254.2.84",26105,4,"6F70656E"

6F70656E = open

SMS are received only after boot or after sending SMS

I use my NB 1500 to monitor a sensor, and send SMS if a warning threshold is reached. The code also monitors incoming SMS for sensor level queries, and responds when this happens. Used to work well. Recently, the code has stopped receiving SMS, unless a) the NB1500 is rebooted, or b) a warning SMS is sent, and only then it receives pending SMSes.

The code issues AT+CMGL="REC UNREAD" once per second and receives "OK" (I can see this with debug mode on). When an SMS is sent, the next query returns pending received SMSes.

Is anyone else seeing this? Is there some configuration I've changed without meaning to? Has this been caused by a hard reboot at the wrong moment? How do I return to the old behavior?

ReceiveSMS sketch hangs after SMS received

In the Arduino example sketch ReceiveSMS.ino, when a message is received by the device, the response gets cut off and the sketch hangs. This was discussed partially in #50, but is a separate issue from what has been discussed there. #80 hypothesized that it was an issue with the '/' character, but the issue was closed without clear resolution (using another library may have solved this). With Serial debugging active, I see that the response returned over the serial monitor is cut off abruptly, like this:

14:32:05.683 -> AT+CMGL="REC UNREAD"
14:32:05.683 -> +CMGL: 6,"REC UNREAD","+1##########",,"21

After this, the code gets stuck in a while() loop, waiting for MODEM.ready() to return something other than 0. This is where the problem becomes more clear. Incoming uart data is stored in the RX ring buffer, which has a size of 64 ints. The first 64 characters of the response are being stored in this buffer, and the rest seems to be dropped. I verified this by adding a Serial.print statement with the size of the RX buffer after each character is read. This means that the response code at the end is not stored or read in the modem's poll() function, causing the return value for "ready" to always remain 0.

I have verified that this is NOT an issue with processing the '/' character; if you change the AT command in the library from "AT+CMGL="REC UNREAD"" to just "AT+CGML" (identical commands, see AT commands reference), the serial monitor will print more of the date/time, like this:

15:45:05.700 -> AT+CMGL
15:45:05.746 -> +CMGL: 11,"REC UNREAD","+1##########",,"21/09/08,12:45

I see that buffering is handled differently for the NBClient functions (the NBSocketBuffer files), where the buffer is extended to 512 ints. Does a similar solution need to be applied here to handle SMS message reading? Is there something that I am missing in my understanding?

Steps to replicate:

  1. Upload ReceiveSMS.ino to an NB1500 with an activated SIM card that has SMS service. Set debugging to true in the NB constructor- nbAccess(true)
  2. Wait for the device to initialize and be in the "Waiting for messages" state
  3. Send an SMS message to the device

Link to gist of Serial Monitor output following the 3 steps above (with phone number redacted)
https://gist.github.com/joshbober/9a9a01e35c540c0f4d4771276bfee0be

Other relevant information:

  • My device firmware is updated to the latest release 05.12
  • Using the SerialSARAPassthrough sketch and u-blox tool m-center, the AT+CGML command returns the full expected response

MKRNB receiving SMS halts after a short time

Hi there

After the ugly hardware problems with the MKR1400 (Switching to 2G freezes the code) i swaped to the MKR1500 facing the next frustrating problem..

The board is receiving sms right after startup but then AT+CMGL="REC UNREAD" on and on.
After a reset the SMS come in, one after the other, like they had waited somewhere in a memory...

After a restart, the SMS is beeing processed without a issue...

I'm testing with the "official" example from the MKRNB, the ReceiveSMS sketch by Javier Zorzano.
I already updated the Modem Firmware
ATI9
L0.0.00.00.05.08,A.02.04

Update:
The SMS are stored in the memory of the Modem
AT+CMGF=1
AT+CMGR=1
+CMGR: "REC READ",".....

So there must be en error in the library,
AT+CMGL="ALL"
+CMGL: 0,"REC UNREAD","Number",,...
but
AT+CMGL="REC UNREAD"
-> OK

Also within the loop()
AT+CMGL="REC UNREAD"
OK
(No message)

but via passtrough the modem answers correct:

AT+CMGL="REC UNREAD"
+CMGL: 0,"REC UNREAD","+41.......
(The SMS is there)
(Meanwhile no SMS in)

Timing problems?
With the AT commands all seems to work fine,the Messages are in the Modem's memory, unread but marked as read.
Everything seem to work fine for the first 10 to 30 seconds running the sketch and the it gets flaky...

Any help or hints or additional questions?
Thx

NB_SMS struggles over the "/" sign in the date of the received sms

After a sms is received, the lib ask with
AT+CMGL="REC UNREAD"
+CMGL: 0,"REC UNREAD","+TelNr",,"21
and breaks here, the modem is freezed.

The complete output (from m-center software) is
+CMGL: 0,"REC UNREAD","+TelNr",,"21/07/21, 07:09:48+08"

So the lib strugles over the "/" sign

I think i made a wrong setting with the modem but i don't know what. Any ideas?
If so then it can be helpful to include the correct modem setup in the NB_SMS class.
THX
Update: Compiled with a MACOS

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.