NB-IoT
NB-IoT Functions
This category contains functions specific to NB-IoT devices.
| API Name | Brief Description |
|---|---|
| api.nbSend() | Sends a message to NB-IoT on specified IP, port, and protocol type. Multiple variants. See below. |
| api.nbReceiveBuffer() | Activates, configures, and uses NB-IoT scratchpad buffer. Multiple variants. See below. |
| api.nbAT() | Sends an AT command to NB-IoT module with specified timeout or uses defined commands. Multiple variants. See below. |
api.nbSend()
Sends a message to NB-IoT on specified IP, port, and protocol type.
| API Name | Brief Description |
|---|---|
| api.nbSend(addr, port, msg, timeout, type, nownewdatatimeout, rxport) | Sends a message string to NB-IoT. |
| api.nbSend(addr, port, bufferlen, timeout, type, nownewdatatimeout, rxport) | Sends data from the scratchpad buffer (api.nbReceiveBuffer) to NB-IoT. |
Info: Maximum length of Rx and Tx messages is 512 bytes. Maximum execution time is limited by timeout in milliseconds.
api.nbSend(addr, port, msg, timeout, type, nownewdatatimeout, rxport)
api.nbSend("185.8.239.192", 5566, "test message", 6000, "UDP")
Sends a message to an IP address via NB-IoT.
Arguments
- addr (string): IP address.
- port (integer): Port.
- msg (string): Message to be sent to NB-IoT.
- timeout (integer): Maximum execution time in milliseconds.
- type (string): Protocol type:
"UDP"- UDP protocol."TCP"- TCP protocol."DTLS"- DTLS protocol.
Optional
- nownewdatatimeout (integer, optional): Maximum delay between data chunks on reception.
- rxport (integer, optional): Port to use for reception; if not specified, port value is used.
Return
- status (integer): Zero for success, negative for failure.
- rxbuffer (string): Received data or
nilfor failure.
Example
-- Sends "test message" string to IP 185.8.239.192 on port 5566 with 6s timeout via UDP
status, answer = api.nbSend("185.8.239.192", 5566, "test message", 6000, "UDP")
--------------------------------
-- Sending IEC readout data via onWake function
function onWake()
print("Executing OnWake() procedure:")
RS485ExternalPower(1)
IECReadoutData = IECReadout(deviceId, initSpeed)
RS485ExternalPower(0)
print("Data: ")
print(IECReadoutData)
res = api.nbSend(ip, port, IECReadoutData, receiveTimeout, protocol)
api.nbSend(addr, port, bufferlen, timeout, type, nownewdatatimeout, rxport)
api.nbSend("185.8.239.192", 5566, 128, 6000, "UDP")
Sends a buffer to an IP address via NB-IoT.
Arguments
- addr (string): IP address.
- port (integer): Port.
- bufferlen (integer): Scratchpad (api.nbReceiveBuffer) buffer is sent in given length.
- timeout (integer): Maximum execution time in milliseconds.
- type (string): Protocol type:
"UDP","TCP", or"DTLS".
Optional
- nownewdatatimeout (integer, optional): Maximum delay between data chunks on reception.
- rxport (integer, optional): Port to use for reception; if not specified, port value is used.
Return
- status (integer): Zero for success, negative for failure.
- rxbufferlen (integer): Length of the received data, zero for failure.
Example
-- Send from buffer of length 128 to IP 185.8.239.192 on port 5566 with 6s timeout via UDP
status, rxbufferlen = api.nbSend("185.8.239.192", 5566, 128, 6000, "UDP")
--------------------------------
api.dumpArray(txbuf)
res = api.nbSend(ip, port, txbuf, receiveTimeout, protocol)
api.nbReceiveBuffer()
Activates, configures, and uses NB-IoT scratchpad buffer.
| API Name | Brief Description |
|---|---|
| api.nbReceiveBuffer("activate") | Activates the buffer. |
| api.nbReceiveBuffer("deactivate") | Deactivates the buffer. |
| api.nbReceiveBuffer("dump", size) | Dumps content of the buffer. |
| api.nbReceiveBuffer("set-size", size) | Sets the size of the buffer. |
| api.nbReceiveBuffer("get-size") | Gets the size of the buffer. |
| api.nbReceiveBuffer(start, len, toWrite) | Writes data into the buffer at the specified start index. |
api.nbReceiveBuffer("activate")
api.nbReceiveBuffer("activate", wantedIndex)
Activates the buffer.
Arguments
-
"activate" (string, command)
❗command - the argument needs to have this exact form❗
Example
-- Activate the buffer
api.nbReceiveBuffer("activate")
api.nbReceiveBuffer("deactivate")
api.nbReceiveBuffer("deactivate")
Deactivates the buffer.
Arguments
-
"deactivate" (string, command)
❗command - the argument needs to have this exact form❗
Example
-- Deactivate the buffer
api.nbReceiveBuffer("deactivate")
api.nbReceiveBuffer("dump", size)
api.nbReceiveBuffer("dump", 128)
Dumps content of the buffer.
Arguments
-
"dump" (string, command)
❗command - the argument needs to have this exact form❗
Optional
- size (integer, optional): Size of the buffer to dump.
Example
-- Dump the buffer content
api.nbReceiveBuffer("dump", 128)
api.nbReceiveBuffer("set-size", size)
api.nbReceiveBuffer("set-size", 128)
Sets the size of the buffer.
Arguments
-
"set-size" (string, command)
❗command - the argument needs to have this exact form❗ -
size (integer): Size of the buffer.
Example
-- Set buffer size to 128
api.nbReceiveBuffer("set-size", 128)
api.nbReceiveBuffer("get-size")
api.nbReceiveBuffer("get-size")
Sets the size of the buffer.
Arguments
-
"set-size" (string, command)
❗command - the argument needs to have this exact form❗
Example
api.nbReceiveBuffer("get-size")
api.nbReceiveBuffer(start, len, toWrite)
api.nbReceiveBuffer(0, 5, "Hello")
Writes data to the NB-IoT scratchpad buffer at the specified start index.
Arguments
- start (integer): Index/location where the first byte will be written.
- len (integer): Length of data to write into the buffer.
- toWrite (string): Data to write into the buffer.
Return
- size (integer): Size of the written data, zero for failure.
- data (string): Data written into the buffer, empty for failure.
Example
-- Write "ACRIOS" into the buffer starting at index 0
written, echoed = api.nbReceiveBuffer(0, 6, "ACRIOS")
print("Written bytes:", written)
print("Echoed data:", echoed)
api.nbAT()
Sends an AT command to NB-IoT module with specified timeout or uses defined commands.
| API Name | Brief Description |
|---|---|
| api.nbAT("AT_DEBUG_OFF") | Turns OFF printing of AT commands. |
| api.nbAT("AT_DEBUG_ON") | Turns ON printing of AT commands. |
| api.nbAT("REINITIALIZE") | Re-initializes the NB-IoT module. |
| api.nbAT("ICCID?") | Returns ICCID value of current SIM card. |
| api.nbAT("IMSI?") | Returns IMSI value of current SIM card. |
| api.nbAT("IMEI?") | Returns IMEI value of the modem. |
| api.nbAT("DOWNLINK_MAX_PERIOD", period) | Sets maximum period without downlink before re-initializing the module. |
| api.nbAT("REINIT_HARD_LIMIT_RETRY", retries) | Sets number of retries before reset after multiple initializations. |
| api.nbAT("FORCED_REINIT_DONE?") | Monitors if "DOWNLINK_MAX_PERIOD" happened. |
| api.nbAT("PSM", psmState, edrxState, edrxPeriod, edrxPTW, keepSocketOpen, forceRaiSingleUL, forceRel13, compensateTimeoutForInactTimer) | Returns or sets power saving mode network status. |
| api.nbAT("ON_TAU_EVENT", enable) | Enables/disables on TAU event. |
| api.nbAT("SLEEP_MONITOR", enable) | Enables/disables sleep monitor. |
| api.nbAT("AT_DEBUG_ON_TX") | Turns ON printing of AT commands on transmission. |
| api.nbAT("SET_CEREG_TRESHOLD", threshold) | Sets AT+CEREG switch threshold. |
| api.nbAT("TAU_BLANKING", tau) | Sets TAU blanking interval. |
| api.nbAT("NET_STATUS?") | Returns network status. |
| api.nbAT("RADIO_OFF_SLEEP") | Turns OFF radio sleep (PSM). |
| api.nbAT("UPDATE") | Switches to SIM module update mode. |
| api.nbAT("DTLS", pskid, psk) | Changes PSK and PSK ID for DTLS. |
| api.nbAT("TIME_SYNC", force, zone) | Synchronizes time with SIM module. |
| api.nbAT("TRANSPARENT") | Sets transparent mode. |
| api.nbAT("SLEEP") | Puts SIM module to sleep. |
| api.nbAT("APN=apn") | Sets APN. |
| api.nbAT("PLMNID=plmnid") | Sets PLMN ID. |
| api.nbAT("HARD_RX_TIMEOUT", timeout) | Sets hard RX timeout. |
| api.nbAT(command, timeout, wakeUp, success, err, tryMore, setAwakeBefore, pollBeforeCommand, setAwakeOffAfter, receiveFixedBytes) | Sends a custom AT command to the NB-IoT module. |
Danger: api.nbAT() is a direct access to the AT command interface of the NB-IoT module. It is advanced and should be used with caution.
Warning: For a backward-compatible interface, avoid using AT commands directly. Instead, use only api.nbSend() for sending.
api.nbAT("AT_DEBUG_OFF")
api.nbAT("AT_DEBUG_OFF")
Turns OFF printing of AT commands.
Arguments
-
"AT_DEBUG_OFF" (string, command)
❗command - the argument needs to have this exact form❗
Example
-- Turn off AT debug
api.nbAT("AT_DEBUG_OFF")
api.nbAT("AT_DEBUG_ON")
api.nbAT("AT_DEBUG_ON")
Turns ON printing of AT commands.
Arguments
-
"AT_DEBUG_ON" (string, command)
❗command - the argument needs to have this exact form❗
Example
-- Turn on AT debug
api.nbAT("AT_DEBUG_ON")
--------------------------------
if atDebug then
api.nbAT("AT_DEBUG_ON")
end
api.nbAT("REINITIALIZE")
api.nbAT("REINITIALIZE")
Re-initializes the NB-IoT module.
Arguments
-
"REINITIALIZE" (string, command)
❗command - the argument needs to have this exact form❗
Example
-- Re-initialize NB-IoT module
api.nbAT("REINITIALIZE")
--------------------------------
function ns() return api.getTick(2) end
if nextWR == 0 then
print("BEACON", lBTs, ns())
lBTs = ns()
else
print("GATHER", lGTs, ns())
lGTs = ns()
if reinitOnWakeGather == 1 then
api.nbAT("REINITIALIZE")
end
end
api.nbAT("ICCID?")
api.nbAT("ICCID?")
Returns ICCID value of current SIM card.
Arguments
-
"ICCID?" (string, command)
❗command - the argument needs to have this exact form❗
Return
- iccid (string):
"89 88 280 666xxxxxxxx x"(x would be numbers) - ICCID value of current SIM card.""- empty string for failure.
- status (integer):
0- successful identification.-1- failure to identify.
Example
-- Get ICCID
iccid, status = api.nbAT("ICCID?")
api.nbAT("IMSI?")
api.nbAT("IMSI?")
Returns IMSI value of current SIM card.
Arguments
-
"IMSI?" (string, command)
❗command - the argument needs to have this exact form❗
Return
- imsi (string):
"901 40 51000xxxxx"(x would be numbers) - IMSI value of current SIM card.""- empty string for failure.
- status (integer):
0- successful identification.-1- failure to identify.
Example
-- Get IMSI number of SIM card with timeout of 5 seconds
function getIMSI() return imsi or (string.gmatch(api.nbAT("IMSI?", 5000), "([0-9]+)")() or "000000000000000") end
api.nbAT("IMEI?")
api.nbAT("IMEI?")
Returns IMEI value of the modem.
Arguments
-
"IMEI?" (string, command)
❗command - the argument needs to have this exact form❗
Return
- imei (string):
"984226666906764"- IMEI value of the modem.""- empty string for failure.
- status (integer):
0- successful identification.-1- failure to identify.
Example
-- Get IMEI number of the modem
x = api.nbAT("AT+CGSN")
start = string.find(x, "\n")
finish = string.find(x, "\r", start + 1)
imei = string.sub(x, (start + 1), (finish - 1))
print("IMEI: " .. imei)
api.nbAT("DOWNLINK_MAX_PERIOD", period)
api.nbAT("DOWNLINK_MAX_PERIOD", 259200000)
If there is no downlink for the given value, sets timeout to 30 seconds and re-initializes the module.
Arguments
-
"DOWNLINK_MAX_PERIOD" (string, command)
❗command - the argument needs to have this exact form❗ -
period (integer): Maximum period of time in milliseconds (1s is 1000ms) without downlink.
Example
-- Set downlink max period to 3 days
api.nbAT("DOWNLINK_MAX_PERIOD", 3 * 24 * 3600 * 1000)
api.nbAT("REINIT_HARD_LIMIT_RETRY", retries)
api.nbAT("REINIT_HARD_LIMIT_RETRY", 5)
If NB-IoT module is initialized the specified number of times in a row, sleeps 4 hours and then resets.
Arguments
-
"REINIT_HARD_LIMIT_RETRY" (string, command)
❗command - the argument needs to have this exact form❗ -
retries (integer): Number of retries before reset.
Example
-- Set hard limit retry to 5
api.nbAT("REINIT_HARD_LIMIT_RETRY", 5)
api.nbAT("FORCED_REINIT_DONE?")
api.nbAT("FORCED_REINIT_DONE?")
Monitors if "DOWNLINK_MAX_PERIOD" happened.
Arguments
-
"FORCED_REINIT_DONE?" (string, command)
❗command - the argument needs to have this exact form❗
Return
- reinits (integer): Number of re-initializations since reset.
Example
-- Check if forced reinit done
reinits = api.nbAT("FORCED_REINIT_DONE?")
api.nbAT("PSM", psmState, edrxState, edrxPeriod, edrxPTW, keepSocketOpen, forceRaiSingleUL, forceRel13, compensateTimeoutForInactTimer)
api.nbAT("PSM", 1, 1, 1024, 64, 1, 0, 0, 0)
Returns or sets power saving mode network status.
Arguments
-
"PSM" (string, command)
❗command - the argument needs to have this exact form❗
Optional
- psmState (integer): PSM state. Use
-1to skip. - edrxState (integer): eDRX state. Use
-1to skip. - edrxPeriod (integer): eDRX Requested Value (Period). Use
-1to skip. - edrxPTW (integer): eDRX Requested Value (PTW). Use
-1to skip. - keepSocketOpen (integer): Keep Socket Open. Use
-1to skip. - forceRaiSingleUL (integer): Force RAI Single UL. Use
-1to skip. - forceRel13 (integer): Force Rel 13. Use
-1to skip. - compensateTimeoutForInactTimer (integer): Compensate Timeout For Inact Timer. Use
-1to skip.
Return
- psmState (integer): PSM state.
- edrxState (integer): eDRX state.
- edrxPeriod (integer): eDRX Requested Value (Period).
- edrxPTW (integer): eDRX Requested Value (PTW).
- keepSocketOpen (integer): Keep Socket Open.
- forceRaiSingleUL (integer): Force RAI Single UL.
- forceRel13 (integer): Force Rel 13.
- compensateTimeoutForInactTimer (integer): Compensate Timeout For Inact Timer.
Example
-- Set PSM parameters
api.nbAT("PSM", 1, 1, 1024, 64, 1, 0, 0, 0)
api.nbAT("ON_TAU_EVENT", enable)
api.nbAT("ON_TAU_EVENT", 1)
Enables/disables on TAU event.
Arguments
-
"ON_TAU_EVENT" (string, command)
❗command - the argument needs to have this exact form❗ -
enable (integer):
1for enable.0for disable.
Return
- status (integer):
1for enabled.0for disabled.
Example
-- Enable on TAU event
api.nbAT("ON_TAU_EVENT", 1)
api.nbAT("SLEEP_MONITOR", enable)
api.nbAT("SLEEP_MONITOR", 1)
Enables/disables sleep monitor.
Arguments
-
"SLEEP_MONITOR" (string, command)
❗command - the argument needs to have this exact form❗ -
enable (integer):
1for enable.0for disable.
Return
- status (integer):
1for enabled.0for disabled.
- timestamp (integer): Last module suspended timestamp.
- failureCount (integer): Module sleep failure count.
Example
-- Enable sleep monitor
api.nbAT("SLEEP_MONITOR", 1)
--------------------------------
function onStartup()
_, FLen = api.wmbusFilter("fetch")
loadConf()
print("WMBus-NBIoT, V"..ver)
hasCC = ex("_hw_features", "CC:1") or false
api.nbAT("APN=acrios.iot")
api.nbAT("PLMNID=23003")
awT = 0
api.nbAT("ON_TAU_EVENT",1)
api.nbAT("SLEEP_MONITOR",1)
api.nbAT("AT_DEBUG_ON_TX")
api.nbAT("AT_DEBUG_ON")
Turns ON printing of AT commands on transmission.
Arguments
-
"AT_DEBUG_ON_TX" (string, command)
❗command - the argument needs to have this exact form❗
Example
-- Turn on AT debug on TX
api.nbAT("AT_DEBUG_ON_TX")
api.nbAT("SET_CEREG_TRESHOLD", threshold)
api.nbAT("SET_CEREG_TRESHOLD", 5)
Sets AT+CEREG switch threshold.
Arguments
-
"SET_CEREG_TRESHOLD" (string, command)
❗command - the argument needs to have this exact form❗ -
threshold (integer): AT+CEREG switch threshold.
Example
-- Set CEREG threshold to 5
api.nbAT("SET_CEREG_TRESHOLD", 5)
api.nbAT("TAU_BLANKING", tau)
api.nbAT("TAU_BLANKING", 3600)
Sets TAU blanking interval.
Arguments
-
"TAU_BLANKING" (string, command)
❗command - the argument needs to have this exact form❗ -
tau (integer): TAU blanking interval.
Return
- interval (integer): TAU blanking interval.
Example
-- Set TAU blanking to 3600
api.nbAT("TAU_BLANKING", 3600)
api.nbAT("NET_STATUS?")
api.nbAT("NET_STATUS?")
Returns network status.
Arguments
-
"NET_STATUS?" (string, command)
❗command - the argument needs to have this exact form❗
Return
- lastTac (integer): Last TAC.
- lastCellId (integer): Last Cell ID.
- lastPeriodicTau (integer): Last Periodic TAU.
- lastActiveTime (integer): Last Active Time.
- lastEdrxValue (integer): Last Provided eDRX Value.
- lastEdrxPtwValue (integer): Last Provided eDRX PTW Value.
- edrxNegotiated (integer): Negotiated eDRX.
- timeoutForInactTimer (integer): Compensate Timeout For Inact Timer Value.
Example
-- Get network status
api.nbAT("NET_STATUS?")
api.nbAT("RADIO_OFF_SLEEP")
api.nbAT("RADIO_OFF_SLEEP")
Turns OFF radio sleep (PSM).
Arguments
-
"RADIO_OFF_SLEEP" (string, command)
❗command - the argument needs to have this exact form❗
Example
-- Turn off radio sleep
api.nbAT("RADIO_OFF_SLEEP")
api.nbAT("UPDATE")
api.nbAT("UPDATE")
Switches to SIM module update mode.
Arguments
-
"UPDATE" (string, command)
❗command - the argument needs to have this exact form❗
Example
-- Switch to update mode
api.nbAT("UPDATE")
api.nbAT("DTLS", pskid, psk)
api.nbAT("DTLS", "id", "psk")
Changes PSK and PSK ID for DTLS.
Arguments
-
"DTLS" (string, command)
❗command - the argument needs to have this exact form❗ -
pskid (string):
"PSK ID 001 test"- PSK ID.""- use empty string for deactivation.
-
psk (string):
"e560cb0d918d26d31b4f642181f5f570ad89a390931102e5391d08327ba434e9"- PSK ID.""- use empty string for deactivation.
Return
- status (integer):
0for success.-1for deactivation.
Example
-- Set DTLS PSK
api.nbAT("DTLS", "id", "psk")
api.nbAT("TIME_SYNC", force, zone)
api.nbAT("TIME_SYNC", 1, "UTC")
Synchronizes time with SIM module (by default done automatically on month change).
Arguments
-
"TIME_SYNC" (string, command)
❗command - the argument needs to have this exact form❗
Optional
- force (integer, optional):
1for force time sync.0for not forcing time sync.
- zone (string, optional): Time zone:
"UTC"for UTC time zone."LOCAL"for local time zone.
Return
- zoneShift (integer): Time zone shift in minutes, returns only when optional argument is set.
Example
-- Sync time in UTC
api.nbAT("TIME_SYNC", 1, "UTC")
api.nbAT("TRANSPARENT")
api.nbAT("TRANSPARENT")
Sets transparent mode.
Arguments
-
"TRANSPARENT" (string, command)
❗command - the argument needs to have this exact form❗
Example
-- Set transparent mode
api.nbAT("TRANSPARENT")
api.nbAT("SLEEP")
api.nbAT("SLEEP")
Puts SIM module to sleep.
Arguments
-
"SLEEP" (string, command)
❗command - the argument needs to have this exact form❗
Example
-- Put SIM to sleep
api.nbAT("SLEEP")
api.nbAT("APN=apn")
api.nbAT("APN=internet")
Sets a custom APN name.
Arguments
- "APN=apn" (string, command):
Explanation
The command consists of two parts, first one needs to stay the same:
"APN=
Then the string needs to be finnished with a value that represents your APN:
myAPN"
Alotgether, it would look like this:
"APN=myAPN"
Example
-- Set APN
api.nbAT("APN=internet")
--------------------------------
function onStartup()
print("--- NB-IoT - S0 default script ---")
-- print to serial only when serial is connected
api.exec("_print_mode", "CONNECTED")
-- set APN and PLMNID explicitely
api.nbAT("APN=" .. APN)
api.nbAT("PLMNID=" .. PLMNID)
api.nbAT("PLMNID=plmnid")
api.nbAT("PLMNID=20404")
Sets a custom PLMN ID.
Arguments
- "PLMNID=plmnid" (string, command):
Explanation
The command consists of two parts, first one needs to stay the same:
"PLMNID=
Then the string needs to be finnished with a value that represents your APN:
12345"
Alotgether, it would look like this:
"PLMNID=12345"
Example
-- Set PLMN ID
api.nbAT("PLMNID=20404")
--------------------------------
function onStartup()
print("--- NB-IoT - S0 default script ---")
-- print to serial only when serial is connected
api.exec("_print_mode", "CONNECTED")
-- set APN and PLMNID explicitely
api.nbAT("APN=" .. APN)
api.nbAT("PLMNID=" .. PLMNID)
api.nbAT("HARD_RX_TIMEOUT", timeout)
api.nbAT("HARD_RX_TIMEOUT", 5000)
Sets hard RX timeout.
Arguments
-
"HARD_RX_TIMEOUT" (string, command)
❗command - the argument needs to have this exact form❗ -
timeout (integer): Hard RX timeout in milliseconds.
Example
-- Set hard RX timeout to 5000 ms
api.nbAT("HARD_RX_TIMEOUT", 5000)
api.nbAT(command, timeout, wakeUp, success, err, tryMore, setAwakeBefore, pollBeforeCommand, setAwakeOffAfter, receiveFixedBytes)
api.nbAT("AT+CSQ")
Sends a custom AT command to the NB-IoT module.
Arguments
- command (string): AT command.
- timeout (integer): Maximum execution time in milliseconds.
Optional
- wakeUp (integer, optional): Sending
1will make sure that module is not asleep. - success (string, optional): Custom success message (default
"OK"). - err (string, optional): Custom error message (default
"ERROR"). - tryMore (integer, optional): Number of retries (max 5,
0- no answer awaited). - setAwakeBefore (integer, optional): Sending
1will set module awake before command. - pollBeforeCommand (integer, optional): Sending
1will test if module is listening. - setAwakeOffAfter (integer, optional): Sending
1will set module asleep after command. - receiveFixedBytes (integer, optional): Number of bytes to receive.
Return
- answer (string):
nilor non-zero length string with an answer to AT command. - status (integer): Zero for success, negative for failure.
Example
-- Get signal strength
res, b = api.nbAT("AT+CSQ")
print(res)
--------------------------------
else -- beacon
local function sendBeacon(rcntr, reason, uptime, sinceTau, lastGatherTs, lastBeaconTs, version)
local ans, res=api.nbAT("AT+CSQ", 6000, nil, "+CSQ:", "99", 3)
tn=mqtt_topic_base .. "beacon"
local y, M, d, h, m, sec=api.getTimeDate()
json("signal", tonumber(string.match(ans, "+CSQ: ([0-9]+),%d.*")) or 0, 1)
--------------------------------
-- Starting MQTT connection
mqtt_server = "server.cz" -- MQTT server
mqtt_user = "uuuuu"
mqtt_password = "pppppp"
mqtt_port = 1883 -- MQTT port
api.nbAT("AT+CSQ")
api.nbAT("AT+CEREG?")
api.nbAT("AT+COPS?")
-- api.nbAT("AT+CSSLCFG=\"authmode\",0,0") -- ,2 for SSL
api.nbAT("AT+CMQTTSTART", 5000, 0, "+CMQTTSTART: 0") -- Start MQTT
api.nbAT('AT+CMQTTACCQ=0,"' .. getIMSI() .. '"') -- ,1 for SSL
api.nbAT("AT+CMQTTCONNECT=0,\"tcp://" .. mqtt_server .. ":" .. mqtt_port .. "\",60,1,\"" .. mqtt_user .. "\",\"" .. mqtt_password .. "\"", 10000, 0, "+CMQTTCONNECT: 0,0")