Ethernet communication for biomedical purposes

Dependencies:   C12832_lcd EthernetNetIf HTTPClient_ToBeRemoved mbed

Fork of TwitterExample by Donatien Garnier

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers TwitterExample.cpp Source File

TwitterExample.cpp

00001 #include "mbed.h"
00002 #include "EthernetNetIf.h"
00003 #include "HTTPClient.h"
00004 #include "C12832_lcd.h"
00005  
00006  // http://mbed.org/forum/mbed/topic/2238/
00007  //
00008  //
00009  //
00010  
00011 
00012 EthernetNetIf eth; 
00013 HTTPClient http;
00014 C12832_LCD lcd;
00015 
00016 //char[] ip = "192.168.200.183";
00017 //char[] site = "http://"+ip+"/Ethernet/watmeetik.txt";
00018   
00019 int main() {
00020  
00021   // SETUP ETHERNET CONNECTION
00022   lcd.printf("Start\n");
00023   wait(1);
00024   lcd.printf("\r\nSetting up...\r\n");
00025   EthernetErr ethErr = eth.setup();
00026   if(ethErr)
00027   {
00028     lcd.printf("Error %d in setup.\n", ethErr);
00029     return -1;
00030   }
00031   lcd.printf("\r\nSetup OK\r\n");
00032   
00033   
00034   // GET HTTP REQUEST
00035   HTTPText txt;
00036   
00037   HTTPResult r = http.get("http://192.168.200.183/Ethernet/watmeetik.txt", &txt);
00038   if(r==HTTP_OK)
00039   {
00040     lcd.printf("Result :\"%s\"\n", txt.gets()); 
00041   }
00042   else
00043   {
00044     lcd.printf("Error %d\n", r);
00045   }
00046   
00047   wait(1);
00048   lcd.cls();
00049   lcd.printf("\nPOST\n");
00050   wait(1);
00051   
00052   
00053     // POST HTTP REQUEST
00054     HTTPMap msg;
00055     msg["m1"] = "test1";
00056     //http.basicAuth("gast","gast");
00057     HTTPResult r2 = http.post("http://192.168.200.183/Ethernet/resultaten.txt", msg, NULL);
00058     
00059     if (r2 == HTTP_OK)
00060     { 
00061         lcd.printf("Update succesful\n");
00062     }
00063     else
00064     {
00065         printf("problem occured, returncode%d\n",r2);
00066     }
00067    
00068   
00069   
00070   
00071   while(1){}
00072 
00073   
00074   return 0;
00075   
00076 }