You are viewing an older revision! See the latest version
Removed
Building an Mbed Application with IFTTT¶
This tutorial will guide you through creating an IFTTT application for the Mbed Connect Cloud board.
Prerequisites¶
- An Mbed account - sign up here
- Install the Mbed serial driver (for Windows PCs)'
- An IFTTT Maker account - sign up here
Required Hardware¶
- Mbed Connect Cloud board
- An active WiFi network
Setup¶
- Connect the board to your computer via the micro USB port.
- The board mounts as a mass-storage device (like a USB drive). Verify that you can see it (the drive name will be DAPLINK).
- Add the u-blox EVK-ODIN-W2 board to your online Mbed Compiler here
Making the Mbed application¶
Import the example program.
Import programIFTTT-Google-Sheets-Demo
Demo for Mbed Connect Cloud board and an IFTTT integration with Google Sheets
Setting up WiFi¶
We will add some code to initialize the Mbed Connect Cloud board's WiFi module and connect to your local WPA/WPA2 WiFi network.
Open mbed_app.json
We need to tell Mbed the name of our WiFi network's SSID and password. Under wifi-ssid
change the "value"
from SSID to your WiFi's name (for example: "\"iotlab\""
) and do not remove the quotes. Under wifi-password
change the "value"
from PASSWORD to your WiFi's password (for example: "\"abcd1234\""
) and do not remove the quotes.
Open main.cpp
The Mbed Connect Cloud board uses the u-blox EVK-ODIN-W2 WiFi module. So to initialize our WiFi connection we need to instantiate a OdinWifiInterface
variable. Under 'GLOBAL VARIABLES HERE' add the following code:
OdinWiFiInterface wifi;
Add some code to tell the WiFi module to connect to your wifi network. Under 'MAIN CODE HERE' add the following code:
wifi.connect(MBED_CONF_APP_WIFI_SSID, MBED_CONF_APP_WIFI_PASSWORD, NSAPI_SECURITY_WPA_WPA2);
The MBED_CONF_APP_WIFI_SSID
and MBED_CONF_APP_WIFI_PASSWORD
are variables defined by the mbed_app.json
file we edited previously. NSAPI_SECURITY_WPA_WPA2
tells Mbed OS that our WiFi network has WPA or WPA2 security (so it requires an SSID and password).
Printing to the screen & adding a button interrupt¶
We will add some code to instantiate an InterruptIn
variable so the SW1 button on the board can interrupt the main program. We will also create an int variable to store the number of times the button has been clicked, and a boolean variable that changes state (true/false) when the button has been clicked. We will also print the number of times the button has been clicked to the board's LCD screen.
Open main.cpp
Instantiate a C12832
variable to write to the LCD screen on the board. Under 'GLOBAL VARIABLES HERE' add the following code:
C12832 lcd(PE_14, PE_12, PD_12, PD_11, PE_9);
Create a function to print to the LCD screen. Under 'FUNCTION DEFINITIONS HERE' add the following code:
void lcd_print(const char* message) { lcd.cls(); lcd.locate(0, 3); lcd.printf(message); }
To keep track of the number of times the SW1 button has been pressed, we need an integer variable and a boolean variable. Under 'GLOBAL VARIABLES HERE' add the following code:
InterruptIn button(PF_2); volatile int count = 0; volatile bool clicked = false;
Add a function that will be called when the button interrupts the main function. When the button is clicked, the clicked
variable will be set to true
and the count
will be incremented by one. The number of clicks will also be printed to the LCD screen. Under 'FUNCTION DEFINITIONS HERE' add the following code:
void button_clicked() { clicked = true; count += 1; char val[32]; sprintf(val, "# of clicks = %d", count); lcd_print(val); }
Attach the button_clicked
function to the rising edge of the InterruptIn
button. Under 'MAIN CODE HERE' add the following code:
button.rise(&button_clicked);
Compile and run¶
- Select the u-blox EVK-ODIN-W2 target board in the upper right hand corner
- Press "Compile"
- Wait for a binary to be downloaded
- Drag the binary to the DAPLINK disk
- Press the board's reset button
- The number of button clicks should now show and update on the LCD screen.