Takehiko Shimojima / Mbed 2 deprecated AmbientExampleSITB

Dependencies:   AmbientLib SimpleIoTBoardLib mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 #include "mbed.h"
00002 #include "math.h"
00003 #include "ESP8266Interface.h"
00004 #include "TCPSocketConnection.h"
00005 #include "SoftSerialSendOnry.h"
00006 
00007 #include "Ambient.h"
00008 
00009 ESP8266Interface wifi(dp16,dp15,dp4,"SSID","Password",115200); // TX,RX,Reset,SSID,Password,Baud
00010 
00011 unsigned int channelId = 100;
00012 const char* writeKey = "ライトキー";
00013 Ambient ambient;
00014 
00015 AnalogIn thermistor(dp13);
00016 const int B=4275; // B value of the thermistor
00017 
00018 SoftSerialSendOnry pc(dp10);
00019 
00020 int main()
00021 {
00022     TCPSocketConnection socket;
00023 
00024     pc.baud(9600);
00025 
00026     wifi.init(); //Reset
00027     wifi.connect(); //Use DHCP
00028     pc.printf("IP Address is %s\r\n", wifi.getIPAddress());
00029 
00030     ambient.init(channelId, writeKey, &socket);
00031 
00032     while (true) {
00033         float temp;
00034         char tempbuf[12];
00035         int a = thermistor.read_u16();
00036         
00037         float R = 65535.0/((float)a)-1.0;
00038         R = 100000.0*R;
00039 
00040         //convert to temperature via datasheet ;
00041         temp = 1.0/(log(R/100000.0)/B+1/298.15)-273.15;
00042         
00043         pc.printf("%4.2f\r\n", temp);
00044 
00045         sprintf(tempbuf, "%2.1f", temp);
00046         ambient.set(1, tempbuf);
00047 
00048         ambient.send();
00049 
00050         wait(30.0);
00051     }
00052 }