This is a demo that upload temperature info. to dweet.io
Dependencies: BLE_API DHT HTTPClient SDFileSystem WIZnet_Library mbed nRF51822
Revision 3:cfc6ff08a668, committed 2015-07-02
- Comitter:
- Kevin_Lee
- Date:
- Thu Jul 02 10:05:43 2015 +0000
- Parent:
- 2:8b304d2b4ca5
- Commit message:
- This is a demo to upload temperature info. to dweet.io
Changed in this revision
DHT.lib | Show annotated file Show diff for this revision Revisions of this file |
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
diff -r 8b304d2b4ca5 -r cfc6ff08a668 DHT.lib --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/DHT.lib Thu Jul 02 10:05:43 2015 +0000 @@ -0,0 +1,1 @@ +http://developer.mbed.org/teams/components/code/DHT/#df22ddf10d75
diff -r 8b304d2b4ca5 -r cfc6ff08a668 main.cpp --- a/main.cpp Tue Jun 30 07:28:24 2015 +0000 +++ b/main.cpp Thu Jul 02 10:05:43 2015 +0000 @@ -3,11 +3,16 @@ #include "BLE.h" #include "WIZnetInterface.h" #include "HTTPClient.h" +#include "DHT.h" + +#define DHT22_Test 0 #define USE_DHCP 0 #define LOOPBACKPORT 5000 int W5500_Test(void); +float temperature_get(); /* Grove - Temperature Sensor V1.2 */ + SPI spi(SPI_PSELMOSI0, SPI_PSELMISO0, SPI_PSELSCK0); WIZnetInterface ethernet(&spi, p24, p17); // Spi ,cs, reset int ret, dummy, lv = 1; @@ -22,6 +27,10 @@ Serial pc(USBTX, USBRX); /* uart */ +DHT dht22(A1,DHT22); + +AnalogIn ain(A0); + int main() { char buffer[256]; wait(1); @@ -29,63 +38,58 @@ wait(1); printf("helloworld\r\n"); + /* + float resistance = (float)(1023.0-val)*10000.0/(float)val; + float temp = 1/(log(resistance/10000)/B+1/298.15)-273.15; + */ + +#if DHT22_Test + int result; + while(1) { + printf("dht22.readData()\r\n"); + printf("ain A0: %.2f\r\n",ain.read()); + printf("temperature_get %.2f\r\n",temperature_get()); + result = dht22.readData(); + printf("the result is %d.\r\n",result); + if(result == 0) { + printf("Temperature is %f.2 C\r\n",dht22.ReadTemperature(CELCIUS)); + printf("Humidity is %f.2 \%\r\n",dht22.ReadHumidity()); + } + wait(4); + } +#endif + + if(W5500_Test() == 0) { // Internet is ok printf("W5500 tested OK \r\n"); - char str[512]; - char get_msg[128]= ""; + char str[512]; + char get_msg[128]= ""; /* - http://dweet.io/follow/nameYouWant + http://dweet.io/follow/ArchLink */ - char nameYouWant[] = "nameYouWant"; - while(1) - { -// sprintf(get_msg,"http://dweet.io/dweet/for/%s?a0=%d",nameYouWant,(int)(1000)); - - sprintf(get_msg,"http://seeedmsvps.cloudapp.net:10080/plantbox/upload_iot/"); - HTTPClient http; - - pc.printf("Send post message to dweet.io\r\n"); - pc.printf("msg : %s\r\n",get_msg); - ret = http.get(get_msg, str, sizeof(str)); - if(!ret) - { - pc.printf("\r\nPage fetched successfully - read %d characters\r\n", strlen(str)); - pc.printf("Result: %s\r\n", str); - } - else + char nameYouWant[] = "ArchLink"; + while(1) { - pc.printf("Error - ret = %d - HTTP return code = %d\n", ret, http.getHTTPResponseCode()); - } - wait(10); - } - + sprintf(get_msg,"http://dweet.io/dweet/for/%s?Temperature=%.2f",nameYouWant,temperature_get()); + printf("temperature_get: %.2f",temperature_get()); + HTTPClient http; - // TCPSocketServer server; - // server.bind(LOOPBACKPORT); - // server.listen(); - // while(1) { - // printf("\nWait for new connection...\r\n"); - // TCPSocketConnection client; - // server.accept(client); - // client.set_blocking(false,0); // Timeout = 0. - // printf("Connection from: %s\r\n",client.get_address()); - // while (client.is_connected() == true) { - // int n = client.receive(buffer,sizeof(buffer)); - // if (n > 0) { - // client.send_all(buffer,n); - // } else { - // } - // if (client.is_fin_received()) { - // client.close(); - // } else { - // } - - // } - // printf("Disconnected.\r\n"); - - // } + pc.printf("Send post message to dweet.io\r\n"); + pc.printf("msg : %s\r\n",get_msg); + ret = http.get(get_msg, str, sizeof(str)); + if(!ret) + { + pc.printf("\r\nPage fetched successfully - read %d characters\r\n", strlen(str)); + pc.printf("Result: %s\r\n", str); + } + else + { + pc.printf("Error - ret = %d - HTTP return code = %d\n", ret, http.getHTTPResponseCode()); + } + wait(10); + } } while(1) { @@ -149,4 +153,15 @@ } pc.printf("Disconnected.\r\n"); }*/ -} \ No newline at end of file +} + + +float temperature_get() +{ + int B = 3975; + float val = (ain.read()*1023); + float resistance = (float)(1023.0-val)*10000.0/(float)val; + float temp = 1/(log(resistance/10000)/B+1/298.15)-273.15; + return temp; +} +