温度センサの値をMilkcocoaへPushするプログラム
Dependencies: EthernetInterface Milkcocoa_EthernetIF mbed-rtos mbed
Fork of MilkcocoaSample_Eth by
Diff: main.cpp
- Revision:
- 1:a45427394577
- Parent:
- 0:92848fdd9379
- Child:
- 2:7be8b81dc8ac
--- a/main.cpp Fri Dec 18 04:43:09 2015 +0000 +++ b/main.cpp Wed Feb 24 16:59:36 2016 +0000 @@ -7,12 +7,13 @@ // The default setting is for the Simple IoT Board(mbed LPC1114FN28) // Please change to fit the platform Serial pc(USBTX, USBRX); -DigitalOut myled(LED1); +DigitalOut red(LED1); +Ticker flipper; /************************* Your Milkcocoa Setup *********************************/ -#define MILKCOCOA_APP_ID "...YOUR_MILKCOCOA_APP_ID..." -#define MILKCOCOA_DATASTORE "esp8266" +#define MILKCOCOA_APP_ID "teaidsirehz" +#define MILKCOCOA_DATASTORE "LED" /************* Milkcocoa Setup (you don't need to change this!) ******************/ @@ -25,8 +26,24 @@ extern void onpush(MQTT::MessageData& md); +int duty = 0; +int duty_count = 0; + +void flip() { + if( duty_count > duty ) + { + red = 0; + } + else + { + red = 1; + } + + duty_count++; + if( duty_count > 100) duty_count = 0; +} + int main() { -// void setup() { pc.baud(9600); MQTTEthernet *ipstack = new MQTTEthernet(); @@ -40,16 +57,10 @@ pc.printf("%d\n\r",milkcocoa->on(MILKCOCOA_DATASTORE, "push", onpush)); -// } + flipper.attach(&flip, 0.0001); + while(1) { -// void loop() { milkcocoa->loop(); - - DataElement elem = DataElement(); - elem.setValue("v", 1); - - milkcocoa->push(MILKCOCOA_DATASTORE, elem); - wait(7.0); } } @@ -57,6 +68,7 @@ { MQTT::Message &message = md.message; DataElement de = DataElement((char*)message.payload); - pc.printf("onpush\n\r"); - pc.printf("%d\n\r",de.getInt("v")); + //pc.printf("onpush:%s\n\r",message.payload); + //pc.printf("%d\n\r",de.getInt("RED")); + duty = de.getInt("RED"); } \ No newline at end of file