LM61のセンサ値をAmbientにアップロードするプログラムです。

Dependencies:   mbed-http

Committer:
JKsoft_main
Date:
Mon Jan 14 11:44:47 2019 +0000
Revision:
1:d33e49e1e46d
Parent:
0:b3812b1c103d
f

Who changed what in which revision?

UserRevisionLine numberNew contents of line
JKsoft_main 0:b3812b1c103d 1 #include "mbed.h"
JKsoft_main 0:b3812b1c103d 2 #include "easy-connect.h"
JKsoft_main 0:b3812b1c103d 3 #include "https_request.h"
JKsoft_main 1:d33e49e1e46d 4 #include "Ambient.h"
JKsoft_main 0:b3812b1c103d 5
JKsoft_main 1:d33e49e1e46d 6 unsigned int channelId = 0;
JKsoft_main 1:d33e49e1e46d 7 const char* writeKey = "";
JKsoft_main 1:d33e49e1e46d 8 Ambient ambient;
JKsoft_main 0:b3812b1c103d 9
JKsoft_main 1:d33e49e1e46d 10 AnalogIn ain(A0);
JKsoft_main 0:b3812b1c103d 11 Serial pc(USBTX,USBRX);
JKsoft_main 0:b3812b1c103d 12
JKsoft_main 0:b3812b1c103d 13
JKsoft_main 0:b3812b1c103d 14 // main() runs in its own thread in the OS
JKsoft_main 0:b3812b1c103d 15 int main() {
JKsoft_main 0:b3812b1c103d 16 NetworkInterface* network = NULL;
JKsoft_main 0:b3812b1c103d 17
JKsoft_main 1:d33e49e1e46d 18 pc.baud(9600);
JKsoft_main 0:b3812b1c103d 19
JKsoft_main 1:d33e49e1e46d 20 pc.printf("Network Connect..");
JKsoft_main 0:b3812b1c103d 21
JKsoft_main 0:b3812b1c103d 22 pc.printf("\r\n----- Start -----\r\n");
JKsoft_main 0:b3812b1c103d 23
JKsoft_main 0:b3812b1c103d 24 network = easy_connect(true); // If true, prints out connection details.
JKsoft_main 0:b3812b1c103d 25 if (!network) {
JKsoft_main 0:b3812b1c103d 26 pc.printf("\r\n----- Network Error -----\r\n");
JKsoft_main 0:b3812b1c103d 27 return -1;
JKsoft_main 0:b3812b1c103d 28 }
JKsoft_main 0:b3812b1c103d 29
JKsoft_main 0:b3812b1c103d 30 pc.printf("\r\n----- Network Connected -----\r\n");
JKsoft_main 0:b3812b1c103d 31
JKsoft_main 0:b3812b1c103d 32 wait(2.0);
JKsoft_main 1:d33e49e1e46d 33
JKsoft_main 1:d33e49e1e46d 34 ambient.init(network,channelId, writeKey);
JKsoft_main 0:b3812b1c103d 35
JKsoft_main 0:b3812b1c103d 36 while(1) {
JKsoft_main 1:d33e49e1e46d 37 float tmp = (ain * 3.3 -0.6)/0.01;
JKsoft_main 1:d33e49e1e46d 38 ambient.set(1, tmp);
JKsoft_main 1:d33e49e1e46d 39
JKsoft_main 1:d33e49e1e46d 40 bool ret = ambient.send();
JKsoft_main 0:b3812b1c103d 41 pc.printf("\n----- HTTPS POST response [%s]----- \n\r",ret== true ? "OK" : "NG");
JKsoft_main 0:b3812b1c103d 42
JKsoft_main 0:b3812b1c103d 43 wait(10.0);
JKsoft_main 0:b3812b1c103d 44 }
JKsoft_main 0:b3812b1c103d 45 }
JKsoft_main 0:b3812b1c103d 46