Facing problem with wifi connection

Hi,

I want to post dummy data to my server to store in mysql database.

I have following harwares

board: ARDUINO UNO
Wifi Module: ESP8266 ESP-01

I have wired wifi module with arduino with following connections

ARDUINO UNO ESP8266 ESP-01

RX TX
TX RX
3.3V CH_P
3.3V VCC
GRN GRN

In Arduino IDE i have select board. Arduino UNO from Tool → board → arduino uno

Here is my code, trying to connect to wifi and post data to url

#include <SPI.h>
#include <WiFi101.h>

// server to connect to and relative path to PHP script
char server = “http://127.0.0.1”;
String phpScript = “/TEST/iot/dummy.php”;

// wifi network and password
char ssid = “delickate”;
char pass = “sd24s23d@d34#”;

int status = WL_IDLE_STATUS;

WiFiServer server(80);

int keyIndex = 0;
WiFiClient client;

void setup()
{

// some data to send (fake wind sensor readings)
float windDir = 380.0;
float windSpeed = 2.2;
float battLevel = 3.85;

// format datapoints as PHP arguments
// this means easy parsing later in the PHP script
String data = “&dir=” + String(windDir, 2) + “&speed=” + String(windSpeed, 2) + “&batt=” + String(battLevel, 2);

Serial.println(data);

// required for Adafruit Feather M0 Wifi board
WiFi.setPins(8,7,4,2);

// start serial connection for feedback
Serial.begin(9600);
while (!Serial) {
//
}

// is a wifi unit attached?
Serial.println(“Checking for wifi hardware…”);
if (WiFi.status() == WL_NO_SHIELD) {
Serial.println("- none found, quitting…");
while (true);
}
Serial.println("- found");

// attempt to connect to WiFi network:
while (status != WL_CONNECTED) {
Serial.print(“Attempting to connect to: “”);
Serial.print(ssid);
Serial.println(”"");
status = WiFi.begin(ssid, pass);
delay(10000); // wait 10 sec for connection
}
Serial.println("- connected!");

// post data using HTTP POST
Serial.println(“Connecting to server…”);
if (client.connect(server, 98)) {
Serial.println("- connected");

Serial.println(“Posting sensor data…”);
client.print(“POST “);
client.print(phpScript);
client.println(” HTTP/1.1”);
client.println(“Host: http://localhost:98”);
client.println(“User-Agent: Arduino/1.0”);
client.println(“Connection: close”);
// client.println(“Content-Type: application/x-www-form-urlencoded”);
client.println(“Content-Type: application/x-www-form-urlencoded; charset=UTF-8”);
client.print(“Content-Length: “);
client.println(data.length());
client.println();
client.print(data);
Serial.println(”- done”);
}

// disconnect when done
Serial.println(“Disconnecting from server…”);
client.stop();
Serial.println("- bye!");

}

void loop() {
// you could also move your HTTP POST code here, if you
// wanted to post repeatedly
}

But unable to connect to wifi.

Please guide what am i missing?

Thanks

localhost and 127.0.0.1 are things the server uses to refer to itself, from itself. Your Arduino needs to know the hostname or IP address of the server.

Thanks for the prompt response.

I also have tried tried by changing live server url to

http://robologicx.com/dummy.php

but problem is with wifi connection.

It keeps trying to connect wifi with following error

"
Checking for wifi hardware...

  • none found, quitting...

Checking for wifi hardware...

  • none found, quitting...

Checking for wifi hardware...

  • none found, quitting...

"

Please help

It looks as though your Arduino code relies on your Uno having a shield on it.

At least, that’s what I infer from this:

  if (WiFi.status() == WL_NO_SHIELD) {

See if you can find a tutorial for using your ESP-01 to connect to wifi. Worry about hitting the server when that’s working.

Thanks for the response. I have modified code by removing shield detection as i do not have it. Its struct with following message

"Attempting to connect to: delickate

Attempting to connect to: delickate

Attempting to connect to: delickate

"

Guide me about wiring between adruino uno & esp-01

Am i doing wrong there?

Please guide…

Hmm you are not going in the right direction. If you want to use the ESP-01 to connect to wifi, there are 2 options.

  • firstly you can control the ESP-01 using AT-commands from the espressif firmware that it came with, Sending the commands from the UNO. which is cumbersome, though there are decent enough tutorials to be found online and there is a library which streamlines this method.
  • secondly and in my opinion the way to go is to upload your own sketch to the ESP-01 using the Arduino IDE which will do the connecting to the WiFi. Your method of connecting will be fully under your control using the same language that you use for the UNO and all you need to do is interface the UNO and The ESP-01 using some kind of Serial protocol. That is if you really need the UNO, the ESP-01 has quite a powerful processor.

Guide me about wiring between adruino uno & esp-01

Depends what you want to do, the main thing you should change is that you should put a voltage divider so the ESP-01 RX-pin is not hit with 5v+ from the UNO logic levels. This is important, ESP-01's tend to fragile and not 5v tolerant.
Now let's say you want to either explore what the AT-commands can do or upload your own firmware onto the ESP, then you should first load a empty sketch onto the UNO (or blink, a sketch that does not involve Serial communication.) and then swap the wires at the UNO side and use the UNO as a TTL to Serial port.
Also for this there are quite a few good tutorials around (some bad ones to though.)