Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: NetServices FatFileSystem csv_parser mbed MQTTClient RF12B DNSResolver SDFileSystem
Revision 5:0dbc27a7af55, committed 2012-05-09
- Comitter:
- SomeRandomBloke
- Date:
- Wed May 09 20:29:30 2012 +0000
- Parent:
- 4:d460406ac780
- Commit message:
- Reduced debug output
Changed in this revision
--- a/Outputs/OutputDef.h Tue May 01 21:43:40 2012 +0000
+++ b/Outputs/OutputDef.h Wed May 09 20:29:30 2012 +0000
@@ -60,6 +60,13 @@
* @returns -1 for fail, 1 for success
*/
virtual int send( ) = 0;
+
+ /** Get the send count
+ *
+ * @returns mumber of API calls made
+ */
+ virtual int getSendCount( ) = 0;
+
};
#endif /* _OUTPUTDEF_H */
\ No newline at end of file
--- a/Outputs/OutputEmonCms.cpp Tue May 01 21:43:40 2012 +0000
+++ b/Outputs/OutputEmonCms.cpp Wed May 09 20:29:30 2012 +0000
@@ -80,12 +80,13 @@
csvContent.set(std::string(dataBuffer));
// uri for post includes feed ID and datastream ID
- printf("URL: %s\n",dataBuffer);
+// printf("URL: %s\n",dataBuffer);
emonActivityLED = 1;
+ sendCount++;
// result should be 0 and response should be 200 for successful post
- printf("EmonCms send count %d\n", ++sendCount);
+// printf("EmonCms send count %d\n", sendCount);
/*
printf("\nHEAP STATS\n");
__heapstats((__heapprt)fprintf,stderr);
@@ -104,3 +105,7 @@
return 0;
}
+int OutputEmonCms::getSendCount( void ) {
+ return sendCount;
+}
+
\ No newline at end of file
--- a/Outputs/OutputEmonCms.h Tue May 01 21:43:40 2012 +0000
+++ b/Outputs/OutputEmonCms.h Wed May 09 20:29:30 2012 +0000
@@ -32,14 +32,11 @@
#ifndef _OUTPUTEMONCMS_H
#define _OUTPUTEMONCMS_H
+#include "iotgateway.h"
#include "mbed.h"
#include "HTTPClient.h"
#include "HTTPText.h"
-#define DATABUF_SIZE 128
-
-#define EMONCMS_URL "http://api.pachube.com/v2/feeds/%d.csv?_method=PUT"
-
/** Output definition class for sending readings to OpenEnergyMonitor emonCms
*/
class OutputEmonCms {
@@ -80,6 +77,12 @@
*/
virtual int send();
+ /** Get the send count
+ *
+ * @returns mumber of API calls made
+ */
+ virtual int getSendCount( );
+
protected:
int sendCount;
// OEM config
--- a/Outputs/OutputMqtt.cpp Tue May 01 21:43:40 2012 +0000
+++ b/Outputs/OutputMqtt.cpp Wed May 09 20:29:30 2012 +0000
@@ -67,6 +67,7 @@
// These are used to send
void OutputMqtt::addReading(char *topic, char *unused, char *reading ) {
+ sendCount++;
mqtt.publish( topic, reading );
}
@@ -77,3 +78,7 @@
return 0;
}
+
+int OutputMqtt::getSendCount( void ) {
+ return sendCount;
+}
--- a/Outputs/OutputMqtt.h Tue May 01 21:43:40 2012 +0000
+++ b/Outputs/OutputMqtt.h Wed May 09 20:29:30 2012 +0000
@@ -32,6 +32,7 @@
#ifndef _OUTPUTMQTT_H
#define _OUTPUTMQTT_H
+#include "iotgateway.h"
#include "mbed.h"
#include "MQTTClient.h"
@@ -71,6 +72,13 @@
* @returns -1 for fail, 1 for success
*/
virtual int send();
+
+ /** Get the send count
+ *
+ * @returns mumber of API calls made
+ */
+ virtual int getSendCount( );
+
protected:
MQTTClient mqtt;
--- a/Outputs/OutputPachube.cpp Tue May 01 21:43:40 2012 +0000
+++ b/Outputs/OutputPachube.cpp Wed May 09 20:29:30 2012 +0000
@@ -70,7 +70,7 @@
int OutputPachube::send( void ) {
- char urlBuf[64];
+ char urlBuf[API_URL_LENGTH];
HTTPClient http;
if ( strlen( dataBuffer ) > 1 ) {
@@ -81,24 +81,25 @@
csvContent.set(std::string(dataBuffer));
// uri for post includes feed ID and datastream ID
- snprintf(urlBuf, 64, PACHUBE_URL, currentFeed );
- printf("URL: %s\n",urlBuf);
+ snprintf(urlBuf, API_URL_LENGTH, apiUrl, currentFeed );
+// printf("URL: %s\n",urlBuf);
activityLED = 1;
// result should be 0 and response should be 200 for successful post
- printf("Pachube Send count %d\n", ++sendCount);
+ sendCount++;
+// printf("Pachube Send count %d\n", sendCount);
- printf("\nHEAP STATS\n");
+/* printf("\nHEAP STATS\n");
__heapstats((__heapprt)fprintf,stderr);
printf("\nHEAP CHECK\n");
__heapvalid((__heapprt)fprintf,stderr, 0);
printf("\nStackP: %ld\n",__current_sp());
printf("---------------\n");
-
+*/
HTTPResult result = http.post(urlBuf, csvContent, NULL);
int response = http.getHTTPResponseCode();
- printf("updateDataStream(%d)\n", response );
+// printf("updateDataStream(%d)\n", response );
activityLED = 0;
}
@@ -109,3 +110,6 @@
}
+int OutputPachube::getSendCount( void ) {
+ return sendCount;
+}
--- a/Outputs/OutputPachube.h Tue May 01 21:43:40 2012 +0000
+++ b/Outputs/OutputPachube.h Wed May 09 20:29:30 2012 +0000
@@ -32,14 +32,11 @@
#ifndef _OUTPUTPACHUBE_H
#define _OUTPUTPACHUBE_H
+#include "iotgateway.h"
#include "mbed.h"
#include "HTTPClient.h"
#include "HTTPText.h"
-#define DATABUF_SIZE 128
-
-#define PACHUBE_URL "http://api.pachube.com/v2/feeds/%d.csv?_method=PUT"
-
/** Output definition class for sending readings to Pachube
*/
class OutputPachube {
@@ -55,12 +52,6 @@
* @param key Pointer to API key
*/
OutputPachube( char *internalBufferStart, char *url, char *key );
-
- /** Set the API Key to use for sending readings to Pachube
- *
- * @param key Pointer to API key
- */
-// void setApiKey( char *key );
/** Initialise output definition object
*/
@@ -80,6 +71,12 @@
*/
virtual int send();
+ /** Get the send count
+ *
+ * @returns mumber of API calls made
+ */
+ virtual int getSendCount( );
+
protected:
int sendCount;
// Pachube config
--- a/Outputs/OutputSenSe.cpp Tue May 01 21:43:40 2012 +0000
+++ b/Outputs/OutputSenSe.cpp Wed May 09 20:29:30 2012 +0000
@@ -1,110 +1,115 @@
-/** IoT Gateway Output definition for Sen.Se
- *
- * @author Andrew Lindsay
- *
- * @section LICENSE
- *
- * Copyright (c) 2012 Andrew Lindsay (andrew [at] thiseldo [dot] co [dot] uk)
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
-
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- *
- * @section DESCRIPTION
- *
- *
- */
-
-#include "mbed.h"
-#include "OutputSenSe.h"
-
-DigitalOut senseActivityLED(p29, "activityLED");
-
-// Constructor
-OutputSenSe::OutputSenSe() {
- sendCount = 0;
-}
-
-/** Alternative Constructor
- */
-OutputSenSe::OutputSenSe( char *internalBufferStart, char *url, char *key ) {
- sendCount = 0;
- dataBuffer = internalBufferStart;
- apiUrl = url;
- apiKey = key;
- init();
-}
-
-
-void OutputSenSe::init( ) {
- dbufPtr = dataBuffer;
- *dbufPtr = '\0';
-}
-
-/*
- {
- "feed_id": <another_feed_id>,
- "value": <another_event_value>
- }
-*/
-
-void OutputSenSe::addReading(char *dataFeed, char *dataStream, char *reading ) {
-
- snprintf(dataBuffer, DATABUF_SIZE, "{ \"feed_id\" : %s, \"value\" : \"%s\" }\n", dataFeed, reading);
- printf("%s\n",dataBuffer);
- send();
-}
-
-
-int OutputSenSe::send( void ) {
- char urlBuf[128];
- HTTPClient http;
-
- if ( strlen( dataBuffer ) > 1 ) {
-
- HTTPText csvContent("application/json");
- // Get the string for Pachube
- csvContent.set(std::string(dataBuffer));
-
- // uri for post includes feed ID and datastream ID
- snprintf(urlBuf, 128, apiUrl, apiKey );
- printf("URL: %s\n",urlBuf);
-
-
- senseActivityLED = 1;
- // result should be 0 and response should be 200 for successful post
- printf("Sen.Se Send count %d\n", ++sendCount);
-
-/* printf("\nHEAP STATS\n");
- __heapstats((__heapprt)fprintf,stderr);
- printf("\nHEAP CHECK\n");
- __heapvalid((__heapprt)fprintf,stderr, 0);
- printf("\nStackP: %ld\n",__current_sp());
- printf("---------------\n");
-*/
- HTTPResult result = http.post(urlBuf, csvContent, NULL);
- int response = http.getHTTPResponseCode();
- printf("updateDataStream(%d)\n", response );
- senseActivityLED = 0;
- }
-
- dbufPtr = dataBuffer;
- *dbufPtr = '\0';
-
- return 0;
-}
-
+/** IoT Gateway Output definition for Sen.Se
+ *
+ * @author Andrew Lindsay
+ *
+ * @section LICENSE
+ *
+ * Copyright (c) 2012 Andrew Lindsay (andrew [at] thiseldo [dot] co [dot] uk)
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ *
+ * @section DESCRIPTION
+ *
+ *
+ */
+
+#include "mbed.h"
+#include "OutputSenSe.h"
+
+DigitalOut senseActivityLED(p29, "activityLED");
+
+// Constructor
+OutputSenSe::OutputSenSe() {
+ sendCount = 0;
+}
+
+/** Alternative Constructor
+ */
+OutputSenSe::OutputSenSe( char *internalBufferStart, char *url, char *key ) {
+ sendCount = 0;
+ dataBuffer = internalBufferStart;
+ apiUrl = url;
+ apiKey = key;
+ init();
+}
+
+
+void OutputSenSe::init( ) {
+ dbufPtr = dataBuffer;
+ *dbufPtr = '\0';
+}
+
+/*
+ {
+ "feed_id": <another_feed_id>,
+ "value": <another_event_value>
+ }
+*/
+
+void OutputSenSe::addReading(char *dataFeed, char *dataStream, char *reading ) {
+
+ snprintf(dataBuffer, DATABUF_SIZE, "{ \"feed_id\" : %s, \"value\" : \"%s\" }\n", dataFeed, reading);
+// printf("%s\n",dataBuffer);
+ send();
+}
+
+
+int OutputSenSe::send( void ) {
+ char urlBuf[API_URL_LENGTH];
+ HTTPClient http;
+
+ if ( strlen( dataBuffer ) > 1 ) {
+
+ HTTPText csvContent("application/json");
+ // Get the string for Pachube
+ csvContent.set(std::string(dataBuffer));
+
+ // uri for post includes feed ID and datastream ID
+ snprintf(urlBuf, API_URL_LENGTH, apiUrl, apiKey );
+// printf("URL: %s\n",urlBuf);
+
+
+ senseActivityLED = 1;
+ sendCount++;
+ // result should be 0 and response should be 200 for successful post
+// printf("Sen.Se Send count %d\n", sendCount);
+
+/* printf("\nHEAP STATS\n");
+ __heapstats((__heapprt)fprintf,stderr);
+ printf("\nHEAP CHECK\n");
+ __heapvalid((__heapprt)fprintf,stderr, 0);
+ printf("\nStackP: %ld\n",__current_sp());
+ printf("---------------\n");
+*/
+ HTTPResult result = http.post(urlBuf, csvContent, NULL);
+ int response = http.getHTTPResponseCode();
+// printf("updateDataStream(%d)\n", response );
+ senseActivityLED = 0;
+ }
+
+ dbufPtr = dataBuffer;
+ *dbufPtr = '\0';
+
+ return 0;
+}
+
+
+int OutputSenSe::getSendCount( void ) {
+ return sendCount;
+}
--- a/Outputs/OutputSenSe.h Tue May 01 21:43:40 2012 +0000
+++ b/Outputs/OutputSenSe.h Wed May 09 20:29:30 2012 +0000
@@ -32,14 +32,11 @@
#ifndef _OUTPUTSENSE_H
#define _OUTPUTSENSE_H
+#include "iotgateway.h"
#include "mbed.h"
#include "HTTPClient.h"
#include "HTTPText.h"
-#define DATABUF_SIZE 128
-
-#define SENSE_URL "http://api.pachube.com/v2/feeds/%d.csv?_method=PUT"
-
/** Output definition class for sending readings to Pachube
*/
class OutputSenSe {
@@ -55,12 +52,6 @@
* @param key Pointer to API key
*/
OutputSenSe( char *internalBufferStart, char *url, char *key );
-
- /** Set the API Key to use for sending readings to Pachube
- *
- * @param key Pointer to API key
- */
-// void setApiKey( char *key );
/** Initialise output definition object
*/
@@ -80,6 +71,12 @@
*/
virtual int send();
+ /** Get the send count
+ *
+ * @returns mumber of API calls made
+ */
+ virtual int getSendCount( );
+
protected:
int sendCount;
// Sen.Se config
--- a/Routing/IoTRouting.cpp Tue May 01 21:43:40 2012 +0000
+++ b/Routing/IoTRouting.cpp Wed May 09 20:29:30 2012 +0000
@@ -257,17 +257,17 @@
}
PayloadRouting* IoTRouting::getRouting( short nodeId, short sensorId ) {
- printf("Getting routing info for node %d, sensor %d - ", nodeId, sensorId);
+// printf("Getting routing info for node %d, sensor %d - ", nodeId, sensorId);
for ( short i=0; i<(short)_routing.size(); i++ ) {
PayloadRouting *pr = (PayloadRouting*)_routing.at(i);
// printf("Node %d, sensor %d\n", pr->nodeId, pr->sensorId);
if ( pr->nodeId == nodeId && pr->sensorId == sensorId ) {
- printf("Found!\n");
+// printf("Found!\n");
return pr;
}
}
- printf("NOT found\n");
+// printf("NOT found\n");
// Add to routing list
addRoutingToList( nodeId, sensorId, 1.0, OUTPUT_UNKNOWN,"","","","");
// Save Routing list
@@ -278,16 +278,16 @@
short IoTRouting::getPayloadType( uint8_t *data, short dataLen ) {
- printf("Getting payload type, size is %d - ",(int)_nodeDefList.size() );
+// printf("Getting payload type, size is %d - ",(int)_nodeDefList.size() );
for (short i=0; i<(int)_nodeDefList.size(); i++) {
// printf("%d, %ld, ",i, (int)_nodeDefList.at(i));
IoTNodeDef *nd = (IoTNodeDef*)_nodeDefList.at(i);
if ( nd->groupId == data[0] && nd->nodeId == (data[1] & 0x1f) && nd->length == data[2] ) {
- printf("Found %d\n", nd->type);
+// printf("Found %d\n", nd->type);
return nd->type;
}
}
- printf("NOT found\n");
+// printf("NOT found\n");
// Add to node list
addNodeToList(data[0], data[1] & 0x1f, data[2], PAYLOAD_TYPE_UNKNOWN );
// Save NodeList
@@ -295,6 +295,7 @@
return PAYLOAD_TYPE_UNKNOWN;
}
+#define TMPBUF_SIZE 20
bool IoTRouting::routePayload( uint8_t *data, short dataLen ) {
bool routed = false;
@@ -303,7 +304,7 @@
PayloadV1 pv1;
PayloadV2 pv2;
PayloadRouting *pr = NULL;
- char tmpBuf[42];
+ char tmpBuf[TMPBUF_SIZE];
pachubeOutput->init(); // Just to be sure
printf("routePayload: ");
@@ -327,8 +328,8 @@
if ( pr != NULL ) {
if ( pr->output != NULL ) {
// printf("Pachube %d, %d, %f, %s, %s\n",pr->nodeId, pr->sensorId, pr->factor, pr->param1, pr->param2);
- snprintf(tmpBuf, DATABUF_SIZE, "%.3f", (float)(psimp.reading(n) * pr->factor));
- printf("Add to output %s, %s, %s\n", pr->param1, pr->param2, tmpBuf );
+ snprintf(tmpBuf, TMPBUF_SIZE, "%.3f", (float)(psimp.reading(n) * pr->factor));
+// printf("Add to output %s, %s, %s\n", pr->param1, pr->param2, tmpBuf );
pr->output->addReading( pr->param1, pr->param2,tmpBuf );
}
}
@@ -352,7 +353,7 @@
printf("LOW Battery detected\n");
}
if ( pr->output != NULL ) {
- snprintf(tmpBuf, DATABUF_SIZE, "%d", (int)( data[3] & STATUS_LOW_BATTERY ));
+ snprintf(tmpBuf, TMPBUF_SIZE, "%d", (int)( data[3] & STATUS_LOW_BATTERY ));
pr->output->addReading( pr->param1, pr->param2, tmpBuf );
}
}
@@ -363,7 +364,7 @@
tmpBuf[0] = '\0';
// printf("Pachube %d, %d, %f, %s, %s\n",pr->nodeId, pr->sensorId, pr->factor, pr->param1, pr->param2);
if ( pr->output != NULL ) {
- snprintf(tmpBuf, DATABUF_SIZE, "%.3f", (float)(pv1.reading(n) * pr->factor));
+ snprintf(tmpBuf, TMPBUF_SIZE, "%.3f", (float)(pv1.reading(n) * pr->factor));
pr->output->addReading( pr->param1, pr->param2, tmpBuf );
}
printf("%d: %d - %s\n", n, pv1.sensorId(n), tmpBuf );
@@ -387,7 +388,7 @@
printf("LOW Battery detected\n");
}
if ( pr->output != NULL ) {
- snprintf(tmpBuf, DATABUF_SIZE, "%d", (int)( data[3] & STATUS_LOW_BATTERY ));
+ snprintf(tmpBuf, TMPBUF_SIZE, "%d", (int)( data[3] & STATUS_LOW_BATTERY ));
pr->output->addReading( pr->param1, pr->param2, tmpBuf );
}
// Need to update add reading to detect change in feed ID and send.
@@ -407,13 +408,13 @@
switch ( pv2.readingType( n ) ) {
case V2_DATATYPE_BYTE:
- snprintf(tmpBuf, DATABUF_SIZE, "%.3f", (float)(pv2.readingByte(n) * pr->factor));
+ snprintf(tmpBuf, TMPBUF_SIZE, "%.3f", (float)(pv2.readingByte(n) * pr->factor));
break;
case V2_DATATYPE_SHORT:
- snprintf(tmpBuf, DATABUF_SIZE, "%.3f", (float)(pv2.readingShort(n) * pr->factor));
+ snprintf(tmpBuf, TMPBUF_SIZE, "%.3f", (float)(pv2.readingShort(n) * pr->factor));
break;
case V2_DATATYPE_LONG:
- snprintf(tmpBuf, DATABUF_SIZE, "%.3f", (float)(pv2.readingLong(n) * pr->factor));
+ snprintf(tmpBuf, TMPBUF_SIZE, "%.3f", (float)(pv2.readingLong(n) * pr->factor));
break;
case V2_DATATYPE_STRING:
break;
--- a/Routing/IoTRouting.h Tue May 01 21:43:40 2012 +0000
+++ b/Routing/IoTRouting.h Wed May 09 20:29:30 2012 +0000
@@ -32,6 +32,7 @@
#ifndef _IOTROUTING_H
#define _IOTROUTING_H
+#include "iotgateway.h"
#include "mbed.h"
#include "HTTPClient.h"
#include "OutputDef.h"
@@ -134,7 +135,7 @@
* @param nodeId ID of the node payload came from
* @param sensorId ID of the sensor within the node
* @param factor Sensor Reading conversion factor, 100, 10, 1, 0.1, 0.01, 0.001 etc
- * @param outType Output type, 1 = Pachube, 2 = MQTT
+ * @param outType Output type, 1 = Pachube, 2 = MQTT, 3 = emonCMS, 4 = Sen.Se
* @param param1 Parameter 1
* @param param2 Parameter 2
* @param param3 Parameter 3
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/iotgateway.h Wed May 09 20:29:30 2012 +0000 @@ -0,0 +1,47 @@ +/** IoT Gateway config defines + * + * @author Andrew Lindsay + * + * @section LICENSE + * + * Copyright (c) 2012 Andrew Lindsay (andrew [at] thiseldo [dot] co [dot] uk) + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + * + * @section DESCRIPTION + * + * Code is to be classed as beta. There is a lot of debug code still includes + * to dump heap sizes and other values. It is still a work in progress and + * should be treated as such. + * + * Further documentation available from + * http://blog.thiseldo.co.uk/wp-filez/IoTGateway.pdf + * + */ + +#ifndef _IOTGATEWAY_H +#define _IOTGATEWAY_H + +#define MAX_LINE_LENGTH 128 + +#define DATABUF_SIZE 200 +#define API_URL_LENGTH 128 +#define API_KEY_LENGTH 65 + +#endif /* IOTGATEWAY_H */
--- a/main.cpp Tue May 01 21:43:40 2012 +0000
+++ b/main.cpp Wed May 09 20:29:30 2012 +0000
@@ -63,7 +63,7 @@
*
*/
-
+#include "iotgateway.h"
#include "mbed.h"
#include <ctype.h>
#include "SDFileSystem.h"
@@ -75,7 +75,9 @@
using std::string;
-#define VERSION_INFO "IoT Gateway Basic - Version 0.7-BETA "
+#undef DEBUG
+
+#define VERSION_INFO "IoT Gateway Basic - Version 0.8"
DigitalOut heartbeatLED(LED1, "heartbeatLED");
DigitalOut led2(LED2, "led2");
@@ -87,8 +89,8 @@
// Put as much as we can into RAM bank AHBSRAM0 which is reserved for USB that we are not using
// Setup which filesystem to use, Local or uSD card, both use same name
-__attribute((section("AHBSRAM0"))) LocalFileSystem fs("iotfs");
-//__attribute((section("AHBSRAM0"))) SDFileSystem sd(p5, p6, p7, p8, "iotfs");
+//__attribute((section("AHBSRAM0"))) LocalFileSystem fs("iotfs");
+__attribute((section("AHBSRAM0"))) SDFileSystem sd(p5, p6, p7, p8, "iotfs");
__attribute((section("AHBSRAM0"))) EthernetNetIf *eth;
__attribute((section("AHBSRAM0"))) NTPClient ntp;
@@ -103,7 +105,6 @@
__attribute((section("AHBSRAM0"))) bool useDHCP = false;
// Static buffers
-#define MAX_LINE_LENGTH 128
__attribute((section("AHBSRAM0"))) static char lineBuf[MAX_LINE_LENGTH];
__attribute((section("AHBSRAM0"))) static OutputPachube outPachube;
__attribute((section("AHBSRAM0"))) static OutputEmonCms outEmonCms;
@@ -111,9 +112,9 @@
__attribute((section("AHBSRAM0"))) static IoTRouting rtr;
// Pachube config
-__attribute((section("AHBSRAM0"))) char pachubeApiUrl[128];
-__attribute((section("AHBSRAM0"))) char pachubeApiKey[65];
-__attribute((section("AHBSRAM0"))) char pachubeDataBuffer[200];
+__attribute((section("AHBSRAM0"))) char pachubeApiUrl[API_URL_LENGTH];
+__attribute((section("AHBSRAM0"))) char pachubeApiKey[API_KEY_LENGTH];
+__attribute((section("AHBSRAM0"))) char pachubeDataBuffer[DATABUF_SIZE];
// MQTT config
__attribute((section("AHBSRAM0"))) IpAddr mqttHostAddress( 0, 0, 0, 0);
@@ -125,14 +126,14 @@
//char mqttHostName[65];
// Open energy Monitor emonCMS config
-__attribute((section("AHBSRAM0"))) char emonCmsApiUrl[128];
-__attribute((section("AHBSRAM0"))) char emonCmsApiKey[65];
-__attribute((section("AHBSRAM0"))) char emonCmsDataBuffer[200];
+__attribute((section("AHBSRAM0"))) char emonCmsApiUrl[API_URL_LENGTH];
+__attribute((section("AHBSRAM0"))) char emonCmsApiKey[API_KEY_LENGTH];
+__attribute((section("AHBSRAM0"))) char emonCmsDataBuffer[DATABUF_SIZE];
// Open energy Monitor Sen.Se config
-__attribute((section("AHBSRAM0"))) char senSeApiUrl[128];
-__attribute((section("AHBSRAM0"))) char senSeApiKey[65];
-__attribute((section("AHBSRAM0"))) char senSeDataBuffer[200];
+__attribute((section("AHBSRAM0"))) char senSeApiUrl[API_URL_LENGTH];
+__attribute((section("AHBSRAM0"))) char senSeApiKey[API_KEY_LENGTH];
+__attribute((section("AHBSRAM0"))) char senSeDataBuffer[DATABUF_SIZE];
// Time server config
__attribute((section("AHBSRAM0"))) char ntpHost[MAX_LINE_LENGTH] = "0.uk.pool.ntp.org";
@@ -392,6 +393,7 @@
extern unsigned int Image$$RW_IRAM3$$Base;
extern unsigned int Image$$RW_IRAM3$$ZI$$Limit;
+//#ifdef DEBUG
// Displays the size of static allocations for each RAM bank as indicated by
// ARM linker to stdout.
static void DisplayRAMBanks(void) {
@@ -403,6 +405,7 @@
printf(" RAM1 = %u\r\n", (unsigned int)&Image$$RW_IRAM3$$ZI$$Limit -
(unsigned int)&Image$$RW_IRAM3$$Base);
}
+//#endif
/** Main function, where all the magic starts
*/
@@ -413,12 +416,13 @@
printf(VERSION_INFO);
printf("\n");
-
DisplayRAMBanks();
+#ifdef DEBUG
printf("Setting up...\n");
printf("\nHEAP STATS\n");
__heapstats((__heapprt)fprintf,stderr);
+#endif
if ( !readConfig() ) {
error("Setup failed");
@@ -485,19 +489,22 @@
}
rtr.initRouting();
-
+#ifdef DEBUG
printf("Setup OK\n");
printf( "Setting RFM12B ID %d, Band %d Group %d\n",rfm12bId, rfm12bBand, rfm12bGroup);
+#endif
+
rfm12b.init(rfm12bId, rfm12bBand, rfm12bGroup ); //id = 2, band 866, group 5
- printf("Listening...\n");
+// printf("Listening...\n");
Timer tm;
tm.start();
-
+#ifdef DEBUG
printf("\nHEAP STATS\n");
__heapstats((__heapprt)fprintf,stderr);
+#endif
short dataLen = 0;
uint8_t *rf12Buf;
@@ -526,9 +533,9 @@
if ((rf12Buf[1] & ~RF12_HDR_MASK) == RF12_HDR_ACK // &&
//(config.nodeId & 0x20) == 0
) {
-
+#ifdef DEBUG
printf("RFM12B -> ack\n");
-
+#endif
byte addr = rf12Buf[1] & RF12_HDR_MASK;
rfm12b.rf12_sendStart(RF12_HDR_CTL | RF12_HDR_DST | addr, 0, 1);
}