This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

How do I post data/readings from the nRF5340 to a web page?

Hello,

I have a:
nRF5340DK connected to Windows10 PC via USB.

I also have these that are working fine in terms of being able to communicate with the nRF5340DK over Bluetooth:
nRF52840 BLE Dongle
nRF Connect and nRF Cloud Gateway on Android smartphone

For the final product, I intend to use BLE to send data from the nRF5340 to a smartphone app to send to a web page, but for the purposes of development, what is the best/easiest way to send data from the nRF5340DK via http to a web page? (Can you point to an example?)

Is there a way I can do it through the Windows10 PC connected via USB? If so, can I use the Application Core of the nRF5340?

Or do I need to use BLE as part of the Network Core to do this?

I have tried using the http_client, http_get, and echo_server projects that come with the nRF Connect SDK.
Below are my outputs, but it looks like I am misunderstanding how to use the correct network interfaces required for this.

I ran these on the Application Core. When I ran them on the Network Core I received no output at all on the terminal.
Does the Network Core require different terminal settings (com port, baud, parity, etc)? I am using Termite as my terminal.

Output using "~\ncs\v1.5.1\zephyr\samples\net\sockets\http_client":

https://developer.nordicsemi.com/nRF_Connect_SDK/doc/latest/zephyr/samples/net/sockets/http_client/README.html

*** Booting Zephyr OS build v2.4.99-ncs2  ***
[1B][1;32muart:~$ [1B][m
[1B][1;32muart:~$ [1B][m

[1B][1;32muart:~$ [1B][m[1B][8D[1B][J[00:01:33.542,358] [1B][1;31m<err> net_config: Timeout while waiting network interface[1B][0m
[1B][1;32muart:~$ [1B][m[1B][8D[1B][J[00:01:33.552,368] [1B][1;31m<err> net_config: Network initialization failed (-62)[1B][0m
[1B][1;32muart:~$ [1B][m[1B][8D[1B][J[00:01:43.382,598] [1B][1;31m<err> net_ctx: Cannot bind to 0.0.0.0[1B][0m
[1B][1;32muart:~$ [1B][m[1B][8D[1B][J[00:01:43.390,838] [1B][1;31m<err> net_http_client_sample: Cannot connect to IPv4 remote (-49)[1B][0m
[1B][1;32muart:~$ [1B][m[1B][8D[1B][J[00:01:43.736,999] [1B][1;31m<err> net_ctx: Cannot bind to ::[1B][0m
[1B][1;32muart:~$ [1B][m[1B][8D[1B][J[00:01:43.744,781] [1B][1;31m<err> net_http_client_sample: Cannot connect to IPv6 remote (-49)[1B][0m
[1B][1;32muart:~$ [1B][m[1B][8D[1B][J[00:01:43.755,554] [1B][0m<dbg> net_http.Data to send
                                  47 45 54 20 2f 20 48 54  54 50 2f 31 2e 31 0d 0a |GET / HT TP/1.1..
                                  48 6f 73 74 3a 20 31 39  32 2e 30 2e 32 2e 32 0d |Host: 19 2.0.2.2.
                                  0a 0d 0a                                         |...              [1B][0m
[1B][1;32muart:~$ [1B][m[1B][8D[1B][J[00:01:43.789,947] [1B][0m<dbg> net_http.Data to send
                                  47 45 54 20 2f 20 48 54  54 50 2f 31 2e 31 0d 0a |GET / HT TP/1.1..
                                  48 6f 73 74 3a 20 32 30  30 31 3a 64 62 38 3a 3a |Host: 20 01:db8::
                                  32 0d 0a 0d 0a                                   |2....            [1B][0m

Output using "~\ncs\v1.5.1\zephyr\samples\net\sockets\http_get":

https://developer.nordicsemi.com/nRF_Connect_SDK/doc/latest/zephyr/samples/net/sockets/http_get/README.html

*** Booting Zephyr OS build v2.4.99-ncs2  ***
[00:00:00.508,422] [1B][1;31m<err> net_if: There is no network interface to work with![1B][0m
[00:00:00.620,361] [1B][1;31m<err> net_ctx: Cannot bind to 0.0.0.0[1B][0m
[00:00:00.620,391] [1B][1;33m<wrn> net_dns_resolve: Cannot initialize DNS resolver (-125)[1B][0m
[00:00:00.624,420] [1B][0m<inf> net_config: Initializing network[1B][0m
[00:00:00.624,450] [1B][0m<inf> net_config: Waiting interface -1 ((nil)) to be up...[1B][0m

Additionally I have gone through the documentation for "Networking with the host system" and "USB Device Networking":

https://developer.nordicsemi.com/nRF_Connect_SDK/doc/latest/zephyr/guides/networking/networking_with_host.html#networking-with-host

https://developer.nordicsemi.com/nRF_Connect_SDK/doc/latest/zephyr/guides/networking/usbnet_setup.html#usb-device-networking-setup

It seems to imply I need to set up a "Socket Echo Server" on the board which I did, but still receive the errors below.

Output from running "~\ncs\v1.5.1\zephyr\samples\net\sockets\echo_server"

https://developer.nordicsemi.com/nRF_Connect_SDK/doc/latest/zephyr/samples/net/sockets/echo_server/README.html#sockets-echo-server-sample

*** Booting Zephyr OS build v2.4.99-ncs2  ***

[1B][1;32muart:~$ [1B][m[1B][8D[1B][J[00:00:00.497,894] [1B][1;31m<err> net_if: There is no network interface to work with![1B][0m
[1B][1;32muart:~$ [1B][m[1B][8D[1B][J[00:00:00.502,014] [1B][0m<inf> net_config: Initializing network[1B][0m
[1B][1;32muart:~$ [1B][m[1B][8D[1B][J[00:00:00.502,044] [1B][0m<inf> net_config: Waiting interface -1 ((nil)) to be up...[1B][0m
[1B][1;32muart:~$ [1B][m[1B][8D[1B][J[1B][1;32muart:~$ [1B][m[1B][8D[1B][J[00:01:33.502,990] [1B][1;31m<err> net_config: Timeout while waiting network interface[1B][0m
[1B][1;32muart:~$ [1B][m[1B][8D[1B][J[00:01:33.503,021] [1B][1;31m<err> net_config: Network initialization failed (-62)[1B][0m
[1B][1;32muart:~$ [1B][m[1B][8D[1B][J[00:01:41.685,729] [1B][0m<inf> net_echo_server_sample: Run echo server[1B][0m
[1B][1;32muart:~$ [1B][m[1B][8D[1B][J[00:01:41.685,760] [1B][0m<inf> net_echo_server_sample: Waiting network to be connected[1B][0m
[1B][1;32muart:~$ [1B][m[1B][8D[1B][J[1B][1;32muart:~$ [1B][m

I feel like what I am doing is overly convoluted for something that should be very simple to get network connectivity for development purposes to post to a web page.  Please advise.

Also, any idea why I receive all the extra characters in the output like "[1B][1;32muart:~$ [1B][m[1B][8D[1B][J[00:01:33.542,358] [1B][1;31m" and what does it mean or how do I get rid of it?
Thank-you!

  • Hi Benny, 
    I don't think the http examples would work straight out of the box for nRF53. It's made for the chip that has LTE/IP connection (e.g nRF91). 

    How do you do the communication between the nRF53 and PC via USB ?  

    My suggestion for the easiest way to send data from the nRF53 to nRF Cloud is to write your own application on Windows PC to send data to nRF Cloud , can use REST API , MQTT API. It can be python or any programming language of your choice. 
    So when you receive data from the NRF53 (USB) you can push it from the Windows PC to the cloud (similar to the way the NRF Cloud app on the phone push the data to nRF Cloud). The data you transmit from the nRF53 to Windows PC via USB can be just raw data. 

    Have a look at the documentation here:  https://nrfcloud.com/#/docs

Related