Example NB-IoT Project for ublox C030-N211
Dependencies: ublox-at-cellular-interface ublox-cellular-base ublox-cellular-base-n2xx ublox-at-cellular-interface-n2xx
Revision 35:a543c24a27a3, committed 2018-12-29
- Comitter:
- andreas_hbrs
- Date:
- Sat Dec 29 12:27:38 2018 +0000
- Parent:
- 33:48101a4c3f14
- Child:
- 36:2faea462ea54
- Commit message:
- echo upd server
Changed in this revision
--- a/main.cpp Wed Feb 28 15:13:03 2018 +0000
+++ b/main.cpp Sat Dec 29 12:27:38 2018 +0000
@@ -38,13 +38,13 @@
// UbloxATCellularInterface library with the UbloxATCellularInterfaceExt
// library). However, it is slower than using the LWIP/PPP on the mbed
// MCU interface since more string parsing is required.
-#define INTERFACE_CLASS UbloxATCellularInterface
+//#define INTERFACE_CLASS UbloxATCellularInterface
//#define INTERFACE_CLASS OnboardCellularInterface
-//#define INTERFACE_CLASS UbloxATCellularInterfaceN2xx
+#define INTERFACE_CLASS UbloxATCellularInterfaceN2xx
// The credentials of the SIM in the board. If PIN checking is enabled
// for your SIM card you must set this to the required PIN.
-#define PIN "0000"
+#define PIN "1833"
// Network credentials. You should set this according to your
// network/SIM card. For C030 non-N2xx boards, leave the parameters as NULL
@@ -53,6 +53,7 @@
// username and password NULL), or you may leave all three as NULL and then
// a lookup will be attempted for a small number of known networks
// (see APN_db.h in mbed-os/features/netsocket/cellular/utils).
+
#define APN NULL
#define USERNAME NULL
#define PASSWORD NULL
@@ -117,6 +118,15 @@
}
}
+static void printUbloxEcho(char * buf, int len)
+{
+ printf("Received Message = ");
+ for(int i = 0;i < len; i++) {
+ printf("%s", &buf[i]);
+ }
+ printf("\n");
+}
+
static void cbButton()
{
buttonPressed = true;
@@ -137,14 +147,14 @@
int main()
{
- INTERFACE_CLASS *interface = new INTERFACE_CLASS();
+// INTERFACE_CLASS *interface = new INTERFACE_CLASS();
// If you need to debug the cellular interface, comment out the
// instantiation above and uncomment the one below.
// For the N2xx interface, change xxx to MBED_CONF_UBLOX_CELL_BAUD_RATE,
// while for the non-N2xx interface change it to MBED_CONF_UBLOX_CELL_N2XX_BAUD_RATE.
-// INTERFACE_CLASS *interface = new INTERFACE_CLASS(MDMTXD, MDMRXD,
-// xxx,
-// true);
+ INTERFACE_CLASS *interface = new INTERFACE_CLASS(MDMTXD, MDMRXD,
+ MBED_CONF_UBLOX_CELL_N2XX_BAUD_RATE,
+ true);
#ifndef TARGET_UBLOX_C030_N211
TCPSocket sockTcp;
#endif
@@ -175,15 +185,22 @@
}
pulseEvent();
- printf("Getting the IP address of \"developer.mbed.org\" and \"2.pool.ntp.org\"...\n");
- if ((interface->gethostbyname("2.pool.ntp.org", &udpServer) == 0) &&
- (interface->gethostbyname("developer.mbed.org", &tcpServer) == 0)) {
+ //printf("Getting the IP address of \"2.pool.ntp.org\"...\n");
+ printf("Getting the IP address of \"echo.ublox.com\" ...\n");
+
+ if (
+ //(interface->gethostbyname("echo.ublox.com", &udpServer) == 0)
+ (interface->gethostbyname("195.34.89.241", &udpServer) == 0) // echo.ublox.com IP Address
+ //(interface->gethostbyname("2.pool.ntp.org", &udpServer) == 0)
+ ) {
pulseEvent();
- udpServer.set_port(123);
- printf("\"2.pool.ntp.org\" address: %s on port %d.\n", udpServer.get_ip_address(), udpServer.get_port());
- printf("\"developer.mbed.org\" address: %s on port %d.\n", tcpServer.get_ip_address(), tcpServer.get_port());
- tcpServer.set_port(80);
+ //udpServer.set_port(123);
+ udpServer.set_port(7); // 123 für ntp und meine Anwendung
+ //printf("\"2.pool.ntp.org\" address: %s on port %d.\n", udpServer.get_ip_address(), udpServer.get_port());
+ printf("\"echo.ublox.com\" address: %s on port %d.\n", udpServer.get_ip_address(), udpServer.get_port());
+ //printf("\"developer.mbed.org\" address: %s on port %d.\n", tcpServer.get_ip_address(), tcpServer.get_port());
+ //tcpServer.set_port(80);
printf("Performing socket operations in a loop (until the user button is pressed on C030 or forever on C027)...\n");
while (!buttonPressed) {
@@ -194,19 +211,27 @@
pulseEvent();
printf("UDP socket open.\n");
sockUdp.set_timeout(10000);
- printf("Sending time request to \"2.pool.ntp.org\" over UDP socket...\n");
+ //printf("Sending time request to \"2.pool.ntp.org\" over UDP socket...\n");
+ printf("Sending echo request to \"echo.ublox.com\" over UDP socket...\n");
memset (buf, 0, sizeof(buf));
- *buf = '\x1b';
+ //*buf = '\x1b';
+ *buf = 'A'; //'\x1b'; // https://stackoverflow.com/questions/26937857/what-does-the-x1b-47-0-message-sent-to-an-ntp-server-mean
+ // "Sending such a packet to port 123 of an NTP server will force the server to send a reply package."
if (sockUdp.sendto(udpServer, (void *) buf, 48) == 48) {
pulseEvent();
printf("Socket send completed, waiting for UDP response...\n");
+
+
x = sockUdp.recvfrom(&udpSenderAddress, buf, sizeof (buf));
+
+
if (x > 0) {
pulseEvent();
printf("Received %d byte response from server %s on UDP socket:\n"
"-------------------------------------------------------\n",
x, udpSenderAddress.get_ip_address());
- printNtpTime(buf, x);
+ //printNtpTime(buf, x);
+ printUbloxEcho(buf, x); // statt printNtpTime
printf("-------------------------------------------------------\n");
}
}
@@ -264,7 +289,8 @@
printf("Stopped.\n");
} else {
bad();
- printf("Unable to get IP address of \"developer.mbed.org\" or \"2.pool.ntp.org\".\n");
+ //printf("Unable to get IP address of \"2.pool.ntp.org\".\n");
+ printf("Unable to get IP address of \"echo.ublox.com\".\n");
}
}
--- a/mbed-os.lib Wed Feb 28 15:13:03 2018 +0000 +++ b/mbed-os.lib Sat Dec 29 12:27:38 2018 +0000 @@ -1,1 +1,1 @@ -https://github.com/ARMmbed/mbed-os/#eaf6f8153d8b8c2d3136f288ca3c5d4fbc1ae18f +https://github.com/ARMmbed/mbed-os/#2fd0c5cfbd83fce62da6308f9d64c0ab64e1f0d6
--- a/ublox-at-cellular-interface-n2xx.lib Wed Feb 28 15:13:03 2018 +0000 +++ b/ublox-at-cellular-interface-n2xx.lib Sat Dec 29 12:27:38 2018 +0000 @@ -1,1 +1,1 @@ -https://developer.mbed.org/teams/ublox/code/ublox-at-cellular-interface-n2xx/#b0757007cc72 +https://os.mbed.com/users/andreas_hbrs/code/ublox-at-cellular-interface-n2xx/#076b81d0c1d9
--- a/ublox-at-cellular-interface.lib Wed Feb 28 15:13:03 2018 +0000 +++ b/ublox-at-cellular-interface.lib Sat Dec 29 12:27:38 2018 +0000 @@ -1,1 +1,1 @@ -https://developer.mbed.org/teams/ublox/code/ublox-at-cellular-interface/#39264b492ce7 +https://developer.mbed.org/teams/ublox/code/ublox-at-cellular-interface/#2b30a056ae54
--- a/ublox-cellular-base-n2xx.lib Wed Feb 28 15:13:03 2018 +0000 +++ b/ublox-cellular-base-n2xx.lib Sat Dec 29 12:27:38 2018 +0000 @@ -1,1 +1,1 @@ -https://developer.mbed.org/teams/ublox/code/ublox-cellular-base-n2xx/#1afe5ed24f0c +https://developer.mbed.org/teams/ublox/code/ublox-cellular-base-n2xx/#e1fc61f7b5e4
--- a/ublox-cellular-base.lib Wed Feb 28 15:13:03 2018 +0000 +++ b/ublox-cellular-base.lib Sat Dec 29 12:27:38 2018 +0000 @@ -1,1 +1,1 @@ -https://developer.mbed.org/teams/ublox/code/ublox-cellular-base/#e420232ee4e7 +https://developer.mbed.org/teams/ublox/code/ublox-cellular-base/#15f31e074d67