Simple IoT BoardからIoT用のクラウドサービス「Ambient」にデーターを送信するサンプルです。 https://ambidata.io
Dependencies: AmbientLib SimpleIoTBoardLib mbed
Diff: main.cpp
- Revision:
- 0:c08564b2cf0e
- Child:
- 1:07639e90e2e8
diff -r 000000000000 -r c08564b2cf0e main.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Sat May 07 02:27:04 2016 +0000 @@ -0,0 +1,52 @@ +#include "mbed.h" +#include "math.h" +#include "ESP8266Interface.h" +#include "TCPSocketConnection.h" +#include "SoftSerialSendOnry.h" + +#include "Ambient.h" + +ESP8266Interface wifi(dp16,dp15,dp4,"SSID","Password",115200); // TX,RX,Reset,SSID,Password,Baud + +unsigned int channelId = 100; +const char* writeKey = "ライトキー"; +AMBIENT ambient; + +AnalogIn thermistor(dp13); +const int B=4275; // B value of the thermistor + +SoftSerialSendOnry pc(dp10); + +int main() +{ + TCPSocketConnection socket; + + pc.baud(9600); + + wifi.init(); //Reset + wifi.connect(); //Use DHCP + pc.printf("IP Address is %s\r\n", wifi.getIPAddress()); + + ambient.init(channelId, writeKey, &socket); + + while (true) { + float temp; + char tempbuf[12]; + int a = thermistor.read_u16(); + + float R = 65535.0/((float)a)-1.0; + R = 100000.0*R; + + //convert to temperature via datasheet ; + temp = 1.0/(log(R/100000.0)/B+1/298.15)-273.15; + + pc.printf("%4.2f\r\n", temp); + + sprintf(tempbuf, "%2.1f", temp); + ambient.set(1, tempbuf); + + ambient.send(); + + wait(30.0); + } +}