element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • About Us
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
Arduino
  • Products
  • More
Arduino
Arduino Forum Arduino YUN sending data to WS via POST
  • Blog
  • Forum
  • Documents
  • Quiz
  • Events
  • Polls
  • Files
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Join Arduino to participate - click to join for free!
Actions
  • Share
  • More
  • Cancel
Forum Thread Details
  • State Verified Answer
  • Replies 6 replies
  • Answers 2 answers
  • Subscribers 393 subscribers
  • Views 1300 views
  • Users 0 members are here
  • yun
  • webservice
  • post
  • server
  • arduino
  • bridge
Related

Arduino YUN sending data to WS via POST

Former Member
Former Member over 10 years ago

Hello Everyoune,

I've my Arduino YUN with a protoshield and some gas sensors (metane, idrogene, temperature, humidity).

I've got to send these values via POST to a web service in PHP. Knowing that:

1) Arduino YUN is connected to a WiFi Router which is connected to the internet (my smartphone working as WiFi Router);

2) The WS works well because when getting post variables from other sources it saves and visualizes data;

3) Arduino YUN is connected to WiFi Router via WiFi and to the PC (which is also connected to the same Router wirelessly) via USB, so I can check serial messages via Serial Monitor on the PC, and also checking on the internet if data are sent and visualized.

 

So, the fact is, even if everybody sends data the same way (see the sketch below) it doesn't work for me. I've also tried to use another Arduino YUN, but nothing. The sketch is:

 

          #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 <dht.h>

          #include <SPI.h>

 

          //IP Address of the sever on which there is the WS: http://www.mywebsite.com/

          IPAddress server(XX,XX,XX,XX);

 

          YunClient client;

          dht DHT;

          #define DHT11_PIN 2

          int temp;

          int hum;

          int metano;

          int idrogeno;

          int led_giallo = 13;

          int led_rosso = 12;

          String parametri ="";           //String of POST parameters

 

          void setup()

          {

                 Bridge.begin();

                 Serial.begin(9600);

 

                 pinMode(led_rosso,OUTPUT);

                 pinMode(led_giallo,OUTPUT);

                 digitalWrite(led_giallo,HIGH);

                 digitalWrite(led_rosso,LOW);

                 delay(2500);

                 digitalWrite(led_giallo,LOW);

          }

 

          void loop()

          {

                 //measures

                 metano = analogRead(0);

                 idrogeno = analogRead(1);

                 hum = (int) DHT.humidity;

                 temp = (int) DHT.temperature;

 

                 if (client.connect(server, 80)) {

                          Serial.println("connected");

                          delay(2500);

                          parametri="temp="+String(temp) + "&hum="+ String(hum)+"&metano="+String(metano)+"&idrogeno="+String(idrogeno);

                          client.println("POST /test/arduino/add.php HTTP/1.1");

                          client.println("Host: XX.XX.XX.XX");

                          client.print("Content-length:");

                          client.println(parametri.length());

                          Serial.println(parametri);

                          client.println("Connection: Close");

                          client.println("Content-Type: application/x-www-form-urlencoded;");

                          client.println();

                          client.println(parametri);  

                 }else{

                        Serial.println("connection failed");

                        digitalWrite(led_rosso,HIGH);

                        delay(1000);

                 }

                 if(client.connected()){

                             client.stop();   //disconnect from server

                 }

                 delay(2000);

    }

 

 

Could anyone help me? Why data does't arrive to the WS?

Thank you all, very much!!!

  • Sign in to reply
  • Cancel

Top Replies

  • Former Member
    Former Member over 10 years ago +1 verified
    I've found the solution. The problem was not about the ip address but how how formulate the request... So I changed from: client.println("POST /test/arduino/add.php HTTP/1.1"); client.println("Host: XX…
Parents
  • clem57
    0 clem57 over 10 years ago

    If you use an IP address like client.println("Host: XX.XX.XX.XX"), you must know about WiFi routing and forwarding. Without the specifics, I would guess the IP was non routable within the setup. Unless you have the necessary knowledge, it is best to use URL like client.println("Host: www.mywebsite.com") which uses DNS to get where you want to go.

    Clem

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Reject Answer
    • Cancel
Reply
  • clem57
    0 clem57 over 10 years ago

    If you use an IP address like client.println("Host: XX.XX.XX.XX"), you must know about WiFi routing and forwarding. Without the specifics, I would guess the IP was non routable within the setup. Unless you have the necessary knowledge, it is best to use URL like client.println("Host: www.mywebsite.com") which uses DNS to get where you want to go.

    Clem

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Reject Answer
    • Cancel
Children
No Data
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2025 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube