Dreamforce Heroku Sample mbed application for the FRDM-K64F. This application uses SocketIO to connect and communicate with Heroku.

Dependencies:   BufferedSerial C12832 EthernetInterface HTTPClient-SSL LM75B MMA7660 SocketIO-k64f WebSocketClient-ThermostatDemo mbed-rtos mbed picojson

Fork of df-2013-minihack-thermostat-complete by MBED_DEMOS

Committer:
ansond
Date:
Thu Oct 09 16:14:18 2014 +0000
Revision:
6:74c1e9c8c90e
Parent:
0:26c48388f725
updates of the 2013 DF heroku app ported to K64F+appshield

Who changed what in which revision?

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