Dreamforce 2013 MiniHack Thermostat Challenge

Dependencies:   C12832_lcd EthernetInterface-ansond-patched HTTPClient-thermostat-remotes LM75B MMA7660 SocketIO WebSocketClient-ThermostatDemo mbed-rtos mbed picojson

Committer:
ansond
Date:
Mon Nov 11 20:36:21 2013 +0000
Revision:
3:399f01802514
Parent:
0:bca7aceedd02
updates

Who changed what in which revision?

UserRevisionLine numberNew contents of line
ansond 0:bca7aceedd02 1 /**
ansond 0:bca7aceedd02 2 * @author Doug Anson
ansond 0:bca7aceedd02 3 *
ansond 0:bca7aceedd02 4 * @section LICENSE
ansond 0:bca7aceedd02 5 *
ansond 0:bca7aceedd02 6 * Copyright (c) 2013 mbed
ansond 0:bca7aceedd02 7 *
ansond 0:bca7aceedd02 8 * Permission is hereby granted, free of charge, to any person obtaining a copy
ansond 0:bca7aceedd02 9 * of this software and associated documentation files (the "Software"), to deal
ansond 0:bca7aceedd02 10 * in the Software without restriction, including without limitation the rights
ansond 0:bca7aceedd02 11 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
ansond 0:bca7aceedd02 12 * copies of the Software, and to permit persons to whom the Software is
ansond 0:bca7aceedd02 13 * furnished to do so, subject to the following conditions:
ansond 0:bca7aceedd02 14 *
ansond 0:bca7aceedd02 15 * The above copyright notice and this permission notice shall be included in
ansond 0:bca7aceedd02 16 * all copies or substantial portions of the Software.
ansond 0:bca7aceedd02 17 *
ansond 0:bca7aceedd02 18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
ansond 0:bca7aceedd02 19 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
ansond 0:bca7aceedd02 20 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
ansond 0:bca7aceedd02 21 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
ansond 0:bca7aceedd02 22 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
ansond 0:bca7aceedd02 23 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
ansond 0:bca7aceedd02 24 * THE SOFTWARE.
ansond 0:bca7aceedd02 25 *
ansond 0:bca7aceedd02 26 * @section DESCRIPTION
ansond 0:bca7aceedd02 27 * SocketIO derivation client library for the Thermostat Demo
ansond 0:bca7aceedd02 28 *
ansond 0:bca7aceedd02 29 */
ansond 0:bca7aceedd02 30
ansond 0:bca7aceedd02 31 #ifndef THERMOSTATSOCKETIO_H
ansond 0:bca7aceedd02 32 #define THERMOSTATSOCKETIO_H
ansond 0:bca7aceedd02 33
ansond 0:bca7aceedd02 34 #include "SocketIO.h"
ansond 0:bca7aceedd02 35
ansond 0:bca7aceedd02 36 /**
ansond 0:bca7aceedd02 37 * ThermostatSocketIO client class.
ansond 0:bca7aceedd02 38 * Derived class from SocketIO library specifically for the ThermostatDemo app
ansond 0:bca7aceedd02 39 */
ansond 0:bca7aceedd02 40
ansond 0:bca7aceedd02 41 class ThermostatSocketIO : public SocketIO
ansond 0:bca7aceedd02 42 {
ansond 0:bca7aceedd02 43 public:
ansond 0:bca7aceedd02 44 /**
ansond 0:bca7aceedd02 45 * Constructor
ansond 0:bca7aceedd02 46 *
ansond 0:bca7aceedd02 47 * @param devname The device's devname for display in the console
ansond 0:bca7aceedd02 48 */
ansond 0:bca7aceedd02 49 ThermostatSocketIO(char *devname);
ansond 0:bca7aceedd02 50
ansond 0:bca7aceedd02 51 /**
ansond 0:bca7aceedd02 52 * Constructor
ansond 0:bca7aceedd02 53 *
ansond 0:bca7aceedd02 54 * @param url The SocketIO url in the form "www.example.com:[port]" (by default: port = 80) - i.e. just the endpoint name
ansond 0:bca7aceedd02 55 * @param devname The device's devname for display in the console
ansond 0:bca7aceedd02 56 */
ansond 0:bca7aceedd02 57 ThermostatSocketIO(char * url, char *devname);
ansond 0:bca7aceedd02 58
ansond 0:bca7aceedd02 59 /**
ansond 0:bca7aceedd02 60 * Emit (Broadcast) a socket.io message to the SocketIO server - specific to the ThermostatDemo app
ansond 0:bca7aceedd02 61 *
ansond 0:bca7aceedd02 62 * @param temp - temperature
ansond 0:bca7aceedd02 63 * @param latitude - the device latitude
ansond 0:bca7aceedd02 64 * @param longitude - the device longitude
ansond 0:bca7aceedd02 65 * @param bat - the battery level
ansond 0:bca7aceedd02 66 * @param errorState - the devices current error state
ansond 0:bca7aceedd02 67 * @param t_status - the devices current error state (string - either OK or FAIL)
ansond 0:bca7aceedd02 68 *
ansond 0:bca7aceedd02 69 * @returns the number of bytes sent
ansond 0:bca7aceedd02 70 */
ansond 0:bca7aceedd02 71 int emit(float temp, float latitude, float longitude, float bat, int errorState, char *t_status);
ansond 0:bca7aceedd02 72
ansond 0:bca7aceedd02 73 /**
ansond 0:bca7aceedd02 74 * Reset the message counter
ansond 0:bca7aceedd02 75 */
ansond 0:bca7aceedd02 76 void resetMessageCounter();
ansond 0:bca7aceedd02 77
ansond 0:bca7aceedd02 78 /**
ansond 0:bca7aceedd02 79 * Close the SocketIO connection
ansond 0:bca7aceedd02 80 *
ansond 0:bca7aceedd02 81 * @return true if the connection has been closed, false otherwise
ansond 0:bca7aceedd02 82 */
ansond 0:bca7aceedd02 83 bool close();
ansond 0:bca7aceedd02 84
ansond 0:bca7aceedd02 85 private:
ansond 0:bca7aceedd02 86 // variables
ansond 0:bca7aceedd02 87 char *device_name;
ansond 0:bca7aceedd02 88
ansond 0:bca7aceedd02 89 // methods
ansond 0:bca7aceedd02 90 char *createDeregisterJSON(char *buffer);
ansond 0:bca7aceedd02 91 char *createJSON(char *buffer, float temp, float latitude, float longitude, float bat, int errorState, char *t_status);
ansond 0:bca7aceedd02 92 };
ansond 0:bca7aceedd02 93
ansond 0:bca7aceedd02 94 #endif // THERMOSTATSOCKETIO_H