port to cellular
Dependencies: C027_Support LM75B M2XStreamClient jsonlite mbed mbed-rtos
Fork of m2x-demo-all by
main.cpp
- Committer:
- mazgch
- Date:
- 2014-05-20
- Revision:
- 3:dac7a2335ba5
- Parent:
- 2:83dd0b8109ca
- Child:
- 5:df776765d890
File content as of revision 3:dac7a2335ba5:
#include <jsonlite.h> #include "M2XStreamClient.h" #include "mbed.h" #include "LM75B.h" //I2C Temperature Sensor //------------------------------------------------------------------------------------ // You need to configure these cellular modem / SIM parameters. // These parameters are ignored for LISA-C200 variants and can be left NULL. //------------------------------------------------------------------------------------ #include "MDM.h" //! Set your secret SIM pin here (e.g. "1234"). Check your SIM manual. #define SIMPIN NULL /*! The APN of your network operator SIM, sometimes it is "internet" check your contract with the network operator. You can also try to look-up your settings in google: https://www.google.de/search?q=APN+list */ #define APN "gprs.swisscom.ch" //! Set the user name for your APN, or NULL if not needed #define USERNAME NULL //! Set the password for your APN, or NULL if not needed #define PASSWORD NULL //------------------------------------------------------------------------------------ char feedId[] = "<feed id>"; // Feed you want to post to char m2xKey[] = "<m2x api key>"; // Your M2X access key char streamName[] = "<stream name>"; // Stream you want to post to char name[] = "<location name>"; // Name of current location of datasource double latitude = 33.007872; double longitude = -96.751614; // You can also read those values from a GPS double elevation = 697.00; Client client; M2XStreamClient m2xClient(&client, m2xKey); LM75B tmp(SDA,SCL); // I2C Temperature Sensor void on_data_point_found(const char* at, const char* value, int index, void* context) { printf("Found a data point, index: %d\r\n", index); printf("At: %s Value: %s\r\n", at, value); } void on_location_found(const char* name, double latitude, double longitude, double elevation, const char* timestamp, int index, void* context) { printf("Found a location, index: %d\r\n", index); printf("Name: %s Latitude: %lf Longitude: %lf\r\n", name, latitude, longitude); printf("Elevation: %lf Timestamp: %s\r\n", elevation, timestamp); } int main() { MDMSerial mdm; //mdm.setDebug(4); // enable this for debugging issues if (!mdm.connect(SIMPIN, APN,USERNAME,PASSWORD)) return -1; char amb_temp[6]; while (true) { // read temp sprintf(amb_temp, "%0.2f", tmp.read()); // post temperature int response = m2xClient.post(feedId, streamName, amb_temp); printf("Post response code: %d\r\n", response); if (response == -1) while (true) ; // read temperature response = m2xClient.fetchValues(feedId, streamName, on_data_point_found, NULL); printf("Fetch response code: %d\r\n", response); if (response == -1) while (true) ; // update location response = m2xClient.updateLocation(feedId, name, latitude, longitude, elevation); printf("updateLocation response code: %d\r\n", response); if (response == -1) while (true) ; // read location response = m2xClient.readLocation(feedId, on_location_found, NULL); printf("readLocation response code: %d\r\n", response); if (response == -1) while (true) ; // wait 60 secs and then loop delay(60000); } mdm.disconnect(); mdm.powerOff(); }