
This is a simple mbed client example demonstrating, registration of a device with mbed Device Connector and reading and writing values as well as deregistering on different Network Interfaces including Ethernet, WiFi, 6LoWPAN ND and Thread respectively.
Getting started with mbed Client on mbed OS
This is the mbed Client example for mbed OS. It demonstrates how to register a device with mbed Device Connector, how to read and write values, and how to deregister. If you are unfamiliar with mbed Device Connector, we recommend that you read the introduction to the data model first.
The application:
- Connects to network with WiFi, Ethernet, 6LoWPAN ND or Thread connection.
- Registers with mbed Device Connector.
- Gives mbed Device Connector access to its resources (read and write).
- Records the number of clicks on the device’s button and sends the number to mbed Device Connector.
- Lets you control the blink pattern of the LED on the device (through mbed Device Connector).
Required hardware
- K64F board.
- 1-2 micro-USB cables.
- mbed 6LoWPAN gateway router for 6LoWPAN ND and Thread.
- mbed 6LoWPAN shield (AT86RF212B/AT86RF233 for 6LoWPAN ND and Thread.
- Ethernet cable and connection to the internet.
Requirements for non K64F board
This example application is primarily designed for FRDM-K64F board but you can also use other mbed OS supported boards to run this example application , with some minor modifications for setup.
- To get the application registering successfully on non K64F boards , you need Edit the mbed_app.json file to add NULL_ENTROPY feature for mbedTLS:
""macros": ["MBEDTLS_USER_CONFIG_FILE=\"mbedtls_mbed_client_config.h\"", "MBEDTLS_NO_DEFAULT_ENTROPY_SOURCES", "MBEDTLS_TEST_NULL_ENTROPY"],
- On non K64F boards, there is no unregistration functionality and button press is simulated through timer ticks incrementing every 15 seconds.
Application setup
To configure the example application, please check following:
- Connection type.
- Client credentials
- Change 6LoWPAN ND & Thread settings
- Change Ethernet settings
- Change Wi-Fi settings
- Set up an IP address. This step is optional.
- Change the socket typeThis step is optional.
Connection type
The application uses Ethernet as the default connection type. To change the connection type, set one of them in mbed_app.json. For example, to enable 6LoWPAN ND mode:
"network-interface": { "help": "options are ETHERNET,WIFI,MESH_LOWPAN_ND,MESH_THREAD.", "value": "MESH_LOWPAN_ND" }
Client credentials
To register the application to the Connector service, you need to create and set the client side certificate.
- Go to mbed Device Connector and log in with your mbed account.
- On mbed Device Connector, go to My Devices > Security credentials and click the Get my device security credentials button to get new credentials for your device.
- Replace the contents in `security.h` of this project's directory with content copied above.
6LoWPAN ND and Thread settings
First you need to select the RF driver to be used by 6LoWPAN/Thread stack.
For example Atmel AT86RF233/212B driver is located in https://github.com/ARMmbed/atmel-rf-driver
To add that driver to you application , import library from following URL:
https://github.com/ARMmbed/atmel-rf-driver
Then you need to enable the IPV6 functionality as the 6LoWPAN and Thread are part of IPv6 stack. Edit the mbed_app.json file to add IPV6 feature:
"target.features_add": ["CLIENT", "IPV6", "COMMON_PAL"],
6LoWPAN ND and Thread use IPv6 for connectivity. Therefore, you need to verify first that you have a working IPv6 connection. To do that, ping the Connector IPv6 address 2607:f0d0:2601:52::20 from your network.
mbed gateway
To connect the example application in 6LoWPAN ND or Thread mode to Connector, you need to set up an mbed 6LoWPAN gateway router as follows:
- Use an Ethernet cable to connect the mbed 6LoWPAN gateway router to the internet.
- Use a micro-USB cable to connect the mbed 6LoWPAN gateway router to your computer. The computer will list the router as removable storage.
- The firmware for the gateway is located in the `GW_Binary` folder in the root of this example. Select the binary matching your application bootstrap mode:
- For the 6LoWPAN ND bootstrap, use `gateway6LoWPANDynamic.bin`.
- For the Thread bootstrap, use `gatewayThreadDynamic.bin`.
The dynamic binaries use IPv6 autoconfiguration and enable the client to connect to the Connector service. The static binaries create a site-local IPv6 network and packets cannot be routed outside.
- Copy the gateway binary file to the mbed 6LoWPAN gateway router to flash the device. The device reboots automatically after flashing. If that does not happen, press the Reset button on the board.
You can view debug traces from the gateway with a serial port monitor. The gateway uses baud rate 460800. The gateway IPv6 address is correctly configured when the following trace is visible: `Eth bootstrap ready, IP=XXXX:XXXX:XXXX:XXXX:XXXX:XXXX:XXXX:XXXX`.
Channel settings
The default 2.4GHz channel settings are already defined by the mbed-mesh-api to match the mbed gateway settings. The application can override these settings by adding them to the mbed_app.json file in the main project directory. For example:
"target_overrides": { "*": { "mbed-mesh-api.6lowpan-nd-channel-page": 0, "mbed-mesh-api.6lowpan-nd-channel": 12, "mbed-mesh-api.thread-config-channel-page": 0, "mbed-mesh-api.thread-config-channel": 12 } }
For sub-GHz shields (AT86RF212B) use the following overrides, 6LoWPAN ND only:
"mbed-mesh-api.6lowpan-nd-channel-page": 2, "mbed-mesh-api.6lowpan-nd-channel": 1
For more information about the radio shields, see [the related documentation](docs/radio_module_identify.md). All the configurable settings can be found in the mbed-os-example-client/mbed-os/features/FEATURE_IPV6/mbed-mesh-api/mbed_lib.json file.
Thread-specific settings
With Thread, you can change the operating mode of the client from the default router mode to a sleepy end device by adding the following override to the `mbed_app.json` file:
"mbed-mesh-api.thread-device-type": "MESH_DEVICE_TYPE_THREAD_SLEEPY_END_DEVICE"
Ethernet settings
For running the example application using Ethernet, you need:
- An Ethernet cable.
- An Ethernet connection to the internet.
Wi-Fi settings
The example application uses ESP8266 WiFi Interface for managing the wireless connectivity. To run this application using WiFi, you need:
- An ESP8266 WiFi module
- Updated Espressif Firmware
- Mount the WiFi module onto K64F Grove Shield v2
- Attach the shield on the K64F board.
- In the `mbed_app.json` file, change
"network-interface": { "help": "options are ETHERNET,WIFI,MESH_LOWPAN_ND,MESH_THREAD.", "value": "WIFI" }
Provide your WiFi SSID and password here and leave `\"` in the beginning and end of your SSID and password (as shown in the example below). Otherwise, the example cannot pick up the SSID and password in correct format.
"wifi-ssid": { "help": "WiFi SSID", "value": "\"SSID\"" }, "wifi-password": { "help": "WiFi Password", "value": "\"Password\"" }
IP address setup
This example uses IPv4 to communicate with the mbed Device Connector Server except for 6LoWPAN ND and Thread. The example program should automatically get an IPv4 address from the router when connected over Ethernet.
If your network does not have DHCP enabled, you have to manually assign a static IP address to the board. We recommend having DHCP enabled to make everything run smoothly.
Changing socket type
Your device can connect to mbed Device Connector via UDP or TCP binding mode. The default is UDP. The binding mode cannot be changed in 6LoWPAN ND or Thread mode.
To change the binding mode:
- In the `simpleclient.h` file, find the parameter `SOCKET_MODE`. The default is `M2MInterface::UDP`.
- To switch to TCP, change it to `M2MInterface::TCP`.
- Rebuild and flash the application.
Tip: The instructions in this document remain the same, irrespective of the socket mode you select.
Monitoring the application
The application prints debug messages over the serial port, so you can monitor its activity with a serial port monitor. The application uses baud rate 115200.
After connecting, you should see messages about connecting to mbed Device Connector:
In app_start() IP address 10.2.15.222 Device name 6868df22-d353-4150-b90a-a878130859d9
When you click the `SW2` button on your board you should see messages about the value changes:
handle_button_click, new value of counter is 1
Testing the application
- Flash the application.
- Verify that the registration succeeded. You should see `Registered object successfully!` printed to the serial port.
- On mbed Device Connector, go to My devices > Connected devices. Your device should be listed here.
- Press the `SW2` button on the device a number of times (make a note of how many times you did that).
- Go to Device Connector > API Console.
- Enter https://api.connector.mbed.com/endpoints/DEVICE_NAME/3200/0/5501 in the URI field and click TEST API. Replace DEVICE_NAME with your actual endpoint name. The device name can be found in the security.h file, see variable MBED_ENDPOINT_NAME or it can be found from the traces.
- The number of times you pressed SW2 is shown.
- Press the SW3 button to unregister from mbed Device Connector. You should see Unregistered Object Successfully printed to the serial port and the LED starts blinking. This will also stop your application. Press the `RESET` button to run the program again.
For more methods check the mbed Device Connector Quick Start.
Application resources
The application exposes three resources:
- 3200/0/5501. Number of presses of SW2 (GET).
- 3201/0/5850. Blink function, blinks LED1 when executed (POST).
- 3201/0/5853. Blink pattern, used by the blink function to determine how to blink. In the format of 1000:500:1000:500:1000:500 (PUT).
For information on how to get notifications when resource 1 changes, or how to use resources 2 and 3, take a look at the mbed Device Connector Quick Start.
Building this example
Building with mbed CLI
If you'd like to use mbed CLI to build this, then you should follow the instructions in the Handbook TODO - new link. The instructions here relate to using the developer.mbed.org Online Compiler
If you'd like to use the online Compiler, then you can Import this code into your compiler, select your platform from the top right, compile the code using the compile button, load it onto your board, press the reset button on the board and you code will run. See the client go online!
More instructions for using the mbed Online Compiler can be found at TODO - update this
Revision 63:c73f78fd7982, committed 2017-02-15
- Comitter:
- mbed_official
- Date:
- Wed Feb 15 08:00:11 2017 +0000
- Parent:
- 62:077cbce2bd10
- Child:
- 64:d7458b04a609
- Commit message:
- Integrate easy-connect, fix serial, fix warning (#176)
Integrate easy-connect
- we can remove all the external RF-drivers from main folder
- get easy-connect into use
- remove all the complicated network stuff
Fix serial - we don't need raw serial and we don't need to initialize it
if we set the right stuff to mbed_app.json (added). Plain printf() works
and it even does type checking now. (Points to Kevin Bracey on this).
Start the thread in a non-deprecated way using callback to remove one compiler
warning (again, points to Kevin Bracey).
Easy-connect ESP8266 TX/RX pins in different defines.
mbed-os-example-client has NEVER used 2 sets of WiFi pins, so need
to add a define to hack them into one set - otherwise it will not compile.
The cp command would not have worked if one would have changed
the compiler. Add UBLOX ODIN ETH config to be built as well,
now that we have figured out how to make the the ethernet work
on it.
Change also the WIFI to work with easy-connect. Easy-connect has 2 separate WIFIs,
so you have to choose between ESP8266 vs. ODIN. Thus, 2 config files are also needed,
one for ESP8266 and one for ODIN.
.
Commit copied from https://github.com/ARMmbed/mbed-os-example-client
Changed in this revision
--- a/README.md Thu Feb 02 08:30:11 2017 +0000 +++ b/README.md Wed Feb 15 08:00:11 2017 +0000 @@ -323,15 +323,17 @@ After connecting, you should see messages about connecting to mbed Device Connector: ``` -Starting mbed Client example... -Using <Network Interface> +Starting mbed Client example in IPv4 mode +[EasyConnect] Using Ethernet +[EasyConnect] Connected to Network successfully +[EasyConnect] IP address 192.168.8.110 +[EasyConnect] MAC address 5c:cf:7f:86:de:bf -Connected to Network successfully -IP address xxx.xxx.xxx.xxx +SOCKET_MODE : TCP -SOCKET_MODE : UDP Connecting to coap://api.connector.mbed.com:5684 +Registered object succesfully! ``` <span class="notes">**Note:** Device name is the endpoint name you will need later on when [testing the application](https://github.com/ARMmbed/mbed-os-example-client#testing-the-application).</span>
--- a/atmel-rf-driver.lib Thu Feb 02 08:30:11 2017 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,1 +0,0 @@ -https://github.com/armmbed/atmel-rf-driver/#57f22763f4d3649d4ac0b1df1f568f4cc45e491a
--- a/build_all.sh Thu Feb 02 08:30:11 2017 +0000 +++ b/build_all.sh Wed Feb 15 08:00:11 2017 +0000 @@ -4,37 +4,52 @@ TOOL=GCC_ARM echo Compiling with $TOOL +echo Ethernet v4 cp configs/eth_v4.json ./mbed_app.json cp configs/eth-wifi-mbedignore ./.mbedignore mbed compile -m K64F -t $TOOL -cp BUILD/K64F/GCC_ARM/mbed-os-example-client.bin k64f-$TOOL-eth-v4.bin +cp BUILD/K64F/$TOOL/mbed-os-example-client.bin k64f-$TOOL-eth-v4.bin mbed compile -m NUCLEO_F439ZI -t $TOOL -cp ./BUILD/NUCLEO_F439ZI/GCC_ARM/mbed-os-example-client.bin f439zi-$TOOL-eth-v4.bin +cp ./BUILD/NUCLEO_F439ZI/$TOOL/mbed-os-example-client.bin f439zi-$TOOL-eth-v4.bin +mbed compile -m UBLOX_EVK_ODIN_W2 -t $TOOL +cp ./BUILD/UBLOX_EVK_ODIN_W2/$TOOL/mbed-os-example-client.bin ublox-odin-$TOOL-eth-v4.bin +echo Ethernet v6 cp configs/eth_v6.json ./mbed_app.json cp configs/eth-wifi-mbedignore ./.mbedignore mbed compile -m K64F -t $TOOL -cp BUILD/K64F/GCC_ARM/mbed-os-example-client.bin k64f-$TOOL-eth-v6.bin +cp BUILD/K64F/$TOOL/mbed-os-example-client.bin k64f-$TOOL-eth-v6.bin mbed compile -m NUCLEO_F439ZI -t $TOOL -cp ./BUILD/NUCLEO_F439ZI/GCC_ARM/mbed-os-example-client.bin f439zi-$TOOL-eth-v4.bin +cp ./BUILD/NUCLEO_F439ZI/$TOOL/mbed-os-example-client.bin f439zi-$TOOL-eth-v4.bin +mbed compile -m UBLOX_EVK_ODIN_W2 -t $TOOL +cp ./BUILD/UBLOX_EVK_ODIN_W2/$TOOL/mbed-os-example-client.bin ublox-odin-$TOOL-eth-v6.bin -cp configs/wifi_v4.json ./mbed_app.json +echo WIFI - ESP8266 +cp configs/wifi_esp8266_v4.json ./mbed_app.json cp configs/eth-wifi-mbedignore ./.mbedignore mbed compile -m K64F -t $TOOL -cp BUILD/K64F/GCC_ARM/mbed-os-example-client.bin k64f-$TOOL-wifi-v4.bin +cp BUILD/K64F/$TOOL/mbed-os-example-client.bin k64f-$TOOL-esp-wifi-v4.bin +mbed compile -m NUCLEO_F439ZI -t $TOOL +cp ./BUILD/NUCLEO_F439ZI/$TOOL/mbed-os-example-client.bin f439zi-$TOOL-esp-wifi-v4.bin + +echo WIFI - ODIN for UBLOX_EVK_ODIN_W2 +cp configs/wifi_odin_v4.json ./mbed_app.json +cp configs/eth-wifi-mbedignore ./.mbedignore mbed compile -m UBLOX_EVK_ODIN_W2 -t $TOOL -cp ./BUILD/UBLOX_EVK_ODIN_W2/GCC_ARM/mbed-os-example-client.bin ublox-odin-$TOOL-wifi-v4.bin +cp ./BUILD/UBLOX_EVK_ODIN_W2/$TOOL/mbed-os-example-client.bin ublox-odin-$TOOL-wifi-v4.bin +echo 6-Lowpan builds cp configs/mesh_6lowpan.json ./mbed_app.json cp configs/mesh-mbedignore ./.mbedignore mbed compile -m K64F -t $TOOL -cp BUILD/K64F/GCC_ARM/mbed-os-example-client.bin k64f-$TOOL-6lowpan.bin +cp BUILD/K64F/$TOOL/mbed-os-example-client.bin k64f-$TOOL-6lowpan.bin mbed compile -m NUCLEO_F439ZI -t $TOOL -cp ./BUILD/NUCLEO_F439ZI/GCC_ARM/mbed-os-example-client.bin f439zi-$TOOL-6lowpan.bin +cp ./BUILD/NUCLEO_F439ZI/$TOOL/mbed-os-example-client.bin f439zi-$TOOL-6lowpan.bin +echo Thread builds cp configs/mesh_thread.json ./mbed_app.json cp configs/mesh-mbedignore ./.mbedignore mbed compile -m K64F -t $TOOL -cp BUILD/K64F/GCC_ARM/mbed-os-example-client.bin k64f-$TOOL-Thread.bin +cp BUILD/K64F/$TOOL/mbed-os-example-client.bin k64f-$TOOL-Thread.bin mbed compile -m NUCLEO_F439ZI -t $TOOL -cp ./BUILD/NUCLEO_F439ZI/GCC_ARM/mbed-os-example-client.bin f439zi-$TOOL-Thread.bin \ No newline at end of file +cp ./BUILD/NUCLEO_F439ZI/$TOOL/mbed-os-example-client.bin f439zi-$TOOL-Thread.bin
--- a/configs/eth-wifi-mbedignore Thu Feb 02 08:30:11 2017 +0000 +++ b/configs/eth-wifi-mbedignore Wed Feb 15 08:00:11 2017 +0000 @@ -1,3 +1,3 @@ -atmel-rf-driver/* -mcr20a-rf-driver/* +easy-connect/atmel-rf-driver/* +easy-connect/mcr20a-rf-driver/*
--- a/configs/eth_v4.json Thu Feb 02 08:30:11 2017 +0000 +++ b/configs/eth_v4.json Wed Feb 15 08:00:11 2017 +0000 @@ -1,7 +1,7 @@ { "config": { "network-interface":{ - "help": "options are ETHERNET,WIFI,MESH_LOWPAN_ND,MESH_THREAD", + "help": "Options are ETHERNET, WIFI_ESP8266, WIFI_ODIN, MESH_LOWPAN_ND, MESH_THREAD", "value": "ETHERNET" } }, @@ -9,6 +9,8 @@ "target_overrides": { "*": { "target.features_add": ["LWIP", "COMMON_PAL"], + "platform.stdio-baud-rate": 115200, + "platform.stdio-convert-newlines": true, "lwip.ipv4-enabled": true, "lwip.ipv6-enabled": false, "mbed-trace.enable": 0
--- a/configs/eth_v6.json Thu Feb 02 08:30:11 2017 +0000 +++ b/configs/eth_v6.json Wed Feb 15 08:00:11 2017 +0000 @@ -1,7 +1,7 @@ { "config": { "network-interface":{ - "help": "options are ETHERNET,WIFI,MESH_LOWPAN_ND,MESH_THREAD", + "help": "Options are ETHERNET, WIFI_ESP8266, WIFI_ODIN, MESH_LOWPAN_ND, MESH_THREAD", "value": "ETHERNET" } }, @@ -9,6 +9,8 @@ "target_overrides": { "*": { "target.features_add": ["LWIP", "COMMON_PAL"], + "platform.stdio-baud-rate": 115200, + "platform.stdio-convert-newlines": true, "lwip.ipv4-enabled": false, "lwip.ipv6-enabled": true, "mbed-trace.enable": 0
--- a/configs/mesh-mbedignore Thu Feb 02 08:30:11 2017 +0000 +++ b/configs/mesh-mbedignore Wed Feb 15 08:00:11 2017 +0000 @@ -1,1 +1,1 @@ -esp8266-driver/* +easy-connect/esp8266-driver/*
--- a/configs/mesh_6lowpan.json Thu Feb 02 08:30:11 2017 +0000 +++ b/configs/mesh_6lowpan.json Wed Feb 15 08:00:11 2017 +0000 @@ -1,7 +1,7 @@ { "config": { "network-interface":{ - "help": "options are ETHERNET,WIFI,MESH_LOWPAN_ND,MESH_THREAD", + "help": "Options are ETHERNET, WIFI_ESP8266, WIFI_ODIN, MESH_LOWPAN_ND, MESH_THREAD", "value": "MESH_LOWPAN_ND" }, "mesh_radio_type": { @@ -13,6 +13,8 @@ "target_overrides": { "*": { "target.features_add": ["NANOSTACK", "LOWPAN_ROUTER", "COMMON_PAL"], + "platform.stdio-baud-rate": 115200, + "platform.stdio-convert-newlines": true, "mbed-mesh-api.6lowpan-nd-channel-page": 0, "mbed-mesh-api.6lowpan-nd-channel": 12, "mbed-trace.enable": 0
--- a/configs/mesh_thread.json Thu Feb 02 08:30:11 2017 +0000 +++ b/configs/mesh_thread.json Wed Feb 15 08:00:11 2017 +0000 @@ -1,7 +1,7 @@ { "config": { "network-interface":{ - "help": "options are ETHERNET,WIFI,MESH_LOWPAN_ND,MESH_THREAD", + "help": "Options are ETHERNET, WIFI_ESP8266, WIFI_ODIN, MESH_LOWPAN_ND, MESH_THREAD", "value": "MESH_THREAD" }, "mesh_radio_type": { @@ -13,6 +13,8 @@ "target_overrides": { "*": { "target.features_add": ["NANOSTACK", "THREAD_ROUTER", "COMMON_PAL"], + "platform.stdio-baud-rate": 115200, + "platform.stdio-convert-newlines": true, "mbed-mesh-api.thread-config-channel": 12, "mbed-mesh-api.thread-config-panid": "0xDEFA", "mbed-trace.enable": 0
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/configs/wifi_esp8266_v4.json Wed Feb 15 08:00:11 2017 +0000 @@ -0,0 +1,43 @@ +{ + "config": { + "network-interface":{ + "help": "Options are ETHERNET, WIFI_ESP8266, WIFI_ODIN, MESH_LOWPAN_ND, MESH_THREAD", + "value": "WIFI_ESP8266" + }, + "wifi-ssid": { + "help": "WiFi SSID", + "value": "\"SSID\"" + }, + "wifi-password": { + "help": "WiFi Password", + "value": "\"Password\"" + }, + "wifi-tx": { + "help": "TX pin for serial connection to external device", + "value": "D1" + }, + "wifi-rx": { + "help": "RX pin for serial connection to external device", + "value": "D0" + } + }, + "macros": ["MBEDTLS_USER_CONFIG_FILE=\"mbedtls_mbed_client_config.h\""], + "target_overrides": { + "*": { + "target.features_add": ["LWIP", "COMMON_PAL"], + "platform.stdio-baud-rate": 115200, + "platform.stdio-convert-newlines": true, + "lwip.ipv4-enabled": true, + "lwip.ipv6-enabled": false, + "mbed-trace.enable": 0 + }, + "NUCLEO_F401RE": { + "wifi-tx": "PA_11", + "wifi-rx": "PA_12" + }, + "NUCLEO_F411RE": { + "wifi-tx": "PA_11", + "wifi-rx": "PA_12" + } + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/configs/wifi_odin_v4.json Wed Feb 15 08:00:11 2017 +0000 @@ -0,0 +1,43 @@ +{ + "config": { + "network-interface":{ + "help": "Options are ETHERNET, WIFI_ESP8266, WIFI_ODIN, MESH_LOWPAN_ND, MESH_THREAD", + "value": "WIFI_ODIN" + }, + "wifi-ssid": { + "help": "WiFi SSID", + "value": "\"SSID\"" + }, + "wifi-password": { + "help": "WiFi Password", + "value": "\"Password\"" + }, + "wifi-tx": { + "help": "TX pin for serial connection to external device", + "value": "D1" + }, + "wifi-rx": { + "help": "RX pin for serial connection to external device", + "value": "D0" + } + }, + "macros": ["MBEDTLS_USER_CONFIG_FILE=\"mbedtls_mbed_client_config.h\""], + "target_overrides": { + "*": { + "target.features_add": ["LWIP", "COMMON_PAL"], + "platform.stdio-baud-rate": 115200, + "platform.stdio-convert-newlines":true, + "lwip.ipv4-enabled": true, + "lwip.ipv6-enabled": false, + "mbed-trace.enable": 0 + }, + "NUCLEO_F401RE": { + "wifi-tx": "PA_11", + "wifi-rx": "PA_12" + }, + "NUCLEO_F411RE": { + "wifi-tx": "PA_11", + "wifi-rx": "PA_12" + } + } +}
--- a/configs/wifi_v4.json Thu Feb 02 08:30:11 2017 +0000 +++ b/configs/wifi_v4.json Wed Feb 15 08:00:11 2017 +0000 @@ -1,8 +1,8 @@ { "config": { "network-interface":{ - "help": "options are ETHERNET,WIFI,MESH_LOWPAN_ND,MESH_THREAD", - "value": "WIFI" + "help": "Options are ETHERNET, WIFI_ESP8266, WIFI_ODIN, MESH_LOWPAN_ND, MESH_THREAD", + "value": "WIFI_ESP8266" }, "wifi-ssid": { "help": "WiFi SSID", @@ -25,6 +25,8 @@ "target_overrides": { "*": { "target.features_add": ["LWIP", "COMMON_PAL"], + "platform.stdio-baud-rate": 115200, + "platform.stdio-convert-newlines": true, "lwip.ipv4-enabled": true, "lwip.ipv6-enabled": false, "mbed-trace.enable": 0
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/easy-connect.lib Wed Feb 15 08:00:11 2017 +0000 @@ -0,0 +1,1 @@ +https://github.com/ARMmbed/easy-connect.git/#a913964341394430cd3997c6f2950f93ba1d75c8
--- a/esp8266-driver.lib Thu Feb 02 08:30:11 2017 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,1 +0,0 @@ -https://github.com/ARMmbed/esp8266-driver/#86ed47c8bf40c86fdc569c7e678a8944f5e01c2a
--- a/main.cpp Thu Feb 02 08:30:11 2017 +0000 +++ b/main.cpp Wed Feb 15 08:00:11 2017 +0000 @@ -13,6 +13,8 @@ * See the License for the specific language governing permissions and * limitations under the License. */ +#define __STDC_FORMAT_MACROS +#include <inttypes.h> #include "simpleclient.h" #include <string> #include <sstream> @@ -23,50 +25,11 @@ #include "security.h" #include "mbed.h" -#include "rtos.h" -#if MBED_CONF_APP_NETWORK_INTERFACE == WIFI - #if TARGET_UBLOX_EVK_ODIN_W2 - #include "OdinWiFiInterface.h" - OdinWiFiInterface wifi; - #else - #include "ESP8266Interface.h" - ESP8266Interface wifi(MBED_CONF_APP_WIFI_TX, MBED_CONF_APP_WIFI_RX); - #endif -#elif MBED_CONF_APP_NETWORK_INTERFACE == ETHERNET - #include "EthernetInterface.h" - EthernetInterface eth; -#elif MBED_CONF_APP_NETWORK_INTERFACE == MESH_LOWPAN_ND - #define MESH - #include "NanostackInterface.h" - LoWPANNDInterface mesh; -#elif MBED_CONF_APP_NETWORK_INTERFACE == MESH_THREAD - #define MESH - #include "NanostackInterface.h" - ThreadInterface mesh; -#endif - -#if defined(MESH) -#if MBED_CONF_APP_MESH_RADIO_TYPE == ATMEL -#include "NanostackRfPhyAtmel.h" -NanostackRfPhyAtmel rf_phy(ATMEL_SPI_MOSI, ATMEL_SPI_MISO, ATMEL_SPI_SCLK, ATMEL_SPI_CS, - ATMEL_SPI_RST, ATMEL_SPI_SLP, ATMEL_SPI_IRQ, ATMEL_I2C_SDA, ATMEL_I2C_SCL); -#elif MBED_CONF_APP_MESH_RADIO_TYPE == MCR20 -#include "NanostackRfPhyMcr20a.h" -NanostackRfPhyMcr20a rf_phy(MCR20A_SPI_MOSI, MCR20A_SPI_MISO, MCR20A_SPI_SCLK, MCR20A_SPI_CS, MCR20A_SPI_RST, MCR20A_SPI_IRQ); -#endif //MBED_CONF_APP_RADIO_TYPE -#endif //MESH - -#ifdef MESH - // Mesh does not have DNS, so must use direct IPV6 address - #define MBED_SERVER_ADDRESS "coaps://[2607:f0d0:2601:52::20]:5684" -#else - // This is address to mbed Device Connector, name based - // assume all other stacks support DNS properly - #define MBED_SERVER_ADDRESS "coap://api.connector.mbed.com:5684" -#endif - -RawSerial output(USBTX, USBRX); +// easy-connect compliancy, it has 2 sets of wifi pins we have only one +#define MBED_CONF_APP_ESP8266_TX MBED_CONF_APP_WIFI_TX +#define MBED_CONF_APP_ESP8266_RX MBED_CONF_APP_WIFI_RX +#include "easy-connect/easy-connect.h" // Status indication DigitalOut red_led(LED1); @@ -176,7 +139,7 @@ // turn the buffer into a string, and initialize a vector<int> on the heap std::string s((char*)buffIn, sizeIn); free(buffIn); - output.printf("led_execute_callback pattern=%s\r\n", s.c_str()); + printf("led_execute_callback pattern=%s\n", s.c_str()); // our pattern is something like 500:200:500, so parse that std::size_t found = s.find_first_of(":"); @@ -196,11 +159,11 @@ String resource_name = param->get_argument_resource_name(); int payload_length = param->get_argument_value_length(); uint8_t* payload = param->get_argument_value(); - output.printf("Resource: %s/%d/%s executed\r\n", object_name.c_str(), object_instance_id, resource_name.c_str()); - output.printf("Payload: %.*s\r\n", payload_length, payload); + printf("Resource: %s/%d/%s executed\n", object_name.c_str(), object_instance_id, resource_name.c_str()); + printf("Payload: %.*s\n", payload_length, payload); } // do_blink is called with the vector, and starting at -1 - blinky_thread.start(this, &LedResource::do_blink); + blinky_thread.start(callback(this, &LedResource::do_blink)); } private: @@ -266,9 +229,9 @@ // up counter counter++; #ifdef TARGET_K64F - printf("handle_button_click, new value of counter is %d\r\n", counter); + printf("handle_button_click, new value of counter is %d\n", counter); #else - printf("simulate button_click, new value of counter is %d\r\n", counter); + printf("simulate button_click, new value of counter is %d\n", counter); #endif // serialize the value of counter as a string, and tell connector char buffer[20]; @@ -304,9 +267,9 @@ if (argument) { if (M2MBlockMessage::ErrorNone == argument->error_code()) { if (argument->is_last_block()) { - output.printf("Last block received\r\n"); + printf("Last block received\n"); } - output.printf("Block number: %d\r\n", argument->block_number()); + printf("Block number: %d\n", argument->block_number()); // First block received if (argument->block_number() == 0) { // Store block @@ -315,14 +278,14 @@ // Store blocks } } else { - output.printf("Error when receiving block message! - EntityTooLarge\r\n"); + printf("Error when receiving block message! - EntityTooLarge\n"); } - output.printf("Total message size: %d\r\n", argument->total_message_size()); + printf("Total message size: %" PRIu32 "\n", argument->total_message_size()); } } void block_message_requested(const String& resource, uint8_t *&/*data*/, uint32_t &/*len*/) { - output.printf("GET request received for resource: %s\r\n", resource.c_str()); + printf("GET request received for resource: %s\n", resource.c_str()); // Copy data and length to coap response } @@ -346,11 +309,6 @@ updates.release(); } -// debug printf function -void trace_printer(const char* str) { - printf("%s\r\n", str); -} - // Entry point to the program int main() { @@ -378,51 +336,24 @@ srand(seed); red_led = 1; blue_led = 1; + status_ticker.attach_us(blinky, 250000); // Keep track of the main thread mainThread = osThreadGetId(); - // Sets the console baud-rate - output.baud(115200); - - output.printf("\r\nStarting mbed Client example in "); + printf("\nStarting mbed Client example in "); #if defined (MESH) || (MBED_CONF_LWIP_IPV6_ENABLED==true) - output.printf("IPv6 mode\r\n"); + printf("IPv6 mode\n"); #else - output.printf("IPv4 mode\r\n"); + printf("IPv4 mode\n"); #endif mbed_trace_init(); - mbed_trace_print_function_set(trace_printer); - NetworkInterface *network_interface = 0; - int connect_success = -1; -#if MBED_CONF_APP_NETWORK_INTERFACE == WIFI - output.printf("\n\rConnecting to WiFi...\r\n"); - connect_success = wifi.connect(MBED_CONF_APP_WIFI_SSID, MBED_CONF_APP_WIFI_PASSWORD, NSAPI_SECURITY_WPA_WPA2); - network_interface = &wifi; -#elif MBED_CONF_APP_NETWORK_INTERFACE == ETHERNET - output.printf("\n\rConnecting to ethernet...\r\n"); - connect_success = eth.connect(); - network_interface = ð -#endif -#ifdef MESH - output.printf("\n\rConnecting to Mesh...\r\n"); - mesh.initialize(&rf_phy); - connect_success = mesh.connect(); - network_interface = &mesh; -#endif - if(connect_success == 0) { - output.printf("\n\rConnected to Network successfully\r\n"); - } else { - output.printf("\n\rConnection to Network Failed %d! Exiting application....\r\n", connect_success); - return 0; - } - const char *ip_addr = network_interface->get_ip_address(); - if (ip_addr) { - output.printf("IP address %s\r\n", ip_addr); - } else { - output.printf("No IP address\r\n"); + NetworkInterface* network = easy_connect(true); + if(network == NULL) { + printf("\nConnection to Network Failed - exiting application...\n"); + return -1; } // we create our button and LED resources @@ -444,7 +375,7 @@ #endif // Create endpoint interface to manage register and unregister - mbed_client.create_interface(MBED_SERVER_ADDRESS, network_interface); + mbed_client.create_interface(MBED_SERVER_ADDRESS, network); // Create Objects of varying types, see simpleclient.h for more details on implementation. M2MSecurity* register_object = mbed_client.create_register_object(); // server object specifying connector info
--- a/mbed_app.json Thu Feb 02 08:30:11 2017 +0000 +++ b/mbed_app.json Wed Feb 15 08:00:11 2017 +0000 @@ -1,7 +1,7 @@ { "config": { "network-interface":{ - "help": "options are ETHERNET,WIFI,MESH_LOWPAN_ND,MESH_THREAD", + "help": "Options are ETHERNET, WIFI_ESP8266, WIFI_ODIN, MESH_LOWPAN_ND, MESH_THREAD", "value": "ETHERNET" }, "mesh_radio_type": { @@ -29,6 +29,8 @@ "target_overrides": { "*": { "target.features_add": ["NANOSTACK", "LOWPAN_ROUTER", "COMMON_PAL"], + "platform.stdio-baud-rate": 115200, + "platform.stdio-convert-newlines": true, "mbed-mesh-api.6lowpan-nd-channel-page": 0, "mbed-mesh-api.6lowpan-nd-channel": 12, "mbed-trace.enable": 0
--- a/mcr20a-rf-driver.lib Thu Feb 02 08:30:11 2017 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,1 +0,0 @@ -https://github.com/ARMmbed/mcr20a-rf-driver/#d8810e105d7d35315aa708ec51d821156cad45e9