This sample code is to upload temperature and air pressure data to your Fastsensing account. It uses SCP1000 to measure temp and pressure. 解説記事はこちら(https://qiita.com/AkiraKashihara/items/fd21fa4fd85aa9f723aa)

Dependencies:   EthernetInterface Fastsensing HTTPClient SCP1000 mbed-rtos mbed

Committer:
AkiraK
Date:
Tue Apr 04 14:07:19 2017 +0000
Revision:
0:4b1269eccf13
Child:
1:507f14e0c252
This sample code is to upload temperature and air pressure data to fastsensing.; This code uses SCP1000 which measure temperature and air pressure.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
AkiraK 0:4b1269eccf13 1 #include "mbed.h"
AkiraK 0:4b1269eccf13 2 #include "SCP1000.h"
AkiraK 0:4b1269eccf13 3 #include "Fastsensing.h"
AkiraK 0:4b1269eccf13 4
AkiraK 0:4b1269eccf13 5 DigitalOut myled(LED1);
AkiraK 0:4b1269eccf13 6 DigitalIn button(p21);
AkiraK 0:4b1269eccf13 7 Serial pc(USBTX, USBRX);
AkiraK 0:4b1269eccf13 8 Fastsensing fast;
AkiraK 0:4b1269eccf13 9 SCP1000 scp1000(p5,p6,p7,p8);
AkiraK 0:4b1269eccf13 10
AkiraK 0:4b1269eccf13 11 int main() {
AkiraK 0:4b1269eccf13 12 //Define User's Device Basic Information
AkiraK 0:4b1269eccf13 13 char *deviceId = "UIYCOQAATQAO5AF7"; //Device ID
AkiraK 0:4b1269eccf13 14 char *channel[3] = {"RFMZW246", "KLQWUD3M", "VT7OQEYA"}; //Channel ID : 1st ID is temperature. 2nd is humidity.
AkiraK 0:4b1269eccf13 15 float data[3]; //Data holder
AkiraK 0:4b1269eccf13 16 fast.ethConnect(); //Ethernet connect
AkiraK 0:4b1269eccf13 17
AkiraK 0:4b1269eccf13 18 while(1) {
AkiraK 0:4b1269eccf13 19 data[0] = scp1000.readPressure(true); //substitute Pressure data to data[0]
AkiraK 0:4b1269eccf13 20 data[1] = scp1000.readTemperature(true); //substitute Temperature data to data[1]
AkiraK 0:4b1269eccf13 21 pc.printf("The pressure is %f Pa and the temperature is %f C\n", data[0], data[1]); //display pressure and temperature to PC
AkiraK 0:4b1269eccf13 22 int val = fast.updateDataAll(deviceId, channel, data); //Send all got data to fastsensing.com
AkiraK 0:4b1269eccf13 23 pc.printf("res : %d\n", val); //updateDataAll result display
AkiraK 0:4b1269eccf13 24 myled = 1;
AkiraK 0:4b1269eccf13 25 if(button == 1) break;
AkiraK 0:4b1269eccf13 26 wait(10.0);
AkiraK 0:4b1269eccf13 27 myled = 0;
AkiraK 0:4b1269eccf13 28 }
AkiraK 0:4b1269eccf13 29 fast.ethDisconnect(); //Ethernet disconnect
AkiraK 0:4b1269eccf13 30 while(1) {
AkiraK 0:4b1269eccf13 31 myled = 1;
AkiraK 0:4b1269eccf13 32 wait(0.5);
AkiraK 0:4b1269eccf13 33 myled = 0;
AkiraK 0:4b1269eccf13 34 wait(0.5);
AkiraK 0:4b1269eccf13 35 }
AkiraK 0:4b1269eccf13 36 }