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