Accessing Arduino Wifi lazarus / 38-Networking and Web Programming ---------------------------------------------------------------------- Serge58 · 2017-08-06 20:38 Hello, I am trying to send some data to my arduino micro controller wifi.  This thing act as a server on my home wireless network but requires specific (and i guess proprietary) commands. For exemple, if I write the following in the address box a regular web browser while connected to the home network:   http://10.0.4.1/arduino/webserver it is a valid command for the Arduino. I can also write something similar to http://10.0.4.1/arduino/analog/1/23 and it is also valid.  This tells the Arduino Microcontroller to set its analog output 1 to 23.  Very basic. How can I send the same type of commands through a Lazarus routine? Also, after receiving the command, Arduino will send back very simple html data to share the status of its inputs ports. I will have to be able to read it back in some way before processing it. Help required. many thanks, Serge ---------------------------------------------------------------------- Almir.Bispo · 2017-08-06 20:46 Hi. You need use Synapse library with HTTPSend unit on Desktop Just do this method HTTPSend.GetText('url' , stringlist); (*url is the server and parameter to your server like this: http://arduinoserver?param1=data1¶m2=data2) stringlist is a Tstringlist class.It must be created on runtime. On Arduino code you must get the params to do something. http://adltecnologia.blogspot.com.br ---------------------------------------------------------------------- molly · 2017-08-06 21:33 Quote from: Serge58 on August 06, 2017, 10:38:49 pmHello, I am trying to send some data to my arduino micro controller wifi. ... How can I send the same type of commands through a Lazarus routine? Also, after receiving the command, Arduino will send back very simple html data to share the status of its inputs ports. I will have to be able to read it back in some way before processing it. You could perhaps use something like this: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i program arduino;uses  fphttpclient;var  s: string;begin  s := TFPCustomHTTPClient.SimpleGet('http://10.0.4.1/arduino/webserver');  WriteLn(s);  // or something like: memo1.Lines.Add(s);end.  See also here. You would need to process the returned html body manually though. ---------------------------------------------------------------------- Serge58 · 2017-08-06 22:55 Thanks both of you. I installed the synapse package.  I was getting some errors and found on the net that I had to disable a line of code in one of the unit.  After the package seems to be installed properly. No error. i tried both of your options:  First, HTTPSend.GetText is giving me some error.  i checked and it seems that there is no GetText method in the HTTPSend class. On the fphttpclient option i do not get error.  But it is not sending data (i think) and does nothing.  i have to stop it. is it possible that i needed to specify the port number somewhere?  I saw that there are many fphttpclient versions.  Is this one part of the same synapse package? Thanks both of you. my code: // Button 2 "Using fphttpclient" procedure TForm1.Button2Click(Sender: TObject);   var   str: String; begin    str := TFPCustomHTTPClient.SimpleGet('http://10.0.4.1/arduino/webserver');    ShowMessage(str); end; // Button 1 using "HTTPSend" procedure TForm1.Button1Click(Sender: TObject);    var    str: String;    Param: TStringlist; begin    Str:='http://1.0.4.1/arduino/webserver';    HTTPSend.GetText (Str , Param);    ShowMessage('Param); end; ---------------------------------------------------------------------- molly · 2017-08-06 23:15 Quote from: Serge58 on August 07, 2017, 12:55:15 amOn the fphttpclient option i do not get error.  But it is not sending data (i think) and does nothing.  i have to stop it. That is strange. I have no idea atm. edit: in case you are running this compiled program on Windows, do you perhaps have antivirus/firewall running that blocks your lazarus application ? In theory tfphttclient.SimpleGet should only 'hang' for the duration of timeout and return on errors (in which case the resulting body should be able to provide more information). Quoteis it possible that i needed to specify the port number somewhere? That is possible.I'm sorry but do not know much about arduino webserver. It should state somewhere what are the default options. SimpleGet just sends data to the server at port 80. Perhaps arduino expects another port, such as 8080 ? Or perhaps the server only accepts secure connections ? QuoteI saw that there are many fphttpclient versions.  Is this one part of the same synapse package? fphttpclient is part of fcl-web and is a native/default Free Pascal package. In case your server is redirecting then simpleget will not work as you expected. In that case have a look at the link i posted in my previous post and use the 'full' version of retrieving a html page from your server. SimpleGet class method is only meant to work in/for the most simplest of conditions. In case you wish to learn more about the data sending/retrieval  between browser and server then you could consider using a proxy server. But there are also other options available that would let you inspect datapackets and/or http transfers. edit2: I do not know much about synapse but i read: Quote from: Serge58 on August 07, 2017, 12:55:15 am   Str:='http://1.0.4.1/arduino/webserver'; Copy-paste error or actual typo in your code (for the web-address) ? edit3: Quote from: Serge58 on August 07, 2017, 12:55:15 ami tried both of your options:  First, HTTPSend.GetText is giving me some error.  i checked and it seems that there is no GetText method in the HTTPSend class. Seems to me that user Almir.Bispo only got it partially correct. According to this online help for synapse, it should read: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i program synapsing;Uses  HTTPSend;var  url: String;  Response: TStringlistbegin  url := 'http://10.0.4.1/arduino/webserver';  Response := TStringList.Create;  if httpGetText (url , Response)     then ShowMessage(Reponse.text)    else ShowMessage('Failure');  Response.free;end. ---------------------------------------------------------------------- Serge58 · 2017-08-07 01:40 Thanks a million!! With your help I was able to make it work.  First, my Url was bad.  It should have read 10.0.1.4. Thanks for pointing it out. My code: // Button 1 using 'HTTPSend' procedure TForm1.Button1Click(Sender: TObject);   var   url,html: String; begin   url:= 'http://10.0.1.4/arduino/webserver';   html := TFPCustomHTTPClient.SimpleGet(url);     memo1.Text := html; end; // Button 2 Using 'fphttpclient' procedure TForm1.Button2Click(Sender: TObject);   var   httpclient: TFPHTTPClient;   html,url: String; begin   url:= 'http://10.0.1.4/arduino/webserver';   httpclient:= TFPHttpClient.Create(Nil);   try      html:= httpclient.Get(url);   finally      httpclient.Free;   end;   memo1.Text := html;  end;  Both of the functions are working. many thanks,