Takehiko Shimojima / Mbed 2 deprecated AmbientExampleLPC1768

Dependencies:   AmbientLib EthernetInterface HDC1000 mbed-rtos mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 #include "mbed.h"
00002 #include "EthernetInterface.h"
00003 #include "Ambient.h"
00004 #include "HDC1000.h"
00005 
00006 unsigned int channelId = 517;
00007 const char* writeKey = "0f63cc33c424afd0";
00008 Ambient ambient;
00009 
00010 HDC1000      hdc1000(p9,p10);
00011 
00012 int main() {
00013     printf("start\r\n");
00014 
00015     EthernetInterface eth;
00016     eth.init();
00017     eth.connect();
00018 
00019     TCPSocketConnection socket;
00020     ambient.init(channelId, writeKey, &socket);
00021 
00022     printf("\n\rClient IP Address is %s\n\r", eth.getIPAddress());
00023     printf("Ambient send to ch: %d\r\n", channelId);
00024 
00025     while (true) {
00026         float temp, humid;
00027         char humidbuf[12];
00028 
00029         hdc1000.get();
00030         temp = hdc1000.temperature();
00031         humid = hdc1000.humidity();
00032 
00033         printf("temp= %2.0f, humid= %2.0f\r\n", temp, humid);
00034 
00035         ambient.set(1, temp);
00036         snprintf(humidbuf, sizeof(humidbuf), "%2.0f", humid);
00037         ambient.set(2, humidbuf);
00038 
00039         ambient.send();
00040         
00041         wait(300.0);
00042     }
00043 }