Dear Hans, sorry I was away for 2 days... thanks for your replay... I change the line in add_data.php: to:
$result1 = mysql_query($SQL) or die(mysql_error());
now you link
http://adverta.com.mk/test/arproekt/add_data.php?serial=123&temperature=20&light=12&moisture1=34&moisture2=56
is working, but still my code from arduino is not working...
also I try this Hello World example that I find on line just to see if I can make a connection to my server online and it worked
here is the code for Hello World example:
/*
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 <SPI.h>
#include <Ethernet.h>
// Enter a MAC address for your controller below.
// Newer Ethernet shields have a MAC address printed on a sticker on the shield
byte mac[] = { 0x90, 0xA2, 0xDA, 0x0F, 0x3A, 0xDC };
// if you don't want to use DNS (and reduce your sketch size)
// use the numeric IP instead of the name for the server:
//IPAddress server(74,125,232,128); // numeric IP for Google (no DNS)
IPAddress ip(192, 168, 2, 121); // name address for Google (using DNS)
// Set the static IP address to use if the DHCP fails to assign
//IPAddress ip(192,168,2,8);
char server[] = "www.adverta.com.mk";
// Initialize the Ethernet client library
// with the IP address and port of the server
// that you want to connect to (port 80 is default for HTTP):
EthernetClient client;
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...");
// if you get a connection, report back via serial:
if (client.connect(server, 80)) {
Serial.println("connected");
// Make a HTTP request:
//client.print("GET /rec.php HTTP/1.1n");
client.println("GET /test/arproekt/rec.php HTTP/1.1");
client.println("Host: www.adverta.com.mk");
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 c = client.read();
Serial.print(c);
}
// if the server's disconnected, stop the client:
if (!client.connected()) {
Serial.println();
Serial.println("disconnecting.");
client.stop();
// do nothing forevermore:
while(true);
} }
I changed the first code ti something like this to try to put some data directly to database but still no luck
#include<Ethernet.h>
#include<SPI.h>
const int temperaturePin = A3; //LM35 Temperature sensor
const int lightPin = A2; //LDR photoresistor sensor
const int moisture1Pin = A4; //Moisture1 sensor
const int moisture2Pin = A5; //Moisture2 sensor
// * ETHERNET SETTING *
// Arduino Uno pins: 10 = CS, 11 = MOSI, 12 = MISO, 13 = SCK
// Ethernet MAC address - must be unique on your network - MAC Reads T4A001 in hex (unique in your network)
byte mac[] = { 0x90, 0xA2, 0xDA, 0x0F, 0x3A, 0xDC };
// For the rest we use DHCP (IP address and such)
IPAddress ip(192, 168, 2, 121);
//IPAddress server(192, 168, 2, 100); // IP Adres (or name) of server to dump data to
// IP Adres (or name) of server to dump data to (godaddy baza server 37.148.204.140) (User: tanjamayaarduino@188.121.42.33) (goddady glavna adresa na hostingot 188.121.46.1)
//IPAddress server(188, 121, 46, 1);
char server[] = "www.adverta.com.mk";
int interval = 5000; // Wait between dumps
EthernetClient client;
void setup() {
Serial.begin(9600);
while (!Serial) {
; // wait for serial port to connect. Needed for Leonardo only
}
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);
}
Serial.println("Tweaking4All.com - Temperature Drone - v2.0");
Serial.println("-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-n");
Serial.print("IP Address : ");
Serial.println(Ethernet.localIP());
Serial.print("Subnet Mask : ");
Serial.println(Ethernet.subnetMask());
Serial.print("Default Gateway IP: ");
Serial.println(Ethernet.gatewayIP());
Serial.print("DNS Server IP : ");
Serial.println(Ethernet.dnsServerIP());
}
void loop() {
// if you get a connection, report back via serial:
if (client.connect(server, 80)) {
float tem = getTemp();
Serial.println( tem );
float lig = getLight();
Serial.println( lig );
float mois1 = getMoisture1();
Serial.println( mois1 );
float mois2 = getMoisture2();
Serial.println( mois2 );
Serial.println("-> Connected");
if (client.connected()) {
// Make a HTTP request:
// client.println("GET /test/arproekt/rec.php HTTP/1.1");
client.print("GET /test/arproekt/add_data.php?");
client.print("serial=");
client.print("100" );
client.print("&");
client.print("temperature=");
client.print("100");
client.print("&");
client.print("light=");
client.print("100");
client.print("&");
client.print("moisture1=");
client.print("100");
client.print("&");
client.print("moisture2=");
client.print("100");
client.println( "HTTP/1.1");
client.print("Host: www.adverta.com.mk");
//client.println(server);
client.println("Connection: close");
client.println();
client.println();
client.stop();
}
}
else {
// you didn't get a connection to the server:
Serial.println("--> connection failed/n");
}
delay(interval);
}
float getTemp() {
float temperature = (5.0 * analogRead(temperaturePin) * 100.0) / 1024; //converting from a 0 to 1023 digital range to 0 to 5 volts (each 1 reading equals ~ 5 millivolts
return temperature;
}
float getLight() {
float light;
light = analogRead(lightPin) ;
return light;
}
float getMoisture1() {
float moisture1;
moisture1 = analogRead(moisture1Pin) ;
return moisture1;
}
float getMoisture2() {
float moisture2;
moisture2 = analogRead(moisture2Pin) ;
return moisture2;
}
please do you have some Idea what it would be wrong?
thanks