This example sends temperature and humidity data to Ambient through ethernet. (Japanese: IoT用のクラウドサービス「Ambient」にLPC1768とイーサーネットを使ってデーターを送信するサンプルです。Ambientはマイコンから送られたセンサーデーターを受信し、蓄積し、可視化(グラフ化)します。 https://ambidata.io)

Dependencies:   AmbientLib EthernetInterface HDC1000 mbed-rtos mbed

Committer:
AmbientData
Date:
Sat May 07 01:42:05 2016 +0000
Revision:
0:8ff3c1a54f88
Child:
1:9aa62bdb3b84
Initial submission

Who changed what in which revision?

UserRevisionLine numberNew contents of line
AmbientData 0:8ff3c1a54f88 1 #include "mbed.h"
AmbientData 0:8ff3c1a54f88 2 #include "EthernetInterface.h"
AmbientData 0:8ff3c1a54f88 3 #include "Ambient.h"
AmbientData 0:8ff3c1a54f88 4 #include "HDC1000.h"
AmbientData 0:8ff3c1a54f88 5
AmbientData 0:8ff3c1a54f88 6 unsigned int channelId = 100;
AmbientData 0:8ff3c1a54f88 7 const char* writeKey = "ライトキー";
AmbientData 0:8ff3c1a54f88 8 AMBIENT ambient;
AmbientData 0:8ff3c1a54f88 9
AmbientData 0:8ff3c1a54f88 10 HDC1000 hdc1000(p9,p10);
AmbientData 0:8ff3c1a54f88 11
AmbientData 0:8ff3c1a54f88 12 int main() {
AmbientData 0:8ff3c1a54f88 13 printf("start\r\n");
AmbientData 0:8ff3c1a54f88 14
AmbientData 0:8ff3c1a54f88 15 EthernetInterface eth;
AmbientData 0:8ff3c1a54f88 16 eth.init();
AmbientData 0:8ff3c1a54f88 17 eth.connect();
AmbientData 0:8ff3c1a54f88 18
AmbientData 0:8ff3c1a54f88 19 TCPSocketConnection socket;
AmbientData 0:8ff3c1a54f88 20 ambient.init(channelId, writeKey, &socket);
AmbientData 0:8ff3c1a54f88 21
AmbientData 0:8ff3c1a54f88 22 printf("\n\rClient IP Address is %s\n\r", eth.getIPAddress());
AmbientData 0:8ff3c1a54f88 23 printf("Ambient send to ch: %d\r\n", channelId);
AmbientData 0:8ff3c1a54f88 24
AmbientData 0:8ff3c1a54f88 25 while (true) {
AmbientData 0:8ff3c1a54f88 26 float temp, humid;
AmbientData 0:8ff3c1a54f88 27 char tempbuf[12], humidbuf[12];
AmbientData 0:8ff3c1a54f88 28
AmbientData 0:8ff3c1a54f88 29 hdc1000.get();
AmbientData 0:8ff3c1a54f88 30 temp = hdc1000.temperature();
AmbientData 0:8ff3c1a54f88 31 humid = hdc1000.humidity();
AmbientData 0:8ff3c1a54f88 32
AmbientData 0:8ff3c1a54f88 33 sprintf(tempbuf, "%2.1f", temp);
AmbientData 0:8ff3c1a54f88 34 ambient.set(1, tempbuf);
AmbientData 0:8ff3c1a54f88 35 sprintf(humidbuf, "%2.0f", humid);
AmbientData 0:8ff3c1a54f88 36 ambient.set(2, humidbuf);
AmbientData 0:8ff3c1a54f88 37 printf("Temp: %s C, Humid: %s %%\r\n", tempbuf, humidbuf);
AmbientData 0:8ff3c1a54f88 38
AmbientData 0:8ff3c1a54f88 39 ambient.send();
AmbientData 0:8ff3c1a54f88 40
AmbientData 0:8ff3c1a54f88 41 wait(30.0);
AmbientData 0:8ff3c1a54f88 42 }
AmbientData 0:8ff3c1a54f88 43 }