mbed IoT Gateway board demo. This program received wireless data from JeeNode and uploads to Pachube. http://www.skpang.co.uk/catalog/mbed-iot-gateway-board-p-1051.html Full kit: http://www.skpang.co.uk/catalog/mbed-iot-gateway-full-kit-p-1052.html

Dependencies:   EthernetNetIf mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 /*
00002 mbed IoT Gateway demo
00003 
00004 This is a demo program to read data from a JeeNode and upload to Pachube.
00005 
00006 http://www.skpang.co.uk/catalog/mbed-iot-gateway-board-p-1051.html
00007 
00008 Jan 2012 skpang.co.uk
00009 */
00010 #include "mbed.h"
00011 #include "RF12B.h"
00012 #include "PachubeV2CSV.h"
00013 #include "EthernetNetIf.h"
00014 #include "HTTPClient.h"
00015  
00016 #define API_KEY "F8Gcwdhx2PvIdUrcGa84hbgBK6NC88yYUp1FxHG6f4E"
00017 #define FEED_ID 40980
00018 #define STREAM_ID "1"
00019 
00020 PachubeV2CSV web(API_KEY);
00021 EthernetNetIf eth;
00022 
00023 DigitalOut myled(LED1);
00024 
00025 DigitalOut led(p25);
00026 RF12B radiolink(p11, p12, p13, p14, p18);
00027 
00028 Serial pc(USBTX, USBRX); // tx, rx
00029 
00030 int main() {
00031    const int feed_id = FEED_ID;
00032    const std::string stream_id = STREAM_ID;
00033    float payload;
00034  
00035    char val1_text[32];
00036       
00037     led = 1;
00038     pc.baud(115200);
00039     printf("RF12B test with Pachube\r\n");
00040   
00041     eth.setup();
00042    
00043     radiolink.init(2,2,1);   //id = 2, band 869, group 1
00044 
00045     led = 0;
00046     
00047     while(1) {
00048    
00049                  
00050     if (radiolink.rf12_recvDone() && (radiolink.check_crc() == 0)) // && rf12_crc == 0 && rf12_len == sizeof payload)
00051     {
00052      led = 1;
00053         // Copy the received data into payload:
00054         memcpy(&payload, (uint8_t*) radiolink.get_data(), sizeof(payload));
00055 
00056         // Print it out:
00057         printf("  payload: %f ", payload);
00058         sprintf(val1_text, "%f", payload);
00059      
00060         printf("updateDataStream(%d)\n", web.updateDataStream(feed_id, stream_id, std::string(val1_text)));
00061          
00062         led = 0; 
00063    }
00064          myled = 1;
00065       //  wait(0.1);
00066         myled = 0;
00067      
00068     }
00069 }