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:
- 4:d460406ac780
- Parent:
- 3:f19f9c62c00b
- Child:
- 5:0dbc27a7af55
--- a/main.cpp Fri Apr 20 19:32:34 2012 +0000 +++ b/main.cpp Tue May 01 21:43:40 2012 +0000 @@ -36,7 +36,6 @@ * Sample configuration file IOTSETUP.TXT * * @code - * pachube.key=***your pachube api key*** * ip.mode=fixed * ip.address=192.168.1.99 * ip.netmask=255.255.255.0 @@ -48,6 +47,12 @@ * time.host=0.uk.pool.ntp.org * time.timezone=GMT * time.dst=yes + * pachube.key=***your Pachube api key*** + * pachube.apiurl=http://api.pachube.com/v2/feeds/%d.csv?_method=PUT + * emoncms.key=***your emonCms api key*** + * emoncms.apiurl=http://your.host.com/emoncms/api/post?apikey=%s&json= + * sense.key=***your Sen.se api key*** + * sense.apiurl=http://api.sen.se/events/?sense_key=%s * mqtt.host= * mqtt.port=1883 * mqtt.username= @@ -70,7 +75,7 @@ using std::string; -#define VERSION_INFO "IoT Gateway Basic - Version 0.6-BETA " +#define VERSION_INFO "IoT Gateway Basic - Version 0.7-BETA " DigitalOut heartbeatLED(LED1, "heartbeatLED"); DigitalOut led2(LED2, "led2"); @@ -101,10 +106,14 @@ #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; +__attribute((section("AHBSRAM0"))) static OutputSenSe outSenSe; __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]; // MQTT config __attribute((section("AHBSRAM0"))) IpAddr mqttHostAddress( 0, 0, 0, 0); @@ -115,10 +124,19 @@ //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]; + +// Open energy Monitor Sen.Se config +__attribute((section("AHBSRAM0"))) char senSeApiUrl[128]; +__attribute((section("AHBSRAM0"))) char senSeApiKey[65]; +__attribute((section("AHBSRAM0"))) char senSeDataBuffer[200]; + // Time server config __attribute((section("AHBSRAM0"))) char ntpHost[MAX_LINE_LENGTH] = "0.uk.pool.ntp.org"; - // RFM12B config __attribute((section("AHBSRAM0"))) static string rfm12bBands[4] = {"xxx", "433", "868", "915" }; __attribute((section("AHBSRAM0"))) static uint8_t rfm12bId; @@ -229,9 +247,9 @@ // read file while (!feof( fp )) { fgets(lineBuf,MAX_LINE_LENGTH,fp); - printf("[%s] ",lineBuf); +// printf("[%s] ",lineBuf); trim( lineBuf ); - printf("[%s]\n", lineBuf); +// printf("[%s]\n", lineBuf); // Need to read each entry and update config char *nameStr; @@ -263,9 +281,23 @@ } else if ( strcmp( nameStr, "time.host" ) == 0 ) { strcpynull(ntpHost, valueStr ); + } else if ( strcmp( nameStr, "pachube.apiurl" ) == 0 ) { + strcpynull(pachubeApiUrl, valueStr ); + } else if ( strcmp( nameStr, "pachube.key" ) == 0 ) { strcpynull(pachubeApiKey, valueStr ); + } else if ( strcmp( nameStr, "emoncms.apiurl" ) == 0 ) { + strcpynull(emonCmsApiUrl, valueStr ); + + } else if ( strcmp( nameStr, "emoncms.key" ) == 0 ) { + strcpynull(emonCmsApiKey, valueStr ); + + } else if ( strcmp( nameStr, "sense.apiurl" ) == 0 ) { + strcpynull(senSeApiUrl, valueStr ); + + } else if ( strcmp( nameStr, "sense.key" ) == 0 ) { + strcpynull(senSeApiKey, valueStr ); } else if ( strcmp( nameStr, "mqtt.host" ) == 0 ) { setIpAddress( &tmpAddress[0], valueStr ); mqttHostAddress = IpAddr( tmpAddress[0],tmpAddress[1],tmpAddress[2],tmpAddress[3]); @@ -419,14 +451,26 @@ time_t ctTime = time(NULL); printf("\nTime is now (UTC): %s\n", ctime(&ctTime)); + // If Pachube API Key defined, set up output module if ( strlen(pachubeApiKey) > 0 ) { - // Only add Pachube output if a key has been defined - outPachube = OutputPachube(); - outPachube.setApiKey( pachubeApiKey ); + outPachube = OutputPachube( pachubeDataBuffer, pachubeApiUrl, pachubeApiKey ); +// outPachube.setApiKey( pachubeApiKey ); // printf("MAIN: outPachube = %ld\n",(int)&outPachube); rtr.addOutput( (OutputDef*)&outPachube , OUTPUT_TYPE_PACHUBE); } + // If emonCms API Key defined, set up output module + if ( strlen(emonCmsApiKey) > 0 ) { + outEmonCms = OutputEmonCms( emonCmsDataBuffer, emonCmsApiUrl, emonCmsApiKey ); + rtr.addOutput( (OutputDef*)&outEmonCms , OUTPUT_TYPE_EMONCMS); + } + + // If Sen.se API Key defined, set up output module + if ( strlen(senSeApiKey) > 0 ) { + outSenSe = OutputSenSe( senSeDataBuffer, senSeApiUrl, senSeApiKey ); + rtr.addOutput( (OutputDef*)&outSenSe , OUTPUT_TYPE_SENSE); + } + //mqttHostAddress = IpAddr(192,168,1,77); OutputMqtt outMqtt = OutputMqtt(); // mqttHostAddress = resolver.resolveName("api.pachube.com");