![](/media/cache/group/default_image.jpg.50x50_q85.jpg)
A basic example of using the mbed NXP LPC1768 Application Board with Exosite.
Dependencies: C12832_lcd EthernetInterface HTTPClient LM75B MMA7660 RGBLed mbed-rtos mbed
Fork of exosite_http_example by
main.cpp
- Committer:
- PBarrett
- Date:
- 2014-05-02
- Revision:
- 1:ae20607dd0c1
- Parent:
- 0:30a991e08e77
- Child:
- 2:8907a25944ab
File content as of revision 1:ae20607dd0c1:
#include "mbed.h" #include "EthernetInterface.h" #include "C12832_lcd.h" EthernetInterface eth; char CIK[] = "c85bec1649f3450667f918305dc33b85af024686"; // patrick's "mbed Dev Board" AnalogIn aPot1(p19); Timer send_timer, run_time; static C12832_LCD lcd; int main() { run_time.start(); send_timer.start(); printf("\r\nStart\r\n"); eth.init(); //Use DHCP lcd.printf("Exosite HTTP Cloud Demo"); lcd.locate(0,11); lcd.printf("MAC: %s", eth.getMACAddress()); lcd.locate(0,22); lcd.printf("IP: Requesting From DHCP..."); eth.connect(); printf("IP Address is %s\r\n", eth.getIPAddress()); printf("MAC Address is %s\r\n", eth.getMACAddress()); lcd.locate(0,22); lcd.printf("IP: %s ", eth.getIPAddress()); printf("[%f] Running...\r\n", run_time.read()); while (1) { int ret; char post_data [70]; int len = snprintf(post_data, 69, "uptime=%0.0f&tempa=128",run_time.read()); printf("[%f] Connecting...\r\n", run_time.read()); TCPSocketConnection sock; //ret = sock.connect("192.168.3.147", 8090); ret = sock.connect("m2.exosite.com", 80); if (ret == -1) { printf("[%f] Error Connecting to Server\r\n", run_time.read()); continue; } printf("[%f] Sending...\r\n", run_time.read()); char header_tmp[80] = "POST /api:v1/stack/alias?screen HTTP/1.1\r\n"; sock.send(header_tmp, strlen(header_tmp)); sock.send("Host: m2.exosite.com\r\n", strlen("Host: m2.exosite.com\r\n")); snprintf(header_tmp, 79, "X-Exosite-CIK: %s\r\n", CIK); sock.send(header_tmp, strlen(header_tmp)); sock.send("Accept: application/x-www-form-urlencoded; charset=utf-8\r\n", strlen("Accept: application/x-www-form-urlencoded; charset=utf-8\r\n")); sock.send("Content-Type: application/x-www-form-urlencoded; charset=utf-8\r\n", strlen("Content-Type: application/x-www-form-urlencoded; charset=utf-8\r\n")); sock.send("Connection: close\r\n", strlen("Connection: close\r\n")); snprintf(header_tmp, 79, "Content-Length: %i\r\n", strlen(post_data)); sock.send(header_tmp, strlen(header_tmp)); sock.send("\r\n", strlen("\r\n")); sock.send_all(post_data, strlen(post_data)); printf("[%f] Receiving...\r\n", run_time.read()); char buffer[300]; ret = sock.receive_all(buffer, 300); if(ret >= 0){ printf("Received %d chars from server:\r\n%.*s\r\n", ret, ret, buffer); }else{ printf("Error Receiving"); } sock.close(); wait(5); } }