Simpe IoT BoardにGrove温度センサを繋げてIFTTTにプッシュするプログラムです。

Dependencies:   mbed

Committer:
jksoft
Date:
Sat Nov 14 02:53:45 2015 +0000
Revision:
1:8a97f4bd9773
Parent:
0:26b07836cf44
IFTTT????????

Who changed what in which revision?

UserRevisionLine numberNew contents of line
jksoft 0:26b07836cf44 1 #include "mbed.h"
jksoft 0:26b07836cf44 2 #include "ESP8266Interface.h"
jksoft 0:26b07836cf44 3 #include "TCPSocketConnection.h"
jksoft 0:26b07836cf44 4 #include "ifttt.h"
jksoft 0:26b07836cf44 5 #include "SoftSerialSendOnry.h"
jksoft 0:26b07836cf44 6
jksoft 0:26b07836cf44 7 AnalogIn thermistor(dp13); /* Temperature sensor connected to Analog Grove connector */
jksoft 0:26b07836cf44 8
jksoft 0:26b07836cf44 9 ESP8266Interface wifi(dp16,dp15,dp4,"SSID","Password",115200); // TX,RX,Reset,SSID,Password,Baud
jksoft 0:26b07836cf44 10
jksoft 0:26b07836cf44 11 SoftSerialSendOnry pc(dp10); // tx
jksoft 0:26b07836cf44 12
jksoft 0:26b07836cf44 13 float getTemperature()
jksoft 0:26b07836cf44 14 {
jksoft 0:26b07836cf44 15 unsigned int a, beta = 3975;
jksoft 0:26b07836cf44 16 float temperature, resistance;
jksoft 0:26b07836cf44 17
jksoft 0:26b07836cf44 18 a = thermistor.read_u16(); /* Read analog value */
jksoft 0:26b07836cf44 19
jksoft 0:26b07836cf44 20 /* Calculate the resistance of the thermistor from analog votage read. */
jksoft 0:26b07836cf44 21 resistance= (float) 10000.0 * ((65536.0 / a) - 1.0);
jksoft 0:26b07836cf44 22
jksoft 0:26b07836cf44 23 /* Convert the resistance to temperature using Steinhart's Hart equation */
jksoft 0:26b07836cf44 24 temperature=(1/((log(resistance/10000.0)/beta) + (1.0/298.15)))-273.15;
jksoft 0:26b07836cf44 25
jksoft 0:26b07836cf44 26 return(temperature);
jksoft 0:26b07836cf44 27 }
jksoft 0:26b07836cf44 28
jksoft 0:26b07836cf44 29 int main()
jksoft 0:26b07836cf44 30 {
jksoft 0:26b07836cf44 31 pc.baud(9600);
jksoft 0:26b07836cf44 32 wifi.init(); //Reset
jksoft 0:26b07836cf44 33 wifi.connect(); //Use DHCP
jksoft 0:26b07836cf44 34 pc.printf("IP Address is %s \n\r", wifi.getIPAddress());
jksoft 0:26b07836cf44 35 TCPSocketConnection socket;
jksoft 0:26b07836cf44 36
jksoft 0:26b07836cf44 37 // Initialize ifttt object, add up to 3 optional values, trigger event.
jksoft 0:26b07836cf44 38 IFTTT ifttt("EventName","Secret Key", &socket); // EventName, Secret Key, socket to use
jksoft 0:26b07836cf44 39
jksoft 0:26b07836cf44 40 char tmp[64];
jksoft 0:26b07836cf44 41
jksoft 0:26b07836cf44 42 sprintf(tmp,"%f",getTemperature());
jksoft 0:26b07836cf44 43
jksoft 0:26b07836cf44 44 ifttt.addIngredients(tmp,"value2","value3");
jksoft 0:26b07836cf44 45 ifttt.trigger(IFTTT_POST);
jksoft 0:26b07836cf44 46 }