Hi everyone, I’m trying to send UDP packages to my server, but my server does not get any package. I want to debug this but it’s not clear what I can do.
Lets say I want to send UDP packages to my server 11.11.11.11
on port 5001
.
I’m using a slightly modified version of this sample code: https://github.com/SodaqMoja/Sodaq_nbIOT/blob/master/examples/nbIOT_test_udp/nbIOT_test_udp.ino
I removed some unused boards, removed T-mobile connection info (I’m using Vodafone) and I removed the UDP response from the server (for now I only want to send a UDP packet, the server does not respond (yet)).
#include "Sodaq_nbIOT.h"
#include "Sodaq_wdt.h"
// Select one of the operators
#define VODAFONE_NL
#if defined(ARDUINO_SODAQ_SARA)
#define DEBUG_STREAM SerialUSB
#define MODEM_STREAM Serial1
#define powerPin SARA_ENABLE
#define enablePin SARA_TX_ENABLE
#else
#error "Please use one of the listed boards or add your board."
#endif
#define DEBUG_STREAM SerialUSB
#define DEBUG_STREAM_BAUD 115200
#define STARTUP_DELAY 3000
#define MESSAGE_DELAY 5000
const char* apn = "nb.inetd.gdsp";
const char* cdp = "172.16.14.22";
const uint8_t band = 20;
const char* forceOperator = "20404";
Sodaq_nbIOT nbiot;
void sendMessageThroughUDP()
{
DEBUG_STREAM.println();
DEBUG_STREAM.println("Sending message through UDP"); // works
int localPort = 5001;
int socketID = nbiot.createSocket(localPort);
if (socketID >= 7 || socketID < 0) {
DEBUG_STREAM.println("Failed to create socket");
return;
}
DEBUG_STREAM.println("Created socket!"); //works
char* buffer = "74657374"; // test in hex
uint8_t size = strlen(buffer);
DEBUG_STREAM.println(nbiot.ping("11.11.11.11")); // <-- OUTPUT: 0
int lengthSent = nbiot.socketSend(socketID, "11.11.11.11", 5001, buffer, size);
DEBUG_STREAM.print("Length buffer vs sent: ");
DEBUG_STREAM.print(size);
DEBUG_STREAM.print(" - ");
DEBUG_STREAM.println(lengthSent); // <-- OUTPUT: Length buffer vs sent: 8 - 14573
nbiot.closeSocket(socketID);
DEBUG_STREAM.println("Closed socket"); //works
}
void setup()
{
sodaq_wdt_safe_delay(STARTUP_DELAY);
DEBUG_STREAM.begin(DEBUG_STREAM_BAUD);
MODEM_STREAM.begin(nbiot.getDefaultBaudrate());
DEBUG_STREAM.println("Initializing and connecting... this takes about 30 seconds."); // works
nbiot.init(MODEM_STREAM, powerPin);
nbiot.setDiag(DEBUG_STREAM);
#ifdef SARA_TX_ENABLE
pinMode(SARA_TX_ENABLE, OUTPUT);
digitalWrite(SARA_TX_ENABLE, HIGH);
#endif
#ifdef SARA_RESET
pinMode(SARA_RESET, OUTPUT);
digitalWrite(SARA_RESET, HIGH);
#endif
nbiot.overrideNconfigParam("CR_0354_0338_SCRAMBLING", true);
if (!nbiot.connect(apn, cdp, forceOperator, band)) {
DEBUG_STREAM.println("FAILED TO CONNECT TO MODEM");
} else {
DEBUG_STREAM.println("Connected to modem");
}
sendMessageThroughUDP();
}
void loop()
{
sodaq_wdt_safe_delay(MESSAGE_DELAY);
sendMessageThroughUDP();
}
That results in the following output:
Initializing and connecting... this takes about 30 seconds.
Connected to modem
Sending message through UDP
Created socket!
0
Length buffer vs sent: 8 - 14573
Closed socket
Sending message through UDP
Created socket!
0
Length buffer vs sent: 8 - 14573
Closed socket
My server does not get any data at all.
What am I missing here?
Using SARA-N211 rev 1.