HI i want to upload ultrasonic sensor value to website,but its not showing on website . i was stuck with this for the past one week ,if anyone have already done this kind of project please help me.
below is the arduino code and i am attaching php files also
#include <SPI.h>
#include <WiFi.h>
// EDIT: Change the 'ssid' and 'password' to match your network
const int TrigPin = 2;
const int EchoPin = 3;
float z;
char ssid[] = "*******"; // your network SSID (name)
char pass[] = "*********"; // your network password (use for WPA, or use as key for WEP)
int keyIndex = 0;
int status = WL_IDLE_STATUS;
WiFiClient client;
// EDIT: 'Server' address to match your domain
char server[] = "192.168.19.171"; // 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
void setup() {
Serial.begin(9600);
pinMode(TrigPin, OUTPUT_FAST);
pinMode(EchoPin, INPUT_FAST);
connectWifi();
// You're connected now, so print out the status
printWifiStatus();
postData();
}
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
fastDigitalWrite(TrigPin, LOW);
delayMicroseconds(2);
fastDigitalWrite(TrigPin, HIGH);
delayMicroseconds(10);
fastDigitalWrite(TrigPin, LOW);
// duration = pulseIn(echoPin, HIGH);
z= pulseIn(EchoPin, HIGH) / 58.0;
Serial.print("distance is ");
Serial.print(z);
Serial.println(" cm");
delay(1000);
// If there's a successful connection, send the HTTP POST request
if (client.connect(server, 80)) {
Serial.println("connecting...");
// EDIT: The POST 'URL' to the location of your insert_mysql.php on your web-host
// client.println("POST /insert_mysql.php HTTP/1.1");
client.print("POST /prudhvi/us.php?z=");// This
client.print(z);
client.println(" HTTP/1.0");
client.println("Host:192.168.19.171");
client.println("Connection: close");
client.println();
// EDIT: 'Host' to match your domain
//client.println("Host: www.yourdomain.com");
//client.println("User-Agent: Arduino/1.0");
//client.println("Connection: close");
//client.println("Content-Type: application/x-www-form-urlencoded;");
// client.print("Content-Length: ");
client.println();
}
else {
// If you couldn't make a connection:
Serial.println("Connection failed");
Serial.println("Disconnecting.");
client.stop();
}
}
us.php.txt (380 Bytes)