Go Down

Topic: Cant write Data from Arduino into Wamp Databaze (Read 283 times) previous topic - next topic


Hi. I am using Arduino Uno with ethernet shield. I want write some data to my local server on Wamp. My php script work good. There it is.

Code: [Select]
$user "root";
$pass "";
$db "bakalarka";
$mysqli mysqli_connect($server$user$pass$db); //připojení k MySQL
if($mysqli and isset($_GET['pwm'])){ //pokud GET obsahuje 'hodnota', pokračuj
$pwm sanitize($_GET['pwm']);
$sql "INSERT INTO optoclen (pwm) VALUES (".$pwm.")"//sestavení SQL
$doSql $mysqli->query($sql); //vykonání SQL
if($doSql){ //test úspěchu
echo 'Zápis byl úspěšný';
'Něco se nepovedlo';
"Neco je špatně";
sanitize($input){ //ořízne řetězec
$input htmlspecialchars($input);
$input htmlentities($input);
$input strip_tags($input);
$input trim($input);

When i try select manually pwm into chrome like localhost/pokus/log_optoclen.php?pwm=5   it works. i can see number 5 in my databaze.

But when i use ardunino, i can see on serial monitor:

Code: [Select]

GET /pokus/log_optoclen.php?pwm=4.98

But  that is all, i cant see any volues in my databaze ( my firewall and AVG are turn off)

My arduino code:

Code: [Select]
#include <Ethernet.h> //Použité knihovny
#include <SPI.h>
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xEB }; //MAC adresa Arduina (posledni pismeno D)
IPAddress ip(192,168,6,130);
IPAddress server(192,168,6,10);
//IPAddress gateway(192,168,6,2);

boolean reading = false; //Funkční podmínka

String data;

int a = A0; //Měřící piny A/D převodníku
int b = A1;
int c = A2;
int d = A3;

float av = 0; //Proměnné pro výpočet napětí
double bv = 0;
double cv = 0;
double dv = 0;

double ai = 0; //Proměnné pro výpočet napětí
double bi = 0;

int i = 255; //Počáteční hodnota PWM
int stav = 1; //Proměnná pro tlačítko MIN/MAX
float pwm = 0; //Proměnná pro zobrazení hodnoty PWM

EthernetClient client; //Konstanta pro prohlížeč

void setup()
  pinMode(9, OUTPUT); //PWM kanál
  Serial.begin(9600); //NAstavění sériového kanálu (nepoužit)
  Ethernet.begin(mac, ip); //Nastavení MAC a IP adresy


void loop()

  analogWrite(9, i);
  if (client.connect(server, 80)) { // REPLACE WITH YOUR SERVER ADDRESS
    client.print("GET /pokus/log_optoclen.php?");
    Serial.print("GET /pokus/log_optoclen.php?");
    client.println( " HTTP/1.1");
    client.println( "Connection: close" );


I think that Wamp must block that writing somehow. Any ideas ?  Wamp icon show that all systems works and server is online.


I think that Wamp must block that writing somehow. Any ideas ?  Wamp icon show that all systems works and server is online.
The A in WAMP stands for Apache. The Apache server has the ability to log accesses to the httpd process. You REALLY need to enable logging, and you need to look at the logs.

The process of entering a URL into a browser and of making a GET request from the Arduino are NOT doing the same thing.

localhost resolves to some IP address. There is no proof that it resolves to the same IP address that the Arduino is trying to connect to. You need to provide that proof by NOT using localhost.

Code: [Select]
Hey, server. I want you to do something with some data. I want you to tell me whether or not you could. But, I'm NOT going to listen to whatever you tell me.

Why the hell not? There is rarely a need to use client.stop(). There is certainly none in this case.

Read the server response. Perhaps a clue-by-four will present itself.
The art of getting good answers lies in asking good questions.

Go Up