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