Hi,ı want to push data a mssql server using arduino and php codes.So firstly i tried send data a mysql server with xampp.My codes and php files given below;
/*
Web client
This sketch connects to a website (http://www.google.com)
using an Arduino Wiznet Ethernet shield.
Circuit:
- Ethernet shield attached to pins 10, 11, 12, 13
created 18 Dec 2009
by David A. Mellis
modified 9 Apr 2012
by Tom Igoe, based on work by Adrian McEwen
*/
#include <EEPROM.h>
#include <SPI.h>
#include <Ethernet.h>
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
IPAddress server(192,168,0,100);
IPAddress ip(192,168,0,100);
EthernetClient client;
int Leddurum;
#define LED1PIN 2
void setup() {
// Open serial communications and wait for port to open:
Serial.begin(9600);
while (!Serial) {
; // wait for serial port to connect. Needed for Leonardo only
}
// start the Ethernet connection:
if (Ethernet.begin(mac) == 0) {
Serial.println("Failed to configure Ethernet using DHCP");
// no point in carrying on, so do nothing forevermore:
// try to congifure using IP address instead of DHCP:
Ethernet.begin(mac, ip);
}
// give the Ethernet shield a second to initialize:
delay(1000);
Serial.println("connecting...");
pinMode(LED1PIN, OUTPUT);
digitalWrite(LED1PIN,Leddurum);
//Leddurum = Serial.read();
Leddurum = EEPROM.read(0);
Serial.println(Leddurum);
if (client.connect(server, 80)) {
Serial.println("connected");
// Make a HTTP request:
client.println("GET /deneme/add.php HTTP/1.1");
client.println("Host: 192.168.0.100");
client.println("Connection: close");
client.println();
}
else {
// kf you didn't get a connection to the server:
Serial.println("connection failed");
}
}
void loop()
{
// if there are incoming bytes available
// from the server, read them and print them:
if (client.available()) {
char Leddurum = client.read();
Serial.print(Leddurum);
}
// if the server's disconnected, stop the client:
if (!client.connected()) {
Serial.println();
Serial.println("disconnecting.");
client.stop();
// do nothing forevermore:
while(true);
}
}
PHP files;
connect.php
<?php function Connection(){ $server="127.0.0.1"; $user="mhbalaman"; $pass="mhb.0913232"; $db="testarduino"; $connection = mysql_connect($server, $user, $pass); if (!$connection) { die('MySQL ERROR: ' . mysql_error()); } mysql_select_db($db) or die( 'MySQL ERROR: '. mysql_error() ); return $connection; } ?>index.php
<?php include("connect.php"); $link=Connection(); $result=mysql_query("SELECT * FROM `Ledstatus` ORDER BY `timeStamp` DESC",$link); ?> Sensor Dataled status reading
<?php if($result!==FALSE){ while($row = mysql_fetch_array($result)) { printf("", $row["timeStamp"], $row["led1"] ); } mysql_free_result($result); mysql_close(); } ?>Timestamp | LED1 |
%s | %s |
This codes sending data my server in every 32 sec.But arduino serial monitor gives some error about php codes.
connected
HTTP/1.1 302 Found
Date: Thu, 04 Dec 2014 07:06:54 GMT
Server: Apache/2.4.10 (Win32) OpenSSL/1.0.1i PHP/5.5.15
X-Powered-By: PHP/5.5.15
Location: index.php
Content-Length: 113
Connection: close
Content-Type: text/html
Notice: Undefined index: Leddurum in C:\xampp\htdocs\deneme\add.php on line 8
disconnecting.
ıf you share your thoughts ı wil be glad.also ı attach my server web page data pic.