AT&T example LPC1768
Dependencies: EthernetInterface M2XStreamClient jsonlite mbed-rtos mbed
Fork of m2x-demo-all by
main.cpp@1:88ff5e1fd66f, 2018-03-22 (annotated)
- Committer:
- brdarji
- Date:
- Thu Mar 22 07:57:42 2018 +0000
- Revision:
- 1:88ff5e1fd66f
- Parent:
- 0:38a7a8cae773
At&T example lpc1768
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
brdarji | 1:88ff5e1fd66f | 1 | #define MBED_PLATFORM |
brdarji | 1:88ff5e1fd66f | 2 | |
jb8414 | 0:38a7a8cae773 | 3 | #include <jsonlite.h> |
jb8414 | 0:38a7a8cae773 | 4 | #include "M2XStreamClient.h" |
jb8414 | 0:38a7a8cae773 | 5 | |
jb8414 | 0:38a7a8cae773 | 6 | #include "mbed.h" |
jb8414 | 0:38a7a8cae773 | 7 | #include "EthernetInterface.h" |
brdarji | 1:88ff5e1fd66f | 8 | |
brdarji | 1:88ff5e1fd66f | 9 | char deviceId[] = "8f4eeb39f1cb1dc95699bfa266e57662"; // Device you want to push to |
brdarji | 1:88ff5e1fd66f | 10 | char streamName[] = "temp_data"; // Stream you want to push to |
brdarji | 1:88ff5e1fd66f | 11 | char m2xKey[] = "4c3ba5e22fc074d4358888afbe96efa7"; // Your M2X API Key or Master API Key |
jb8414 | 0:38a7a8cae773 | 12 | |
brdarji | 1:88ff5e1fd66f | 13 | // For Static IP |
brdarji | 1:88ff5e1fd66f | 14 | static const char* mbedIp = "192.168.0.85"; //IP |
brdarji | 1:88ff5e1fd66f | 15 | static const char* mbedMask = "255.255.255.0"; // Mask |
brdarji | 1:88ff5e1fd66f | 16 | static const char* mbedGateway = "192.168.0.254"; //Gateway |
jb8414 | 0:38a7a8cae773 | 17 | |
jb8414 | 0:38a7a8cae773 | 18 | Client client; |
jb8414 | 0:38a7a8cae773 | 19 | M2XStreamClient m2xClient(&client, m2xKey); |
jb8414 | 0:38a7a8cae773 | 20 | |
jb8414 | 0:38a7a8cae773 | 21 | EthernetInterface eth; |
jb8414 | 0:38a7a8cae773 | 22 | |
jb8414 | 0:38a7a8cae773 | 23 | |
jb8414 | 0:38a7a8cae773 | 24 | int main() { |
brdarji | 1:88ff5e1fd66f | 25 | float data = 32.5; |
brdarji | 1:88ff5e1fd66f | 26 | |
brdarji | 1:88ff5e1fd66f | 27 | eth.init(mbedIp,mbedMask,mbedGateway); |
jb8414 | 0:38a7a8cae773 | 28 | eth.connect(); |
brdarji | 1:88ff5e1fd66f | 29 | printf("IP Address: %s\n", eth.getIPAddress()); |
jb8414 | 0:38a7a8cae773 | 30 | |
jb8414 | 0:38a7a8cae773 | 31 | while (true) { |
brdarji | 1:88ff5e1fd66f | 32 | double val = data; |
brdarji | 1:88ff5e1fd66f | 33 | printf("Current temperature is: %lf", val); |
brdarji | 1:88ff5e1fd66f | 34 | |
brdarji | 1:88ff5e1fd66f | 35 | int response = m2xClient.updateStreamValue(deviceId, streamName, val); |
brdarji | 1:88ff5e1fd66f | 36 | printf("Response code: %d\n", response); |
brdarji | 1:88ff5e1fd66f | 37 | |
jb8414 | 0:38a7a8cae773 | 38 | if (response == -1) while (true) ; |
jb8414 | 0:38a7a8cae773 | 39 | |
brdarji | 1:88ff5e1fd66f | 40 | delay(5000); |
jb8414 | 0:38a7a8cae773 | 41 | } |
jb8414 | 0:38a7a8cae773 | 42 | } |