![](/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:
- 2015-01-20
- Revision:
- 2:8907a25944ab
- Parent:
- 1:ae20607dd0c1
- Child:
- 4:d6e87aea518f
File content as of revision 2:8907a25944ab:
#include "mbed.h" #include "EthernetInterface.h" #include "HTTPClient.h" #include "C12832_lcd.h" EthernetInterface eth; HTTPClient http; #define CIK "0000000000000000000000000000000000000000" #define WRITE_ALIAS "temp" #define READ_ALIASES "?screen" char EXO_CIK_HDR[] = "X-Exosite-CIK: " CIK "\r\n"; char EXO_ACCEPT_HDR[] = "Accept: application/x-www-form-urlencoded; charset=utf-8\r\n"; char EXO_CONTYP_HDR[] = "Content-Type: application/x-www-form-urlencoded; charset=utf-8\r\n"; const char EXO_URI[] = "https://m2.exosite.com:443/onep:v1/stack/alias" READ_ALIASES; // NOTE: Need to specify port due to parsing bug in lib on "onep:v1" #define TIMEOUT 2000 #define BUFFSIZE 1024 AnalogIn aPot1(p19); Timer send_timer, connection_timer, run_time; static C12832_LCD lcd; int main() { run_time.start(); send_timer.start(); connection_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 incomming_buffer[BUFFSIZE]; char outgoing_buffer[BUFFSIZE]; HTTPText read_text = HTTPText(incomming_buffer, BUFFSIZE); HTTPText write_map = HTTPText(outgoing_buffer); snprintf(outgoing_buffer, BUFFSIZE, "tempf=%0.0f", 42.37); connection_timer.reset(); printf("[%f] Sending...\r\n", run_time.read()); http.setHeader(0,EXO_CIK_HDR); http.setHeader(1,EXO_ACCEPT_HDR); http.setHeader(2,EXO_CONTYP_HDR); ret = http.post(EXO_URI, write_map, &read_text); printf("Done! Status: %d, %d\r\n", ret, http.getHTTPResponseCode()); lcd.locate(0,0); lcd.printf(" "); if (!ret) { printf("Success, Got: %s\n", incomming_buffer); lcd.locate(0,0); lcd.printf(incomming_buffer); } else { printf("Error, Got: %s\n", incomming_buffer); lcd.locate(0,0); lcd.printf(incomming_buffer); } printf("Completed in %f seconds.\r\n", connection_timer.read()); wait(5); } }