Demo for Mbed Connect Cloud board and an IFTTT integration with Google Sheets

Dependencies:   mbed-http C12832

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main_working.h Source File

main_working.h

00001 //----------------------------------------------------------------------------
00002 // The confidential and proprietary information contained in this file may
00003 // only be used by a person authorised under and to the extent permitted
00004 // by a subsisting licensing agreement from ARM Limited or its affiliates.
00005 //
00006 // (C) COPYRIGHT 2016 ARM Limited or its affiliates.
00007 // ALL RIGHTS RESERVED
00008 //
00009 // This entire notice must be reproduced on all copies of this file
00010 // and copies of this file may only be made by a person if such person is
00011 // permitted to do so under the terms of a subsisting license agreement
00012 // from ARM Limited or its affiliates.
00013 //----------------------------------------------------------------------------
00014 #include "mbed.h"
00015 #include "C12832.h"
00016 #include "OdinWiFiInterface.h"
00017 #include "http_request.h"
00018 
00019 // GLOBAL VARIABLES HERE
00020 
00021 C12832  lcd(PE_14, PE_12, PD_12, PD_11, PE_9);
00022 OdinWiFiInterface wifi;
00023 InterruptIn button(PF_2);
00024 volatile int count = 0;
00025 volatile bool clicked = false;
00026 
00027 // FUNCTION DEFINTIONS HERE
00028 
00029 void lcd_print(const char* message) {
00030     lcd.cls();
00031     lcd.locate(0, 3);
00032     lcd.printf(message);
00033 }
00034 
00035 void button_clicked() {
00036     clicked = true;
00037     count += 1;
00038     char val[32];
00039     sprintf(val, "# of clicks = %d", count);
00040     lcd_print(val);
00041 }
00042 
00043 int main() {
00044 
00045     // MAIN CODE HERE
00046 
00047     lcd_print("Connecting...");
00048     int ret = wifi.connect(MBED_CONF_APP_WIFI_SSID, MBED_CONF_APP_WIFI_PASSWORD, NSAPI_SECURITY_WPA_WPA2);
00049     if (ret != 0) {
00050         lcd_print("Connection error.");
00051         return -1;
00052     }
00053     lcd_print("Successfully connected!");
00054 
00055     button.rise(&button_clicked);
00056 
00057     while (true) {
00058         // WHILE LOOP CODE HERE
00059 
00060         if (clicked) {
00061             clicked = false;
00062             char body[140];
00063             char event_name[] = "Button Clicked";
00064             NetworkInterface* net = &wifi;
00065             HttpRequest* request = new HttpRequest(net, HTTP_POST, "http://maker.ifttt.com/trigger/mbed_connect/with/key/SECRET_KEY_HERE");
00066             request->set_header("Content-Type", "application/json");
00067             sprintf(body, "{\"value1\":\"%s\", \"value2\":\"%d\"}", event_name, count);
00068             HttpResponse* response = request->send(body, strlen(body));
00069             delete request;
00070         }
00071     }
00072 
00073 }