Go Down

Topic: sending post data from the Yun to a webpage (Read 11715 times) previous topic - next topic

Heiko73

Please help, I cannot find any samples in the web.

I want to send some text from my Yun to a webpage. My first try was to use Bridge HttpClient with GET URL-Parameters like this:   client.get("http://mypage.php?data=blablabla&data2=something")

But I have large texts and also with many not in URLs acceptet characters. So for me would be much better to send data via the POST-method like in Web-Forms. But how does that work with the Yun??? I tryed samples for the Ethernet and the Wifi Libraries, but this does not work with the Yun. There are thousends of samples to send data with Yun to existing webservices but nothing to send data simpli to the own PHP-Webpage.

Please help, I don't know how to finish my project.

Thanks

Jantje

Why not send the data to the sd card and call a script that does a the http calls?

Do not PM me a question unless you are prepared to pay for consultancy.
Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -

Heiko73

Hello Jantje,

thanks for the fast respoding. Do you mean, I should call a phyton-script on the linux-part for that? If that is a solution, I could do that. But I don't know phyton. Are there some examples for that?

I wonder, why the bridge-library does not support a solution for sending post data to a webpage. Is that only for me important?

Jantje

I'm not saying that what I propose is the "only option". It is just an option I know will work.
It doesn't have to be python. It can be any "language" that yun can handle. Such as python, lua, ash ......
I personally would look at the curl command. I'm using it to get data (from my yun1 to my yun2 and the other way around) but it also supports post.


I wonder, why the bridge-library does not support a solution for sending post data to a webpage. Is that only for me important?

There are so many ways to do this (and so many other things) that you can not expect Arduino to support all of them with a method.
If you are working with the yun some basic openwrt/linino/linux knowledge is very handy. This because you can move "actions" to linino very easily if you know your options on linino.

Best regards
Jantje
Do not PM me a question unless you are prepared to pay for consultancy.
Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -

Heiko73

Ok, I would be more than happy, if someone can post a short sample how to send data (a text) to a Webserver with a known URL. Here my really simple sample wich only works with short text :   

HttpClient client;
client.get("http://mypage.php?mytext=this%20is%20my%20text");

May be, in future HttpClient will have a "post" method or some methodes to manage the request-body.

Again: Given samples with WiFi do not work with the Yun. They all need the Wifi-Shield. No chance to do that with Yun?

Piero76

some days ago i has the same problem...:D
there's the solution

Code: [Select]
#include <Bridge.h>
#include <Console.h>
#include <FileIO.h>
#include <HttpClient.h>
#include <Mailbox.h>
#include <Process.h>
#include <YunClient.h>
#include <YunServer.h>

#include <SPI.h>
//#include <Ethernet.h>


//byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
IPAddress server(10,33,66,149); //
//EthernetClient client;
YunClient client;

int temp = 64;

void setup()
{
  //Ethernet.begin(mac);
  Bridge.begin();
  Serial.begin(9600);
  String parametri ="";
  //delay(5000);
  //Serial.println("XXXXXXXXX");

  delay(2500);
  Serial.println("connecting...");

  if (client.connect(server, 80))
  {
    Serial.println("connected");
    delay(2500);
    parametri="rem_temp="+String(temp);
   
    client.println("POST /prova/inserisci.php HTTP/1.1");
    client.print("Content-length:");
    client.println(parametri.length());
    Serial.println(parametri.length());
    Serial.println(parametri);
    client.println("Connection: Close");
    client.println("Host:10.33.66.149");
    client.println("Content-Type: application/x-www-form-urlencoded");
    client.println();
    client.println(parametri);     //Set Remote temperture to ___
    //client.print(temp);
    //client.println("}");
  }
    else
    {
    Serial.println("connection failed");
    }
}
void loop()
{
  if (client.available()) {
    char c = client.read();
    Serial.print(c); 
  }
  if (!client.connected()) {
    Serial.println();
    Serial.println("disconnecting.");
    client.stop();
    for(;;)
;
  }
}


the comment here because the original sketch was for arduino Uno
the sketck send only one  variable but you can expand easily for any number of variable

bye


Heiko73

Piero, you are the hero of the day, it works perfect  :D

You only have to include <Bridge.h> and <YunClient.h>, not the other libraries. To your honour I will keep the name of the String "Parametri" in my project  ;)

Thanks

sonnyyu


luisea

Hi Piero, Might you show me the code of the php file "insercici.php"

bugart303

Piero, will this work with xampp as a server? I can't see any data in my server or as what luisea said can you show the php file

Go Up