温度センサの値をMilkcocoaへPushするプログラム

Dependencies:   EthernetInterface Milkcocoa_EthernetIF mbed-rtos mbed

Fork of MilkcocoaSample_Eth by Junichi Katsu

Committer:
jksoft
Date:
Mon Jun 06 03:38:14 2016 +0000
Revision:
7:90a62daabce9
Parent:
6:bb5007360554
??

Who changed what in which revision?

UserRevisionLine numberNew contents of line
jksoft 0:92848fdd9379 1 #include "mbed.h"
jksoft 0:92848fdd9379 2 #include "MQTTEthernet.h"
jksoft 0:92848fdd9379 3 #include "MQTTClient.h"
jksoft 0:92848fdd9379 4 #include "Milkcocoa.h"
jksoft 0:92848fdd9379 5 #include "MClient.h"
jksoft 0:92848fdd9379 6
jksoft 0:92848fdd9379 7 // The default setting is for the Simple IoT Board(mbed LPC1114FN28)
jksoft 0:92848fdd9379 8 // Please change to fit the platform
jksoft 0:92848fdd9379 9 Serial pc(USBTX, USBRX);
jksoft 7:90a62daabce9 10 PwmOut myled(LED1);
jksoft 0:92848fdd9379 11
jksoft 0:92848fdd9379 12 /************************* Your Milkcocoa Setup *********************************/
jksoft 6:bb5007360554 13 #define MILKCOCOA_APP_ID "...YOUR_MILKCOCOA_APP_ID..."
jksoft 7:90a62daabce9 14 #define MILKCOCOA_DATASTORE "LED"
jksoft 0:92848fdd9379 15
jksoft 0:92848fdd9379 16 /************* Milkcocoa Setup (you don't need to change this!) ******************/
jksoft 0:92848fdd9379 17
jksoft 0:92848fdd9379 18 #define MILKCOCOA_SERVERPORT 1883
jksoft 0:92848fdd9379 19
jksoft 0:92848fdd9379 20 /************ Global State (you don't need to change this!) ******************/
jksoft 0:92848fdd9379 21
jksoft 0:92848fdd9379 22 const char MQTT_SERVER[] = MILKCOCOA_APP_ID ".mlkcca.com";
jksoft 0:92848fdd9379 23 const char MQTT_CLIENTID[] = __TIME__ MILKCOCOA_APP_ID;
jksoft 0:92848fdd9379 24
jksoft 0:92848fdd9379 25 extern void onpush(MQTT::MessageData& md);
jksoft 0:92848fdd9379 26
jksoft 0:92848fdd9379 27 int main() {
jksoft 0:92848fdd9379 28 // void setup() {
jksoft 0:92848fdd9379 29 pc.baud(9600);
jksoft 0:92848fdd9379 30
jksoft 0:92848fdd9379 31 MQTTEthernet *ipstack = new MQTTEthernet();
jksoft 0:92848fdd9379 32 MClient *client = new MClient(ipstack);
jksoft 0:92848fdd9379 33 Milkcocoa *milkcocoa = new Milkcocoa(client, MQTT_SERVER, MILKCOCOA_SERVERPORT, MILKCOCOA_APP_ID, MQTT_CLIENTID);
jksoft 0:92848fdd9379 34
jksoft 0:92848fdd9379 35 pc.printf("Milkcocoa mbed ver demo\n\r\n\r\n\r");
jksoft 0:92848fdd9379 36
jksoft 0:92848fdd9379 37 milkcocoa->connect();
jksoft 0:92848fdd9379 38 pc.printf("\n\rEther connected\n\r");
jksoft 0:92848fdd9379 39
jksoft 0:92848fdd9379 40 pc.printf("%d\n\r",milkcocoa->on(MILKCOCOA_DATASTORE, "push", onpush));
jksoft 0:92848fdd9379 41
jksoft 0:92848fdd9379 42 // }
jksoft 0:92848fdd9379 43 while(1) {
jksoft 0:92848fdd9379 44 // void loop() {
jksoft 0:92848fdd9379 45 milkcocoa->loop();
jksoft 0:92848fdd9379 46 }
jksoft 0:92848fdd9379 47 }
jksoft 0:92848fdd9379 48
jksoft 0:92848fdd9379 49 void onpush(MQTT::MessageData& md)
jksoft 0:92848fdd9379 50 {
jksoft 0:92848fdd9379 51 MQTT::Message &message = md.message;
jksoft 0:92848fdd9379 52 DataElement de = DataElement((char*)message.payload);
jksoft 0:92848fdd9379 53 pc.printf("onpush\n\r");
jksoft 7:90a62daabce9 54 myled = (float)de.getInt("RED") / 100.0f;
jksoft 0:92848fdd9379 55 }