ワークショップ用のサンプルプログラムです。

Dependencies:   DHT mbed

Committer:
jksoft
Date:
Fri Apr 29 21:07:24 2016 +0000
Revision:
0:a967c8649563
??

Who changed what in which revision?

UserRevisionLine numberNew contents of line
jksoft 0:a967c8649563 1 #include "mbed.h"
jksoft 0:a967c8649563 2 #include "ESP8266Interface.h"
jksoft 0:a967c8649563 3 #include "TCPSocketConnection.h"
jksoft 0:a967c8649563 4 #include "ifttt.h"
jksoft 0:a967c8649563 5 #include "SoftSerialSendOnry.h"
jksoft 0:a967c8649563 6 #include "DHT.h"
jksoft 0:a967c8649563 7
jksoft 0:a967c8649563 8 DHT sensor(dp13, DHT11);
jksoft 0:a967c8649563 9
jksoft 0:a967c8649563 10 ESP8266Interface wifi(dp16,dp15,dp4,"SSID","Password",115200); // TX,RX,Reset,SSID,Password,Baud
jksoft 0:a967c8649563 11
jksoft 0:a967c8649563 12 SoftSerialSendOnry pc(dp10); // tx
jksoft 0:a967c8649563 13
jksoft 0:a967c8649563 14 int main()
jksoft 0:a967c8649563 15 {
jksoft 0:a967c8649563 16 int error = 0;
jksoft 0:a967c8649563 17 float h = 0.0f, c = 0.0f;
jksoft 0:a967c8649563 18
jksoft 0:a967c8649563 19 pc.baud(9600);
jksoft 0:a967c8649563 20 wifi.init(); //Reset
jksoft 0:a967c8649563 21 wifi.connect(); //Use DHCP
jksoft 0:a967c8649563 22 pc.printf("IP Address is %s \n\r", wifi.getIPAddress());
jksoft 0:a967c8649563 23 TCPSocketConnection socket;
jksoft 0:a967c8649563 24
jksoft 0:a967c8649563 25 error = sensor.readData();
jksoft 0:a967c8649563 26 if (0 == error) {
jksoft 0:a967c8649563 27
jksoft 0:a967c8649563 28 c = sensor.ReadTemperature(CELCIUS);
jksoft 0:a967c8649563 29 h = sensor.ReadHumidity();
jksoft 0:a967c8649563 30
jksoft 0:a967c8649563 31 // Initialize ifttt object, add up to 3 optional values, trigger event.
jksoft 0:a967c8649563 32 IFTTT ifttt("EventName","Secret Key", &socket); // EventName, Secret Key, socket to use
jksoft 0:a967c8649563 33
jksoft 0:a967c8649563 34 char tmp1[16],tmp2[16];
jksoft 0:a967c8649563 35
jksoft 0:a967c8649563 36 sprintf(tmp1,"%4.2f",c);
jksoft 0:a967c8649563 37 sprintf(tmp2,"%4.2f",h);
jksoft 0:a967c8649563 38
jksoft 0:a967c8649563 39 ifttt.addIngredients(tmp1,tmp2,"value3");
jksoft 0:a967c8649563 40 ifttt.trigger(IFTTT_POST);
jksoft 0:a967c8649563 41
jksoft 0:a967c8649563 42 } else {
jksoft 0:a967c8649563 43 pc.printf("Error: %d\n", error);
jksoft 0:a967c8649563 44 }
jksoft 0:a967c8649563 45 }