Hello everybody. I am trying to connect to a UPD Webserver. I used the NBWebClient example project for the MKRNB 1500 with sim and antenna. With this code I had no trouble connecting to the http test website. But for this UPD server I am not sure what is going wrong. So far I know that something with this code part might not be right:
client.connect(server, port)
I saw that the function has a return value which I am saving and printing in the serial monitor. it takes a very long time. Sometimes it does not work and sometimes it gives me back a 0, connects and then disconnects again. My colleague who built the webserver (according to this example UDP - Client and Server example programs in Python | Pythontic.com) added the function if the client send a message Hello UDP Server it should answer Hello UDP Client. But nothing happens. even tough it quickly connects sometimes.

.
Unfortunately I have trouble using the debugger in the Arduino IDE and was not able to use it yet (error message Failed to launch OpenOCD GDB Server: Timeout)
/*
Web client
This sketch connects to a website through a MKR NB 1500 board. Specifically,
this example downloads the URL "http://example.org/" and
prints it to the Serial monitor.
Circuit:
- MKR NB 1500 board
- Antenna
- SIM card with a data plan
created 8 Mar 2012
by Tom Igoe
*/
// libraries
#include <MKRNB.h>
//#include "arduino_secrets.h"
// Please enter your sensitive data in the Secret tab or arduino_secrets.h
// PIN Number
const char PINNUMBER[] = "xxxx";
// initialize the library instance
NBClient client;
GPRS gprs;
NB nbAccess;
// URL, path and port (for example: example.org)
char server[] = "ec2-63-32-126-88.eu-west-1.compute.amazonaws.com";
//char server[] = "ec2-63-32-126-88.eu-west-1.compute.amazonaws.com";//"example.org";// "63.32.126.88"; // "ec2-63-32-126-88.eu-west-1.compute.amazonaws.com";
//char path[] = "/";
int port = 20001; //20001; // port 80 is the default for HTTP
void setup() {// initialize 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
}
Serial.println("Starting Arduino web client.");
// connection state
boolean connected = false;
// After starting the modem with NB.begin()
// attach to the GPRS network with the APN, login and password
while (!connected) {
// Serial.println("TEST: connecting");
if ((nbAccess.begin(PINNUMBER) == NB_READY) &&
(gprs.attachGPRS() == GPRS_READY)) {
connected = true;
} else {
Serial.println("Not connected");
delay(1000);
}
}
Serial.println("connecting...");
// if you get a connection, report back via serial:
int connResult = client.connect(server, port);
Serial.println(connResult);
if (connResult == 0) {
// if (client.connect(server, port)) {
Serial.println("connected");
// Make a HTTP request:
client.print("Hello UDP Server");
Serial.println("message to server sent");
} else {
// if you didn't get a connection to the server:
Serial.println("connection failed");
}
}
void loop() {
// if there are incoming bytes available from the server, read them and print them:
if (client.available()) {
Serial.print((char)client.read());
}
// if the server's disconnected, stop the client:
if (!client.available() && !client.connected()) {
Serial.println();
Serial.println("disconnecting.");
client.stop();
// do nothing forevermore:
for (;;)
;
}
}