Method
Description
getSaraR4Baudrate()
Returns the correct baudrate for the serial
port that connects to SARA R4XX
device
setDiag (Stream& stream)
Sets the optional "Diagnostics and
Debug" stream.
init(Stream& stream, int8_t onoffPin,
Stream&
stream, int8_t onoffPin, int8_t txEnablePin,
int8_t saraR4XXTogglePin, uint8_t cid)
Initializes the modem instance. Sets the
modem stream and the on-off power
pins.
createSocket(uint16_t localPort = 0)
Create a UDP socket for the specified
local port, returns the socket handle.
connect(const char* apn, const char* cdp, const
char* forceOperator = 0, uint8_t band = 8)
Turns on and initializes the modem, then
connects to the network and activates the
data connection. Returns true when
successful.
socketSend(uint8_t socket, const char*
remoteIP, const uint16_t remotePort, const
uint8_t* buffer, size_t size)
Send a UDP payload buffer to a
specified remote IP and port, through a
specific socket.
Table 3.1.2.1.1 SODAQ NB-IoT API
[31]
42
The code snippet below shows different methods used from API to implement the UPD
messaging over NB-IoT
//Define the operator-specific settings
const
char
* apn =
"u.iot.mt.gr.hu"
;
//The operator
’
s pre-commercial NB-IOT APN
const
char
* cdp =
NULL
;
const
uint8_t cid =
1
;
const
uint8_t band =
20
;
//LTE band 20 (Uplink: 832 MHz
–
862MHz; Downlink:
791
–
821)
const
char
* forceOperator =
"21630"
;
Sodaq_nbIOT nbiot;
//Create an object to access the API methods
void
setup()
{
/*Connect to the NB-IoT Network*/
DEBUG_STREAM.print(
"Initializing and connecting... "
);
while
(!nbiot.connect(apn, cdp, forceOperator, band));
DEBUG_STREAM.println(
"Connected succesfully!"
);
/*Open a UDP Socket*/
while
(!openSocketUDP());
/*Send a string to a remote IP and port*/
nbiot.socketSend(socketID,
"165.227.145.200"
,
41243
,
"SODAQ UDP Packet"
);
}
/*A custom-made function to open a UDP socket*/
int
openSocketUDP()
{
/*A open a socket at local port 0*/
socketID = nbiot.createSocket(0);
/*NB-IoT module assigns a socket ID, valid values are 0 to 6*/
if
(socketID >=
7
|| socketID <
0
)
{
DEBUG_STREAM.println(
"Failed to create socket"
);
return
0
;
}
else
{
DEBUG_STREAM.println(
"Created socket at"
);
DEBUG_STREAM.println(socketID);
return
1
;
}
}
43
Results
The state of debug serial terminal during the run-time and the received message
“SODAQ
UDP PACKET”
at remote IP is shown below.
Do'stlaringiz bilan baham: |