3 Replies Latest reply on Sep 7, 2015 10:15 PM by chewcheik

    client.connection(server,port) fails alternately with WiFi Edison (http request)

    chewcheik

      Greeting to everyone,

       

      Here I have a funny error that I cannot fixed.

      Tools:

      1. Intel Edison

      2. RFID 13.52MHz

      3. WAMP server

      4. Arduino IDE

       

      I success PUSH my RFID ID with Intel Edison WiFi to WAMP server but this data will success alternately only.

      No matter I waiting after 1min, 3min, 10min or half hour the result will turn up like this.

      It will success alternately only (very funny).

      I have read Arduino Wifi connection problem: client.connect(server, 80) command not working. They state that could be the firmware not up-to-date

      but i cannot find the article about update Edison WiFi firmware.

      connecting alternately error.PNG

      Arduino Code

      void postData() {

        int check ;

        if (check = client.connect(server, 8081)) {

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

          Serial.println("+++++++++++++++++++");

          Serial.println(check);

          Serial.println("+++++++++++++++++++");

          // EDIT: The POST 'URL' to the location of your insert_mysql.php on your web-host

          client.println("POST /arduino.php?name="+RFID+" HTTP/1.1");

            // EDIT: 'Host' to match your domain

          client.println("Host: 192.168.43.158:8081");

          client.println("User-Agent: ArduinoWiFi/1.1");

          client.println("Connection: close");

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

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

         }

      else {

          Serial.println("========================");

          Serial.println(check);

          Serial.println("======================");

          Serial.println("Connection failed");

          Serial.println("Disconnecting.");

          client.stop();

        }

      }

       

      Thank you

        • 1. Re: client.connection(server,port) fails alternately with WiFi Edison (http request)
          Intel_Alvarado

          Hi,

           

          Well you can start by checking your image release version. Go to the terminal and type configure_edison –version. The output for the latest version is 159.

          Also, check for the Arduino IDE version. The latest available is 1.6.5 and can be downloaded from Arduino - Software .

          I tried to run your code and it failed to compile. Is that the complete code?

           

          Sergio

          • 2. Re: client.connection(server,port) fails alternately with WiFi Edison (http request)
            chewcheik

            Hi @Intel_Alvarodo,

             

            Thank you for ur suggestion.

            My image release version is 159.

            edison version.PNG

            I have install the latest version of arduino IDE 1.6.5 but the problem that I face before is occurring again. 

            Edison board at com is not available

             

            This is my code but you cant access by database because I am using the WAMP server.

            //****************************************************

            #include <SPI.h>

            #include <WiFi.h>

             

             

            // EDIT: Change the 'ssid' and 'password' to match your network

            char ssid[] = "sun_ray";  // wireless network name

            char password[] = "Jac_happy_129"; // wireless password

            int status = WL_IDLE_STATUS;

            WiFiClient client;

             

             

            // EDIT: 'Server' address to match your domain

            char server[] = "192.168.43.158"; // This could also be 192.168.1.18/~me if you are running a server on your computer on a local network.

             

             

            // This is the data that will be passed into your POST and matches your mysql column

            int yourarduinodata = 999;

            String yourdatacolumn = "?name=";

            String yourdata = "wednesday";

             

             

            void setup() {

              Serial.begin(9600);

             

              connectWifi();

             

             

              // You're connected now, so print out the status

              printWifiStatus();

               Serial.print("try to print 5 times");

              for(int i=0 ; i < 5 ;i++){

              postData();

              delay(3000);}

             

             

            }

             

             

            void loop() {

             

            }

             

             

            void connectWifi() {

              // Attempt to connect to wifi network

              while ( status != WL_CONNECTED) {

                Serial.print("Attempting to connect to SSID: ");

                Serial.println(ssid);

                status = WiFi.begin(ssid, password);

                // Wait 10 seconds for connection

                delay(10000);

              }

            }

             

             

            void printWifiStatus() {

              // Print the SSID of the network you're attached to

              Serial.print("SSID: ");

              Serial.println(WiFi.SSID());

             

             

              // Print your WiFi shield's IP address

              IPAddress ip = WiFi.localIP();

              Serial.print("IP Address: ");

              Serial.println(ip);

             

             

              // Print the received signal strength

              long rssi = WiFi.RSSI();

              Serial.print("signal strength (RSSI):");

              Serial.print(rssi);

              Serial.println(" dBm");

            }

             

             

            // This method makes a HTTP connection to the server and POSTs data

            void postData() {

              // Combine yourdatacolumn header (yourdata=) with the data recorded from your arduino

              // (yourarduinodata) and package them into the String yourdata which is what will be

              // sent in your POST request

              //yourdata = yourdatacolumn + yourarduinodata;

              Serial.println(yourdata);

             

             

              // If there's a successful connection, send the HTTP POST request

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

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

             

             

                // EDIT: The POST 'URL' to the location of your insert_mysql.php on your web-host

                client.println("POST /arduino.php?name="+yourdata+" HTTP/1.1");

                // Serial.println("connecting... twice");

                // EDIT: 'Host' to match your domain

                client.println("Host: 192.168.43.158:8081");

                client.println("Accept: yourdata");

                //Serial.println("connecting... trice");

                client.println("User-Agent: Arduino/1.0");

                //Serial.println("connecting... four");

                client.println("Connection: close");

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

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

                client.println(yourdata.length());

                client.println();

                client.println(yourdata);

              }

              else {

                // If you couldn't make a connection:

                Serial.println("Connection failed");

                Serial.println("Disconnecting.");

                client.stop();

              }

            }

             

            //****************************************************


            Thanks

            • 3. Re: client.connection(server,port) fails alternately with WiFi Edison (http request)
              chewcheik

              Hi @Intel_Alvarado,

              My friend has solve my problem with comment off one line of program.

              //client.stop(); inside the else statement, then put it outside the if else statement.

              Now it can send continuously.

              Thank you for helping me Alvarado.