![](/media/cache/profiles/DalekSelfie2.jpg.50x50_q85.jpg)
mbed based IoT Gateway More details http://blog.thiseldo.co.uk/wp-filez/IoTGateway.pdf
Dependencies: NetServices FatFileSystem csv_parser mbed MQTTClient RF12B DNSResolver SDFileSystem
Diff: main.cpp
- Revision:
- 5:0dbc27a7af55
- Parent:
- 4:d460406ac780
--- 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); }