hellomqttt to thingspeak mqtt and ifttt

Dependencies:   Servo MQTTPacket FP

Committer:
jasonberry
Date:
Wed May 05 14:48:01 2021 +0000
Revision:
25:ca1b1098c77f
TEST

Who changed what in which revision?

UserRevisionLine numberNew contents of line
jasonberry 25:ca1b1098c77f 1 # Easy Connect - Easily add all supported connectivity methods to your mbed OS project
jasonberry 25:ca1b1098c77f 2
jasonberry 25:ca1b1098c77f 3 Often you want to give users of your application the choice to switch between connectivity methods. The `NetworkInterface` API makes this easy, but you'll still need a mechanism for the user to chooce the method, throw in some `#define`'s, etc. Easy Connect handles all this for you. Just declare the desired connectivity method in your `mbed_app.json` file, and call `easy_connect()` from your application.
jasonberry 25:ca1b1098c77f 4
jasonberry 25:ca1b1098c77f 5 ## Specifying connectivity method
jasonberry 25:ca1b1098c77f 6
jasonberry 25:ca1b1098c77f 7 Add the following to your ``mbed_app.json`` file:
jasonberry 25:ca1b1098c77f 8
jasonberry 25:ca1b1098c77f 9 ```json
jasonberry 25:ca1b1098c77f 10 {
jasonberry 25:ca1b1098c77f 11 "config": {
jasonberry 25:ca1b1098c77f 12 "network-interface":{
jasonberry 25:ca1b1098c77f 13 "help": "options are ETHERNET,WIFI_ESP8266,MESH_LOWPAN_ND,MESH_THREAD",
jasonberry 25:ca1b1098c77f 14 "value": "ETHERNET"
jasonberry 25:ca1b1098c77f 15 }
jasonberry 25:ca1b1098c77f 16 },
jasonberry 25:ca1b1098c77f 17 "target_overrides": {
jasonberry 25:ca1b1098c77f 18 "*": {
jasonberry 25:ca1b1098c77f 19 "target.features_add": ["NANOSTACK", "LOWPAN_ROUTER", "COMMON_PAL"],
jasonberry 25:ca1b1098c77f 20 "mbed-mesh-api.6lowpan-nd-channel-page": 0,
jasonberry 25:ca1b1098c77f 21 "mbed-mesh-api.6lowpan-nd-channel": 12
jasonberry 25:ca1b1098c77f 22 }
jasonberry 25:ca1b1098c77f 23 }
jasonberry 25:ca1b1098c77f 24 }
jasonberry 25:ca1b1098c77f 25 ```
jasonberry 25:ca1b1098c77f 26
jasonberry 25:ca1b1098c77f 27 If you choose `WIFI_ESP8266`, you'll also need to add the WiFi SSID and password:
jasonberry 25:ca1b1098c77f 28
jasonberry 25:ca1b1098c77f 29 ```json
jasonberry 25:ca1b1098c77f 30 "config": {
jasonberry 25:ca1b1098c77f 31 "network-interface":{
jasonberry 25:ca1b1098c77f 32 "help": "options are ETHERNET,WIFI_ESP8266,MESH_LOWPAN_ND,MESH_THREAD",
jasonberry 25:ca1b1098c77f 33 "value": "WIFI_ESP8266"
jasonberry 25:ca1b1098c77f 34 },
jasonberry 25:ca1b1098c77f 35 "esp8266-tx": {
jasonberry 25:ca1b1098c77f 36 "help": "Pin used as TX (connects to ESP8266 RX)",
jasonberry 25:ca1b1098c77f 37 "value": "PTD3"
jasonberry 25:ca1b1098c77f 38 },
jasonberry 25:ca1b1098c77f 39 "esp8266-rx": {
jasonberry 25:ca1b1098c77f 40 "help": "Pin used as RX (connects to ESP8266 TX)",
jasonberry 25:ca1b1098c77f 41 "value": "PTD2"
jasonberry 25:ca1b1098c77f 42 },
jasonberry 25:ca1b1098c77f 43 "esp8266-ssid": {
jasonberry 25:ca1b1098c77f 44 "value": "\"SSID\""
jasonberry 25:ca1b1098c77f 45 },
jasonberry 25:ca1b1098c77f 46 "esp8266-password": {
jasonberry 25:ca1b1098c77f 47 "value": "\"Password\""
jasonberry 25:ca1b1098c77f 48 },
jasonberry 25:ca1b1098c77f 49 "esp8266-debug": {
jasonberry 25:ca1b1098c77f 50 "value": true
jasonberry 25:ca1b1098c77f 51 }
jasonberry 25:ca1b1098c77f 52 }
jasonberry 25:ca1b1098c77f 53 ```
jasonberry 25:ca1b1098c77f 54
jasonberry 25:ca1b1098c77f 55 If you use `MESH_LOWPAN_ND` or `MESH_THREAD` you will need to specify your radio module:
jasonberry 25:ca1b1098c77f 56
jasonberry 25:ca1b1098c77f 57 ```json
jasonberry 25:ca1b1098c77f 58 "config": {
jasonberry 25:ca1b1098c77f 59 "network-interface":{
jasonberry 25:ca1b1098c77f 60 "help": "options are ETHERNET,WIFI_ESP8266,MESH_LOWPAN_ND,MESH_THREAD",
jasonberry 25:ca1b1098c77f 61 "value": "MESH_LOWPAN_ND"
jasonberry 25:ca1b1098c77f 62 },
jasonberry 25:ca1b1098c77f 63 "mesh_radio_type": {
jasonberry 25:ca1b1098c77f 64 "help": "options are ATMEL, MCR20",
jasonberry 25:ca1b1098c77f 65 "value": "ATMEL"
jasonberry 25:ca1b1098c77f 66 }
jasonberry 25:ca1b1098c77f 67 }
jasonberry 25:ca1b1098c77f 68 ```
jasonberry 25:ca1b1098c77f 69
jasonberry 25:ca1b1098c77f 70 ## Using Easy Connect from your application
jasonberry 25:ca1b1098c77f 71
jasonberry 25:ca1b1098c77f 72 Easy Connect has just one function which will either return a `NetworkInterface`-pointer or `NULL`:
jasonberry 25:ca1b1098c77f 73
jasonberry 25:ca1b1098c77f 74 ```cpp
jasonberry 25:ca1b1098c77f 75 #include "easy-connect.h"
jasonberry 25:ca1b1098c77f 76
jasonberry 25:ca1b1098c77f 77 int main(int, char**) {
jasonberry 25:ca1b1098c77f 78 NetworkInterface* network = easy_connect(true); /* has 1 argument, enable_logging (pass in true to log to serial port) */
jasonberry 25:ca1b1098c77f 79 if (!network) {
jasonberry 25:ca1b1098c77f 80 printf("Connecting to the network failed... See serial output.\r\n");
jasonberry 25:ca1b1098c77f 81 return 1;
jasonberry 25:ca1b1098c77f 82 }
jasonberry 25:ca1b1098c77f 83
jasonberry 25:ca1b1098c77f 84 // Rest of your program
jasonberry 25:ca1b1098c77f 85 }
jasonberry 25:ca1b1098c77f 86 ```
jasonberry 25:ca1b1098c77f 87
jasonberry 25:ca1b1098c77f 88 ## Extra defines
jasonberry 25:ca1b1098c77f 89
jasonberry 25:ca1b1098c77f 90 If you'd like to use Easy Connect with mbed Client then you're in luck. Easy Connect automatically defines the `MBED_SERVER_ADDRESS` macro depending on your connectivity method (either IPv4 or IPv6 address). Use this address to connect to the right instance of mbed Device Connector.