Local copy
Dependencies: C12832_lcd ConfigFile EthernetInterface LM75B MMA7660 MQTTPacket mbed-rtos mbed
Fork of IBMIoTClientExampleForLPC1768 by
src/main.cpp
- Committer:
- rajathishere
- Date:
- 2014-06-30
- Revision:
- 6:a022f983f94b
- Parent:
- 4:e8de333c1cb4
- Child:
- 7:2c5d0dbd7985
File content as of revision 6:a022f983f94b:
/******************************************************************************* * Copyright (c) 2014 IBM Corporation and other Contributors. * * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * * Contributors: Sam Danbury * IBM - Initial Contribution *******************************************************************************/ #include "stdio.h" #include "mbed.h" #include "rtos.h" #include "EthernetInterface.h" #include "C12832_lcd.h" #include "LM75B.h" #include "MMA7660.h" #include "C12832_lcd.h" #include "QuickstartClient.h" #include "QuickstartMessage.h" #include <string> using namespace std; //LCD C12832_LCD lcd; //LED DigitalOut led1(LED1); //Accelerometer MMA7660 MMA(p28, p27); //Temperature sensor LM75B tmp(p28, p27); //Joystick BusIn Down(p12); BusIn Left(p13); BusOut Click(p14); BusIn Up(p15); BusIn Right(p16); string joystickPos; void joystickThread(void const *args); //Potentiometer AnalogIn ain1(p19); AnalogIn ain2(p20); float pot1; float pot2; LocalFileSystem local("local"); int main() { //RAJATH's COMMIT //Connect to the network EthernetInterface eth; eth.init(); eth.connect(); //Obtain mac address of mbed string mac = eth.getMACAddress(); //Remove colons from mac address mac.erase(remove(mac.begin(), mac.end(), ':'), mac.end()); //Start thread to read data from joystick Thread jThd(joystickThread); joystickPos = "CENTRE"; QuickstartClient* c = new QuickstartClient(mac); lcd.cls(); lcd.locate(0,0); lcd.printf("Mac address: %s\n", mac); wait(3.0); //subscribe(*c); c->subscribe(); while(1) { //Initialize lcd //Flash led to show message has been sent successfully led1 = 1; //Construct quickstart message with desired datapoints //QuickstartMessage* m = new QuickstartMessage(); //m->add("accelX", MMA.x()); //m->add("accelY", MMA.y()); //m->add("accelZ", MMA.z()); //m->add("temp", tmp.read()); //m->add("joystick", joystickPos); //pot1 = ain1; //pot2 = ain2; //m->add("potentiometer1", pot1); //m->add("potentiometer2", pot2); //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()); lcd.printf("After"); wait(3.0); //if (m) { // delete m; //} led1 = 0; //Message published every second wait(1); } eth.disconnect(); } void joystickThread(void const *args) { while (1) { if (Down) joystickPos = "DOWN"; else if (Left) joystickPos = "LEFT"; else if (Click) joystickPos = "CLICK"; else if (Up) joystickPos = "UP"; else if (Right) joystickPos = "RIGHT"; else joystickPos = "CENTRE"; } }