https://github.com/ryantm/attcarhomehackathon

Dependencies:   EthernetInterface LM75B M2XStreamClient jsonlite mbed-rtos mbed

Dependents:   clothesItReceiver

Fork of m2x-demo-all by AT&T M2X Team

Committer:
buf006
Date:
Sun Sep 07 23:22:50 2014 +0000
Revision:
2:3bec0454c754
Parent:
1:225ed64c9353
added led debugging

Who changed what in which revision?

UserRevisionLine numberNew contents of line
jb8414 0:38a7a8cae773 1 #include <jsonlite.h>
jb8414 0:38a7a8cae773 2 #include "M2XStreamClient.h"
jb8414 0:38a7a8cae773 3
jb8414 0:38a7a8cae773 4 #include "mbed.h"
jb8414 0:38a7a8cae773 5 #include "EthernetInterface.h"
jb8414 0:38a7a8cae773 6 #include "LM75B.h" //I2C Temperature Sensor
jb8414 0:38a7a8cae773 7
buf006 1:225ed64c9353 8
buf006 1:225ed64c9353 9 char feedId[] = "c6eabf437b8c69efbb4e4a8d5c60c04d"; // Feed you want to post to
buf006 1:225ed64c9353 10 char m2xKey[] = "10bc8a4dc4a37c5dc549b41ffaa6d6c1"; // Your M2X access key
buf006 1:225ed64c9353 11 char streamName[] = "danger_bit"; // Stream you want to post to
buf006 1:225ed64c9353 12
buf006 1:225ed64c9353 13 DigitalOut garage(PTB9);
buf006 2:3bec0454c754 14 DigitalOut led(LED_RED);
buf006 2:3bec0454c754 15 DigitalOut bled(LED_BLUE);
buf006 1:225ed64c9353 16
buf006 1:225ed64c9353 17 /*
buf006 1:225ed64c9353 18 char feeidId[] = "08a3bceeee7e7bfa32340aadd282ea23"; // Feed you want to post to
buf006 1:225ed64c9353 19 char m2xKey[] = "41e5905679b7a6fa668303e00da65826"; // Your M2X access key
buf006 1:225ed64c9353 20 char streamName[] = "garagecommand"; // Stream you want to post to
buf006 1:225ed64c9353 21 */
buf006 1:225ed64c9353 22 int danger = 0;
jb8414 0:38a7a8cae773 23
jb8414 0:38a7a8cae773 24 Client client;
jb8414 0:38a7a8cae773 25 M2XStreamClient m2xClient(&client, m2xKey);
jb8414 0:38a7a8cae773 26
jb8414 0:38a7a8cae773 27 EthernetInterface eth;
jb8414 0:38a7a8cae773 28
jb8414 0:38a7a8cae773 29 void on_data_point_found(const char* at, const char* value, int index, void* context) {
jb8414 0:38a7a8cae773 30 printf("Found a data point, index: %d\r\n", index);
jb8414 0:38a7a8cae773 31 printf("At: %s Value: %s\r\n", at, value);
buf006 1:225ed64c9353 32
buf006 1:225ed64c9353 33 if(index == 0)
buf006 1:225ed64c9353 34 {
buf006 1:225ed64c9353 35 danger = atoi(value);
buf006 1:225ed64c9353 36
buf006 1:225ed64c9353 37 if (danger == 1)
buf006 1:225ed64c9353 38 {
buf006 1:225ed64c9353 39 printf("Carbonmonoxide levels are dangerous. \n");
buf006 1:225ed64c9353 40 garage = 0;
buf006 1:225ed64c9353 41
buf006 1:225ed64c9353 42 }
buf006 1:225ed64c9353 43
buf006 2:3bec0454c754 44 if (danger == 0)
buf006 2:3bec0454c754 45 {
buf006 2:3bec0454c754 46 garage = 1;
buf006 2:3bec0454c754 47 }
buf006 2:3bec0454c754 48
buf006 1:225ed64c9353 49 }
jb8414 0:38a7a8cae773 50 }
jb8414 0:38a7a8cae773 51
jb8414 0:38a7a8cae773 52 void on_location_found(const char* name,
jb8414 0:38a7a8cae773 53 double latitude,
jb8414 0:38a7a8cae773 54 double longitude,
jb8414 0:38a7a8cae773 55 double elevation,
jb8414 0:38a7a8cae773 56 const char* timestamp,
jb8414 0:38a7a8cae773 57 int index,
jb8414 0:38a7a8cae773 58 void* context) {
jb8414 0:38a7a8cae773 59 printf("Found a location, index: %d\r\n", index);
jb8414 0:38a7a8cae773 60 printf("Name: %s Latitude: %lf Longitude: %lf\r\n", name, latitude, longitude);
jb8414 0:38a7a8cae773 61 printf("Elevation: %lf Timestamp: %s\r\n", elevation, timestamp);
jb8414 0:38a7a8cae773 62 }
jb8414 0:38a7a8cae773 63
jb8414 0:38a7a8cae773 64 int main() {
buf006 2:3bec0454c754 65 garage = 1;
buf006 2:3bec0454c754 66 led = 0;
buf006 2:3bec0454c754 67
jb8414 0:38a7a8cae773 68 eth.init();
jb8414 0:38a7a8cae773 69 eth.connect();
jb8414 0:38a7a8cae773 70 printf("IP Address: %s\r\n", eth.getIPAddress());
jb8414 0:38a7a8cae773 71
jb8414 0:38a7a8cae773 72 char amb_temp[6];
jb8414 0:38a7a8cae773 73
buf006 1:225ed64c9353 74
jb8414 0:38a7a8cae773 75 while (true) {
jb8414 0:38a7a8cae773 76
jb8414 0:38a7a8cae773 77 // read temperature
buf006 2:3bec0454c754 78 int response = m2xClient.fetchValues(feedId, streamName, on_data_point_found, NULL, NULL, NULL, "1");
jb8414 0:38a7a8cae773 79 printf("Fetch response code: %d\r\n", response);
buf006 2:3bec0454c754 80 if (response == -1)
buf006 2:3bec0454c754 81 bled = 0;
buf006 2:3bec0454c754 82 else
buf006 2:3bec0454c754 83 bled = 1;
jb8414 0:38a7a8cae773 84
buf006 2:3bec0454c754 85 led = !led;
jb8414 0:38a7a8cae773 86
buf006 1:225ed64c9353 87 // wait 5 secs and then loop
buf006 2:3bec0454c754 88 delay(2000);
jb8414 0:38a7a8cae773 89 }
jb8414 0:38a7a8cae773 90 }