Working version 1.0 of Clothes-It Receiver

Dependencies:   EthernetInterface LM75B M2XStreamClient carbon_home_module jsonlite mbed-rtos mbed

Fork of carbon_home_module by Jeremy Feliciano

Committer:
buf006
Date:
Sun Jan 04 23:04:19 2015 +0000
Revision:
3:6fa1107c6129
Parent:
2:3bec0454c754
working version of Clothes-It receiver;

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 3:6fa1107c6129 8 char feedId[] = "bb84147dbab191356d0b5fb090c19a9e"; // Feed you want to post to
buf006 3:6fa1107c6129 9 char m2xKey[] = "f68404a95d271e5d81c4d7f9224cbd8d"; // Your M2X access key
buf006 3:6fa1107c6129 10 char streamNameShirt[] = "shirtposition"; // Stream you want to post to
buf006 3:6fa1107c6129 11 char streamNamePants[] = "pantsposition";
buf006 1:225ed64c9353 12
buf006 2:3bec0454c754 13 DigitalOut led(LED_RED);
buf006 2:3bec0454c754 14 DigitalOut bled(LED_BLUE);
buf006 1:225ed64c9353 15
buf006 3:6fa1107c6129 16 Serial uart0(USBTX, USBRX);
buf006 3:6fa1107c6129 17 Serial uart3(PTC17, PTC16);
buf006 3:6fa1107c6129 18
buf006 3:6fa1107c6129 19 int shirtPosition = 0;
buf006 3:6fa1107c6129 20 int pantsPosition = 0;
buf006 3:6fa1107c6129 21
buf006 3:6fa1107c6129 22 int topPackage = 0;
buf006 3:6fa1107c6129 23 int bottomPackage = 0;
buf006 3:6fa1107c6129 24 int totalPackage = 0;
jb8414 0:38a7a8cae773 25
jb8414 0:38a7a8cae773 26 Client client;
jb8414 0:38a7a8cae773 27 M2XStreamClient m2xClient(&client, m2xKey);
jb8414 0:38a7a8cae773 28
jb8414 0:38a7a8cae773 29 EthernetInterface eth;
jb8414 0:38a7a8cae773 30
buf006 3:6fa1107c6129 31 void on_data_point_found_shirt(const char* at,const char* value, int index, void* context) {
buf006 3:6fa1107c6129 32 //printf("Found a data point, index: %d\r\n", index);
buf006 3:6fa1107c6129 33 //printf("At: %s Value: %s\r\n", at, value);
buf006 1:225ed64c9353 34
buf006 1:225ed64c9353 35 if(index == 0)
buf006 1:225ed64c9353 36 {
buf006 3:6fa1107c6129 37 shirtPosition = atoi(value);
buf006 1:225ed64c9353 38
buf006 3:6fa1107c6129 39 if(shirtPosition < 7 && shirtPosition > 0)
buf006 1:225ed64c9353 40 {
buf006 3:6fa1107c6129 41 uart0.printf("%x", shirtPosition);
buf006 3:6fa1107c6129 42 uart3.printf("%x", shirtPosition);
buf006 1:225ed64c9353 43 }
buf006 3:6fa1107c6129 44 }
buf006 3:6fa1107c6129 45 }
buf006 3:6fa1107c6129 46 void on_data_point_found_pants(const char* at,const char* value, int index, void* context) {
buf006 3:6fa1107c6129 47 //printf("Found a data point, index: %d\r\n", index);
buf006 3:6fa1107c6129 48 //printf("At: %s Value: %s\r\n", at, value);
buf006 3:6fa1107c6129 49
buf006 3:6fa1107c6129 50 if(index == 0)
buf006 3:6fa1107c6129 51 {
buf006 3:6fa1107c6129 52 pantsPosition = atoi(value) + 6;
buf006 1:225ed64c9353 53
buf006 3:6fa1107c6129 54 if(pantsPosition < 13 && pantsPosition > 6)
buf006 2:3bec0454c754 55 {
buf006 3:6fa1107c6129 56 uart0.printf("%x", pantsPosition);
buf006 3:6fa1107c6129 57 uart3.printf("%x", pantsPosition);
buf006 2:3bec0454c754 58 }
buf006 3:6fa1107c6129 59
buf006 3:6fa1107c6129 60
buf006 1:225ed64c9353 61 }
jb8414 0:38a7a8cae773 62 }
jb8414 0:38a7a8cae773 63
jb8414 0:38a7a8cae773 64 int main() {
buf006 3:6fa1107c6129 65
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());
buf006 1:225ed64c9353 71
jb8414 0:38a7a8cae773 72 while (true) {
jb8414 0:38a7a8cae773 73
buf006 3:6fa1107c6129 74
buf006 3:6fa1107c6129 75 int response1 = m2xClient.fetchValues(feedId, streamNameShirt, on_data_point_found_shirt, NULL, NULL, NULL, "1");
buf006 3:6fa1107c6129 76 int response2 = m2xClient.fetchValues(feedId, streamNamePants, on_data_point_found_pants, NULL, NULL, NULL, "1");
buf006 3:6fa1107c6129 77 //printf("Fetch response code: %d\r\n", response);
buf006 3:6fa1107c6129 78 if (response1 == -1 || response2 == -1 )
buf006 2:3bec0454c754 79 bled = 0;
buf006 2:3bec0454c754 80 else
buf006 2:3bec0454c754 81 bled = 1;
jb8414 0:38a7a8cae773 82
buf006 2:3bec0454c754 83 led = !led;
jb8414 0:38a7a8cae773 84
buf006 1:225ed64c9353 85 // wait 5 secs and then loop
buf006 3:6fa1107c6129 86 delay(2000); // was originally 2000
jb8414 0:38a7a8cae773 87 }
jb8414 0:38a7a8cae773 88 }