I have started experimenting with low power wide area networks (LP-WAN) in New Zealand using a u-blox SARA-R410-02B. Here is is what I have experimented with so far.
I am currently experimenting with integrating a low power wide area networks (LP-WAN) modem with a microcontroller. In New Zealand, we have two operators offering LP-WAN services. Vodafone offers both LTE-M/Cat-M1 and narrowband Internet of thing (NB-IoT) networks. Spark offers only a LTE-M/Cat-M1 network (they also have a LoraWAN network, but coverage is very limited).
To do the experimentation, we purchased a Mikroe LTE IoT Click, which uses the u-blox SARA-R410-02B-01 NB-IoT/LTE-M module. The module uses an AT command set for control over a USB or a (voltage-level selectable) UART serial port.
Accessing LP-WAN Networks
To access the LP-WAN networks, you have to get a SIM card that has been set up for them.
Vodafone on the otherhand makes it amazingly impossible. No one on their non-business teams and few on their business teams even know what NB-IoT is and the fact that Vodafone offers it. They have an email address, which you are supposed to email and someone will contact you... four weeks on I have had nothing from them.
Setting Up The SARA-R4 (and Linux) To Connect
Once I received the Mikroe module, put the Spark IoT SIM card in and plugged it into my computers USB port with a big smile on my face. I soon found out it wasn't quite as easy as I was hoping.
First off, with the Spark SIM cards, you have to activate them before they can connect to the network.
If you are using Linux to control the module, Linux has a ModemManager service which should be disabled to stop it from trying to take control of the device.
# systemctl stop ModemManager.service
To connect to the New Zealand networks, you have to change the mobile network operator (MNO) profile to the stnndard Europe profile (as this has the most flexibility) and then change the bandmask to the bands used by the New Zealand networks (LTE bands 28, 3 and 7 for Vodafone, and LTE bands 28, 3, 1 and 7 for Spark).
# Disable the radio AT+CFUN=0 # Select the Standard Europe MNO profile AT+UMNOPROF=100 # Restart the modem for the MNO profile change to take effect AT+CFUN=15 # Update the NB-IoT bandmask to 1, 3, 7 and 28 AT+UBANDMASK=0,134217797 # Update the LTE-M bandmask to 1, 3, 7 and 28 AT+UBANDMASK=1,134217797
Once this is done, you should be able to see the Vodafone and Spark networks, and the module should automatically connect to them.
# Scan for available networks AT+COPS=? +COPS: (1,"530 01","530 01","53001",7),(2,"530 05","530 05","53005",7),(1,"530 05","530 05","53005",9),(1,"530 01","530 01","53001",9),,(0,1,2,3,4),(0,1,2) # Check of the modem has connected AT+COPS? +COPS: 0,0,"530 05 Spark NZ",7 # (Shows currently connected to the Spark LTE-M network)
To send requests to HTTP servers, you have to configure a HTTP server profile first (see the SARA-R4 AT Commands Manual for a full reference for the HTTP AT Commands).
# Set the server domain name of profile 0 AT+UHTTP=0,1,"example.com" # Use HTTPS (and port 443) for profile 0 (think very hard if you choose not to use this option) AT+UHTTP=0,6,1
Once the profile is set up, you can use it to send a request to the server
# Send a GET /hello request to the server in profile 0, saving the response to the file "response" AT+UHTTPC=2,1,"/hello","response" # Read the contents of the file "response" AT+URDFILE="response"
Even though, the SARA-R4 documentation documents an option to manually set the server name indication (SNI), it does not seem to be supported on the SARA-R410-02B-01 out of the box (even though it should be) as it responds with an operation not supported error. This means if you want to use HTTPS, you will have to find a server that doesn't require SNI (for example Nginx configured for virtual hosts does require SNI, so will produce a secure socket connect error HTTP error code 73 on the module).
Sending MQTT messages is similar to sending HTTP request with an additional step of connecting to the server after its configured (see the SARA-R4 AT Commands Manual for a full reference for the MQTT AT Commands).
# Configure the client ID AT+UMQTTC=0,"CLIENT123456789" # Configure the hostname and the port AT+UMQTTC=2,"example.com",1883 # Configure the keepalive (timeout time) in seconds for the connection (REQUIRED for mosquitto) AT+UMQTT=10,36000
Once configured, you can save the configuratin in non-volatile (NV) memory.
Then connect to the server
AT+UMQTTC=1 +UMQTTC: 1,1
Then publish a message
# Send "hello" on the "/user/hello" topic AT+UMQTTC=2,0,0,"/user/hello","hello"