Local copy
Dependencies: C12832_lcd ConfigFile EthernetInterface LM75B MMA7660 MQTTPacket mbed-rtos mbed
Fork of IBMIoTClientExampleForLPC1768 by
Diff: src/main.cpp
- Revision:
- 7:2c5d0dbd7985
- Parent:
- 6:a022f983f94b
- Child:
- 8:e58e10ca4352
--- a/src/main.cpp Mon Jun 30 21:10:25 2014 +0000 +++ b/src/main.cpp Tue Jul 01 08:22:36 2014 +0000 @@ -79,30 +79,51 @@ lcd.printf("Mac address: %s\n", mac); wait(3.0); - //subscribe(*c); - c->subscribe(); + //c->subscribe(); + char value[10]; + //string data_points = ""; while(1) { //Initialize lcd //Flash led to show message has been sent successfully led1 = 1; - + string data_points = "\"myName\": \"IoT mbed\""; //Construct quickstart message with desired datapoints //QuickstartMessage* m = new QuickstartMessage(); //m->add("accelX", MMA.x()); - + sprintf(value, "%0.4f", MMA.x()); + data_points+=",\"accelX\":"; + data_points+=value; //m->add("accelY", MMA.y()); + sprintf(value, "%0.4f", MMA.y()); + data_points+=",\"accelY\":"; + data_points+=value; //m->add("accelZ", MMA.z()); + sprintf(value, "%0.4f", MMA.z()); + data_points+=",\"accelZ\":"; + data_points+=value; //m->add("temp", tmp.read()); + sprintf(value, "%0.4f", tmp.read()); + data_points+=",\"temp\":"; + data_points+=value; //m->add("joystick", joystickPos); - //pot1 = ain1; - //pot2 = ain2; + data_points+=",\"joystick\":" + joystickPos; + pot1 = ain1; + pot2 = ain2; //m->add("potentiometer1", pot1); + sprintf(value, "%0.4f", pot1); + data_points+=",\"potentiometer1\":"; + data_points+=value; //m->add("potentiometer2", pot2); + sprintf(value, "%0.4f", pot1); + data_points+=",\"potentiometer1\":"; + data_points+=value; + + string message = "{\"d\":{" + data_points + "}}"; //Message is converted from datapoints into json format and then published - c->publish("{\"d\":{\"myName\":\"Mymbed\",\"temperature\":43,\"acelX\":0.3644,\"acelY\":0.9344,\"acelZ\":0.9334}}");//c->publish(m->convertToJson()); + c->publish(message);//c->publish(m->convertToJson()); lcd.printf("After"); wait(3.0); //if (m) {