AT&T M2X example featuring FRDM-K64F and Seed Grove Wifi to stream the Accelerometer X, Y, Z-axis values
Dependencies: ESP8266Interface FXOS8700Q M2XStreamClient jsonlite mbed
Fork of frdm-k64F_Wifi_M2X_Acc by
main.cpp@6:ec30a917efa8, 2016-10-17 (annotated)
- Committer:
- GregC
- Date:
- Mon Oct 17 21:10:15 2016 +0000
- Revision:
- 6:ec30a917efa8
- Parent:
- 5:2f6125e8ee48
AT&T M2X example featuring FRDM-K64F and Seed Grove Wifi to stream the Accelerometer X, Y, Z-axis values
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
jb8414 | 0:ece599ab76bb | 1 | #include "mbed.h" |
jb8414 | 0:ece599ab76bb | 2 | #include "FXOS8700Q.h" |
jb8414 | 0:ece599ab76bb | 3 | #include "M2XStreamClient.h" |
mbedAustin | 3:694a1a67b156 | 4 | #include "ESP8266Interface.h" |
mbedAustin | 3:694a1a67b156 | 5 | #include "TCPSocketConnection.h" |
jb8414 | 0:ece599ab76bb | 6 | |
jb8414 | 0:ece599ab76bb | 7 | |
jb8414 | 0:ece599ab76bb | 8 | #ifndef MAX |
jb8414 | 0:ece599ab76bb | 9 | #define max(a,b) ({ __typeof__ (a) _a = (a); __typeof__ (b) _b = (b); _a > _b ? _a : _b; }) |
jb8414 | 0:ece599ab76bb | 10 | #endif |
jb8414 | 0:ece599ab76bb | 11 | |
jb8414 | 0:ece599ab76bb | 12 | #ifndef MIN |
jb8414 | 0:ece599ab76bb | 13 | #define min(a,b) ({ __typeof__ (a) _a = (a); __typeof__ (b) _b = (b); _a < _b ? _a : _b; }) |
jb8414 | 0:ece599ab76bb | 14 | #endif |
jb8414 | 0:ece599ab76bb | 15 | |
GregC | 5:2f6125e8ee48 | 16 | char deviceId[] = "<deviceId>"; // Device you want to push to |
GregC | 5:2f6125e8ee48 | 17 | char streamName[] = "<streamName>"; // Stream you want to push to |
GregC | 5:2f6125e8ee48 | 18 | char m2xKey[] = "<m2xKey>"; // Your M2X API Key or Master API Key |
jb8414 | 0:ece599ab76bb | 19 | |
mbedAustin | 3:694a1a67b156 | 20 | /* |
mbedAustin | 4:3c1d712dcc48 | 21 | * ESP8266 Wifi Config, connect it to D0 on Seeed Grove shield |
mbedAustin | 3:694a1a67b156 | 22 | */ |
GregC | 6:ec30a917efa8 | 23 | ESP8266Interface wifi(D1,D0,D3,"wifi SSID","wifi PASSWORD",115200); // TX,RX,Reset,SSID,Password,Baud |
mbedAustin | 3:694a1a67b156 | 24 | |
jb8414 | 0:ece599ab76bb | 25 | int main() |
jb8414 | 0:ece599ab76bb | 26 | { |
mbedAustin | 3:694a1a67b156 | 27 | printf("Starting...\r\n"); |
mbedAustin | 3:694a1a67b156 | 28 | |
mbedAustin | 3:694a1a67b156 | 29 | // connect to wifi |
mbedAustin | 3:694a1a67b156 | 30 | wifi.init(); //Reset |
mbedAustin | 3:694a1a67b156 | 31 | wifi.connect(); //Use DHCP |
mbedAustin | 3:694a1a67b156 | 32 | printf("IP Address is %s \n\r", wifi.getIPAddress()); |
jb8414 | 0:ece599ab76bb | 33 | |
jb8414 | 0:ece599ab76bb | 34 | // Initialize the M2X client |
jb8414 | 0:ece599ab76bb | 35 | Client client; |
mbedAustin | 3:694a1a67b156 | 36 | M2XStreamClient m2xClient(&client, m2xKey,1,"52.22.150.98"); |
jb8414 | 0:ece599ab76bb | 37 | int ret; |
jb8414 | 0:ece599ab76bb | 38 | |
jb8414 | 0:ece599ab76bb | 39 | // Create an accelerometer instance |
jb8414 | 0:ece599ab76bb | 40 | FXOS8700Q_acc acc( PTE25, PTE24, FXOS8700CQ_SLAVE_ADDR1); // Proper Ports and I2C Address for K64F Freedom board |
jb8414 | 0:ece599ab76bb | 41 | acc.enable(); |
jb8414 | 0:ece599ab76bb | 42 | printf("\r\n\nFXOS8700Q Who Am I= %X\r\n", acc.whoAmI()); |
jb8414 | 0:ece599ab76bb | 43 | |
jb8414 | 0:ece599ab76bb | 44 | while (true) { |
jb8414 | 0:ece599ab76bb | 45 | |
jb8414 | 0:ece599ab76bb | 46 | float x, y, z; |
jb8414 | 0:ece599ab76bb | 47 | acc.getX(&x); |
jb8414 | 0:ece599ab76bb | 48 | acc.getY(&y); |
jb8414 | 0:ece599ab76bb | 49 | acc.getZ(&z); |
jb8414 | 0:ece599ab76bb | 50 | |
jb8414 | 0:ece599ab76bb | 51 | printf("Accel X: %1.2f, Y: %1.2f, Z: %1.2f\n\r", x, y, z); |
jb8414 | 0:ece599ab76bb | 52 | |
GregC | 5:2f6125e8ee48 | 53 | // Send data to stream |
mbedAustin | 3:694a1a67b156 | 54 | |
GregC | 5:2f6125e8ee48 | 55 | ret = m2xClient.updateStreamValue(deviceId, streamName, x); |
GregC | 5:2f6125e8ee48 | 56 | ret = m2xClient.updateStreamValue(deviceId, streamName, y); |
GregC | 5:2f6125e8ee48 | 57 | ret = m2xClient.updateStreamValue(deviceId, streamName, z); |
jb8414 | 0:ece599ab76bb | 58 | printf("send() returned %d\r\n", ret); |
jb8414 | 2:68b759c89fd9 | 59 | wait(1.0); |
mbedAustin | 3:694a1a67b156 | 60 | |
jb8414 | 0:ece599ab76bb | 61 | } |
jb8414 | 0:ece599ab76bb | 62 | } |