Junichi Katsu
/
MilkcocoaOsSample_Eth_sensor
mbed(エンベッド)の仕組みを学び、試作体験!用のサンプル
Fork of MilkcocoaOsSample_Eth by
Diff: main.cpp
- Revision:
- 7:49a5a7e621d6
- Parent:
- 5:103da32c92c7
- Child:
- 8:d5c4aa73f69e
diff -r d2dcba3c77f0 -r 49a5a7e621d6 main.cpp --- a/main.cpp Thu Jun 01 05:38:12 2017 +0000 +++ b/main.cpp Sun Aug 06 15:49:14 2017 +0000 @@ -4,11 +4,12 @@ EthernetInterface eth; RawSerial pc(USBTX,USBRX); +AnalogIn sensor(A1); /************************* Your Milkcocoa Setup *********************************/ #define MILKCOCOA_APP_ID "...YOUR_MILKCOCOA_APP_ID..." -#define MILKCOCOA_DATASTORE "mbed_lan" +#define MILKCOCOA_DATASTORE "sensor" /************* Milkcocoa Setup (you don't need to change this!) ******************/ @@ -20,8 +21,9 @@ extern void onpush(MQTT::MessageData& md); + int main() { - + float val; pc.baud(9600); pc.printf("Milkcocoa mbed os ver demo\n\r\n\r\n\r"); @@ -35,31 +37,18 @@ Milkcocoa* milkcocoa = new Milkcocoa(ð, MQTT_SERVER, MILKCOCOA_SERVERPORT, MILKCOCOA_APP_ID, MQTT_CLIENTID); milkcocoa->connect(); - - pc.printf("%d\n\r",milkcocoa->on(MILKCOCOA_DATASTORE, "push", onpush)); - -#ifdef __MILKCOCOA_THREAD - milkcocoa->setLoopCycle(5000); - milkcocoa->start(); -#endif + while(1) { DataElement elem = DataElement(); - elem.setValue("v", 1); + val = sensor.read(); + pc.printf("light = %f\r\n",val); + elem.setValue("light", val); milkcocoa->push(MILKCOCOA_DATASTORE, elem); -#ifndef __MILKCOCOA_THREAD milkcocoa->loop(); -#endif - Thread::wait(7000); - + + Thread::wait(2000); } } - -void onpush(MQTT::MessageData& md) -{ - MQTT::Message &message = md.message; - DataElement de = DataElement((char*)message.payload); - pc.printf("onpush\n\r"); - pc.printf("%d\n\r",de.getInt("v")); -} \ No newline at end of file + \ No newline at end of file