Simpe IoT BoardにGrove温度センサを繋げてIFTTTにプッシュするプログラムです。
Dependencies: ESP8266Interface IFTTT mbed
Fork of SimpleIoTBoard_sample by
main.cpp@5:2039ddc6f807, 2015-11-12 (annotated)
- Committer:
- jksoft
- Date:
- Thu Nov 12 16:22:27 2015 +0000
- Revision:
- 5:2039ddc6f807
- Parent:
- 4:3994cd534bd5
??
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| mbedAustin | 0:0f0676c43e4b | 1 | #include "mbed.h" |
| mbedAustin | 1:15dd4d0a3af0 | 2 | #include "ESP8266Interface.h" |
| mbedAustin | 1:15dd4d0a3af0 | 3 | #include "TCPSocketConnection.h" |
| mbedAustin | 1:15dd4d0a3af0 | 4 | #include "ifttt.h" |
| jksoft | 4:3994cd534bd5 | 5 | #include "SoftSerialSendOnry.h" |
| mbedAustin | 1:15dd4d0a3af0 | 6 | |
| jksoft | 5:2039ddc6f807 | 7 | AnalogIn thermistor(dp13); /* Temperature sensor connected to Analog Grove connector */ |
| jksoft | 5:2039ddc6f807 | 8 | |
| jksoft | 4:3994cd534bd5 | 9 | ESP8266Interface wifi(dp16,dp15,dp4,"SSID","Password",115200); // TX,RX,Reset,SSID,Password,Baud |
| jksoft | 5:2039ddc6f807 | 10 | |
| jksoft | 4:3994cd534bd5 | 11 | SoftSerialSendOnry pc(dp10); // tx |
| mbedAustin | 0:0f0676c43e4b | 12 | |
| jksoft | 5:2039ddc6f807 | 13 | float getTemperature() |
| jksoft | 5:2039ddc6f807 | 14 | { |
| jksoft | 5:2039ddc6f807 | 15 | unsigned int a, beta = 3975; |
| jksoft | 5:2039ddc6f807 | 16 | float temperature, resistance; |
| jksoft | 5:2039ddc6f807 | 17 | |
| jksoft | 5:2039ddc6f807 | 18 | a = thermistor.read_u16(); /* Read analog value */ |
| jksoft | 5:2039ddc6f807 | 19 | |
| jksoft | 5:2039ddc6f807 | 20 | /* Calculate the resistance of the thermistor from analog votage read. */ |
| jksoft | 5:2039ddc6f807 | 21 | resistance= (float) 10000.0 * ((65536.0 / a) - 1.0); |
| jksoft | 5:2039ddc6f807 | 22 | |
| jksoft | 5:2039ddc6f807 | 23 | /* Convert the resistance to temperature using Steinhart's Hart equation */ |
| jksoft | 5:2039ddc6f807 | 24 | temperature=(1/((log(resistance/10000.0)/beta) + (1.0/298.15)))-273.15; |
| jksoft | 5:2039ddc6f807 | 25 | |
| jksoft | 5:2039ddc6f807 | 26 | return(temperature); |
| jksoft | 5:2039ddc6f807 | 27 | } |
| jksoft | 5:2039ddc6f807 | 28 | |
| mbedAustin | 1:15dd4d0a3af0 | 29 | int main() |
| mbedAustin | 0:0f0676c43e4b | 30 | { |
| mbedAustin | 1:15dd4d0a3af0 | 31 | pc.baud(9600); |
| mbedAustin | 1:15dd4d0a3af0 | 32 | wifi.init(); //Reset |
| mbedAustin | 1:15dd4d0a3af0 | 33 | wifi.connect(); //Use DHCP |
| jksoft | 4:3994cd534bd5 | 34 | pc.printf("IP Address is %s \n\r", wifi.getIPAddress()); |
| mbedAustin | 1:15dd4d0a3af0 | 35 | TCPSocketConnection socket; |
| mbedAustin | 0:0f0676c43e4b | 36 | |
| mbedAustin | 1:15dd4d0a3af0 | 37 | // Initialize ifttt object, add up to 3 optional values, trigger event. |
| jksoft | 4:3994cd534bd5 | 38 | IFTTT ifttt("EventName","Secret Key", &socket); // EventName, Secret Key, socket to use |
| jksoft | 5:2039ddc6f807 | 39 | |
| jksoft | 5:2039ddc6f807 | 40 | char tmp[64]; |
| jksoft | 4:3994cd534bd5 | 41 | |
| jksoft | 5:2039ddc6f807 | 42 | sprintf(tmp,"%f",getTemperature()); |
| jksoft | 5:2039ddc6f807 | 43 | |
| jksoft | 5:2039ddc6f807 | 44 | ifttt.addIngredients(tmp,"value2","value3"); |
| mbedAustin | 1:15dd4d0a3af0 | 45 | ifttt.trigger(IFTTT_POST); |
| mbedAustin | 0:0f0676c43e4b | 46 | } |
