Mohamad Nazrin Napiah / Mbed 2 deprecated HTTPClientexample

Dependencies:   C12832_lcd EthernetInterface HTTPClient LM75B mbed-rtos mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 #include "mbed.h"
00002 #include "EthernetInterface.h"
00003 #include "LM75B.h"
00004 #include "HTTPClient.h"
00005 #include "C12832_lcd.h" // Include for LCD code
00006 
00007 LM75B tmp(p28,p27); // temperature sensor
00008 char* Server = "http://192.168.1.108/IoT/api_update.php";
00009 char* id = "1";
00010 
00011 char buffer[256];
00012 C12832_LCD lcd; //Initialize LCD Screen
00013 
00014 
00015 void ethernetSetup(){
00016    static const char*          mbedIp       = "192.168.137.2";  //IP
00017    static const char*          mbedMask     = "255.255.255.0";  // Mask
00018    static const char*          mbedGateway  = "192.168.137.1";    //Gateway
00019 
00020 EthernetInterface eth;
00021   //  eth.init(); //Use DHCP
00022     eth.init(mbedIp,mbedMask,mbedGateway); 
00023     eth.connect();
00024     printf("IP Address is %s\n", eth.getIPAddress()); // display at terminal
00025     lcd.printf("IP address: %s \n",eth.getIPAddress()); // display LCD screen
00026     
00027     }
00028     
00029 void sendToServer(){
00030     HTTPClient http;
00031     buffer[0] = 0;
00032     sprintf(buffer,"%s?id=%s&data=%2f",Server,id,tmp.read());
00033     printf("Send to %s\r\n", buffer);
00034     http.get(buffer, buffer , 10); // Execute the URL of urlBuffer
00035    // lcd.printf("Send: %s \n",buffer);
00036     }
00037 
00038 int main() {
00039     ethernetSetup();
00040       sendToServer();
00041     while(1) {
00042            wait(0.5);
00043           sendToServer();
00044            wait(0.5);
00045         }
00046 }