Local copy

Dependencies:   C12832_lcd ConfigFile EthernetInterface LM75B MMA7660 MQTTPacket mbed-rtos mbed

Fork of IBMIoTClientExampleForLPC1768 by Sam Danbury

Committer:
samdanbury
Date:
Tue Jun 24 10:35:40 2014 +0000
Revision:
4:e8de333c1cb4
Parent:
1:dd948ce80918
Parent:
2:25ddff75a8c7
Child:
6:a022f983f94b
merge changes

Who changed what in which revision?

UserRevisionLine numberNew contents of line
samdanbury 0:6276e9f72327 1 /*******************************************************************************
samdanbury 0:6276e9f72327 2 * Copyright (c) 2014 IBM Corporation and other Contributors.
samdanbury 0:6276e9f72327 3 *
samdanbury 0:6276e9f72327 4 * All rights reserved. This program and the accompanying materials
samdanbury 0:6276e9f72327 5 * are made available under the terms of the Eclipse Public License v1.0
samdanbury 0:6276e9f72327 6 * which accompanies this distribution, and is available at
samdanbury 0:6276e9f72327 7 * http://www.eclipse.org/legal/epl-v10.html
samdanbury 0:6276e9f72327 8 *
samdanbury 0:6276e9f72327 9 * Contributors: Sam Danbury
samdanbury 0:6276e9f72327 10 * IBM - Initial Contribution
samdanbury 0:6276e9f72327 11 *******************************************************************************/
samdanbury 0:6276e9f72327 12
samdanbury 0:6276e9f72327 13 #include "stdio.h"
samdanbury 0:6276e9f72327 14 #include "mbed.h"
samdanbury 0:6276e9f72327 15 #include "rtos.h"
samdanbury 0:6276e9f72327 16 #include "EthernetInterface.h"
samdanbury 0:6276e9f72327 17 #include "C12832_lcd.h"
samdanbury 0:6276e9f72327 18 #include "LM75B.h"
samdanbury 0:6276e9f72327 19 #include "MMA7660.h"
samdanbury 0:6276e9f72327 20 #include "C12832_lcd.h"
samdanbury 0:6276e9f72327 21 #include "QuickstartClient.h"
samdanbury 0:6276e9f72327 22 #include "QuickstartMessage.h"
samdanbury 0:6276e9f72327 23
samdanbury 0:6276e9f72327 24 #include <string>
samdanbury 0:6276e9f72327 25
samdanbury 0:6276e9f72327 26 using namespace std;
samdanbury 0:6276e9f72327 27
samdanbury 0:6276e9f72327 28 //LCD
samdanbury 0:6276e9f72327 29 C12832_LCD lcd;
samdanbury 0:6276e9f72327 30
samdanbury 0:6276e9f72327 31 //LED
samdanbury 0:6276e9f72327 32 DigitalOut led1(LED1);
samdanbury 0:6276e9f72327 33
samdanbury 0:6276e9f72327 34 //Accelerometer
samdanbury 0:6276e9f72327 35 MMA7660 MMA(p28, p27);
samdanbury 0:6276e9f72327 36
samdanbury 0:6276e9f72327 37 //Temperature sensor
samdanbury 0:6276e9f72327 38 LM75B tmp(p28, p27);
samdanbury 0:6276e9f72327 39
samdanbury 0:6276e9f72327 40 //Joystick
samdanbury 0:6276e9f72327 41 BusIn Down(p12);
samdanbury 0:6276e9f72327 42 BusIn Left(p13);
samdanbury 0:6276e9f72327 43 BusOut Click(p14);
samdanbury 0:6276e9f72327 44 BusIn Up(p15);
samdanbury 0:6276e9f72327 45 BusIn Right(p16);
samdanbury 0:6276e9f72327 46 string joystickPos;
samdanbury 0:6276e9f72327 47 void joystickThread(void const *args);
samdanbury 0:6276e9f72327 48
samdanbury 0:6276e9f72327 49 //Potentiometer
samdanbury 0:6276e9f72327 50 AnalogIn ain1(p19);
samdanbury 0:6276e9f72327 51 AnalogIn ain2(p20);
samdanbury 0:6276e9f72327 52 float pot1;
samdanbury 0:6276e9f72327 53 float pot2;
samdanbury 0:6276e9f72327 54
samdanbury 2:25ddff75a8c7 55 LocalFileSystem local("local");
samdanbury 2:25ddff75a8c7 56
samdanbury 0:6276e9f72327 57 int main()
samdanbury 0:6276e9f72327 58 {
rajathishere 1:dd948ce80918 59 //RAJATH's COMMIT
samdanbury 0:6276e9f72327 60 //Connect to the network
samdanbury 0:6276e9f72327 61 EthernetInterface eth;
samdanbury 0:6276e9f72327 62 eth.init();
samdanbury 0:6276e9f72327 63 eth.connect();
samdanbury 0:6276e9f72327 64
samdanbury 0:6276e9f72327 65 //Obtain mac address of mbed
samdanbury 0:6276e9f72327 66 string mac = eth.getMACAddress();
samdanbury 0:6276e9f72327 67
samdanbury 0:6276e9f72327 68 //Remove colons from mac address
samdanbury 0:6276e9f72327 69 mac.erase(remove(mac.begin(), mac.end(), ':'), mac.end());
samdanbury 0:6276e9f72327 70
samdanbury 0:6276e9f72327 71 //Start thread to read data from joystick
samdanbury 0:6276e9f72327 72 Thread jThd(joystickThread);
samdanbury 0:6276e9f72327 73 joystickPos = "CENTRE";
samdanbury 0:6276e9f72327 74
samdanbury 0:6276e9f72327 75 QuickstartClient* c = new QuickstartClient(mac);
samdanbury 0:6276e9f72327 76
samdanbury 0:6276e9f72327 77 while(1)
samdanbury 0:6276e9f72327 78 {
samdanbury 0:6276e9f72327 79 //Initialize lcd
samdanbury 0:6276e9f72327 80 lcd.cls();
samdanbury 0:6276e9f72327 81 lcd.locate(0,0);
samdanbury 0:6276e9f72327 82
samdanbury 0:6276e9f72327 83 lcd.printf("Mac address: %s\n", mac);
samdanbury 0:6276e9f72327 84
samdanbury 0:6276e9f72327 85 //Flash led to show message has been sent successfully
samdanbury 0:6276e9f72327 86 led1 = 1;
samdanbury 0:6276e9f72327 87
samdanbury 0:6276e9f72327 88 //Construct quickstart message with desired datapoints
samdanbury 0:6276e9f72327 89 QuickstartMessage* m = new QuickstartMessage();
samdanbury 0:6276e9f72327 90 m->add("accelX", MMA.x());
samdanbury 0:6276e9f72327 91 m->add("accelY", MMA.y());
samdanbury 0:6276e9f72327 92 m->add("accelZ", MMA.z());
samdanbury 0:6276e9f72327 93 m->add("temp", tmp.read());
samdanbury 0:6276e9f72327 94 m->add("joystick", joystickPos);
samdanbury 0:6276e9f72327 95
samdanbury 0:6276e9f72327 96 pot1 = ain1;
samdanbury 0:6276e9f72327 97 pot2 = ain2;
samdanbury 0:6276e9f72327 98 m->add("potentiometer1", pot1);
samdanbury 0:6276e9f72327 99 m->add("potentiometer2", pot2);
samdanbury 0:6276e9f72327 100
samdanbury 0:6276e9f72327 101 //Message is converted from datapoints into json format and then published
samdanbury 0:6276e9f72327 102 c->publish(m->convertToJson());
samdanbury 0:6276e9f72327 103
samdanbury 0:6276e9f72327 104 if (m) {
samdanbury 0:6276e9f72327 105 delete m;
samdanbury 0:6276e9f72327 106 }
samdanbury 0:6276e9f72327 107
samdanbury 0:6276e9f72327 108 led1 = 0;
samdanbury 0:6276e9f72327 109
samdanbury 0:6276e9f72327 110 //Message published every second
samdanbury 0:6276e9f72327 111 wait(1);
samdanbury 0:6276e9f72327 112 }
samdanbury 0:6276e9f72327 113
samdanbury 0:6276e9f72327 114 eth.disconnect();
samdanbury 0:6276e9f72327 115 }
samdanbury 0:6276e9f72327 116
samdanbury 0:6276e9f72327 117 void joystickThread(void const *args) {
samdanbury 0:6276e9f72327 118 while (1) {
samdanbury 0:6276e9f72327 119 if (Down)
samdanbury 0:6276e9f72327 120 joystickPos = "DOWN";
samdanbury 0:6276e9f72327 121 else if (Left)
samdanbury 0:6276e9f72327 122 joystickPos = "LEFT";
samdanbury 0:6276e9f72327 123 else if (Click)
samdanbury 0:6276e9f72327 124 joystickPos = "CLICK";
samdanbury 0:6276e9f72327 125 else if (Up)
samdanbury 0:6276e9f72327 126 joystickPos = "UP";
samdanbury 0:6276e9f72327 127 else if (Right)
samdanbury 0:6276e9f72327 128 joystickPos = "RIGHT";
samdanbury 0:6276e9f72327 129 else
samdanbury 0:6276e9f72327 130 joystickPos = "CENTRE";
samdanbury 0:6276e9f72327 131 }
samdanbury 0:6276e9f72327 132 }