Skip to main content
Bumped by Community user
added 470 characters in body
Source Link

EDIT the problem i encountered is whenever i checked http://localhost/log.php this appears:

Parse error: syntax error, unexpected ';' in C:\xampp\htdocs\log.php on line 7

i have tried modifying the syntax in numerous ways but the problem presist. I suspect my code may have some underlying fundamental problem that is not syntax related, but i can't tell due to my lack of experience. Again, any help/clue is greatly appreciated. Thank you very much

EDIT the problem i encountered is whenever i checked http://localhost/log.php this appears:

Parse error: syntax error, unexpected ';' in C:\xampp\htdocs\log.php on line 7

i have tried modifying the syntax in numerous ways but the problem presist. I suspect my code may have some underlying fundamental problem that is not syntax related, but i can't tell due to my lack of experience. Again, any help/clue is greatly appreciated. Thank you very much

Removed commented-out code and non-English comments
Source Link
Mark Smith
  • 2.2k
  • 1
  • 11
  • 14
#include <ESP8266WiFi.h>
 
//#define DHTPIN D2
//#define DHTTYPE DHT11
//DHT dht(DHTPIN, DHTTYPE);
 
/* Parameters:
* t = temperature
* h = humidity
* i = ID
*/
const char* server = "192.168.1.106"; // ganti dengan alamat servermu
const char* ssid = "DARUSALAM C8"; // ganti dengan SSID modem/router wifimu
const char* password = "asro4520"; // ganti dengan password utk konek ke wifimu
const char* SensorID = "ESP001"; // ini sekedar identitas sensormu
 
WiFiClient client;
 
void setup() {
  Serial.begin(115200);
  delay(10);
//  dht.begin();
 
  pinMode(BUILTIN_LED, OUTPUT);
  digitalWrite(BUILTIN_LED, HIGH);
 
  WiFi.begin(ssid, password);
  Serial.println();
  Serial.println();
  Serial.print("Connecting to ");
  Serial.print(ssid);
  WiFi.begin(ssid, password);
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }
  Serial.println("");
  Serial.println("WiFi Connected");
}
 
void loop() {
//  float h = dht.readHumidity();
//  float t = dht.readTemperature();
float n = random(300);
//  if (isnan(h) || isnan(t)) {
//    Serial.println("Gagal membaca sensor DHT");
//    return;
//  }
 
//  Serial.print("Temperature: ");
//  Serial.print(t);
//  Serial.print(" *C. Humidity: ");
//  Serial.println(h);
Serial.print("Random Number: ");
Serial.println(n);
 
  if (client.connect(server,80)) {
    Serial.print("Posting data...");
    digitalWrite(BUILTIN_LED, LOW);
//    Serial.println("Temperature: " + String(t) + ", Humidity: " + String(h));
      Serial.println("Random Number: " + String(n));
//    client.println("GET /dht.php?t=" + String(t) + "&amp;amp;h=" + String(h) + "&amp;amp;i=" +SensorID+ " HTTP/1.1");
    client.println("GET /log.php?n=" + String(n));
    client.println("HOST: ");
    client.println(server);
    client.println("Connection: close");
    client.println();
 
    /*
    while (client.connected() &amp;amp;&amp;amp; !client.available()) delay(1);
    while (client.connected() || client.available()) {
      char c = client.read();
      Serial.print(c);
    }
    */
    client.stop();
    Serial.println();
 
    digitalWrite(BUILTIN_LED, HIGH);
  }
 
  delay(5000); // Beri delay 5 detik sebelum polling berikutnya
}
#include <ESP8266WiFi.h>
 
//#define DHTPIN D2
//#define DHTTYPE DHT11
//DHT dht(DHTPIN, DHTTYPE);
 
/* Parameters:
* t = temperature
* h = humidity
* i = ID
*/
const char* server = "192.168.1.106"; // ganti dengan alamat servermu
const char* ssid = "DARUSALAM C8"; // ganti dengan SSID modem/router wifimu
const char* password = "asro4520"; // ganti dengan password utk konek ke wifimu
const char* SensorID = "ESP001"; // ini sekedar identitas sensormu
 
WiFiClient client;
 
void setup() {
  Serial.begin(115200);
  delay(10);
//  dht.begin();
 
  pinMode(BUILTIN_LED, OUTPUT);
  digitalWrite(BUILTIN_LED, HIGH);
 
  WiFi.begin(ssid, password);
  Serial.println();
  Serial.println();
  Serial.print("Connecting to ");
  Serial.print(ssid);
  WiFi.begin(ssid, password);
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }
  Serial.println("");
  Serial.println("WiFi Connected");
}
 
void loop() {
//  float h = dht.readHumidity();
//  float t = dht.readTemperature();
float n = random(300);
//  if (isnan(h) || isnan(t)) {
//    Serial.println("Gagal membaca sensor DHT");
//    return;
//  }
 
//  Serial.print("Temperature: ");
//  Serial.print(t);
//  Serial.print(" *C. Humidity: ");
//  Serial.println(h);
Serial.print("Random Number: ");
Serial.println(n);
 
  if (client.connect(server,80)) {
    Serial.print("Posting data...");
    digitalWrite(BUILTIN_LED, LOW);
//    Serial.println("Temperature: " + String(t) + ", Humidity: " + String(h));
      Serial.println("Random Number: " + String(n));
//    client.println("GET /dht.php?t=" + String(t) + "&amp;amp;h=" + String(h) + "&amp;amp;i=" +SensorID+ " HTTP/1.1");
    client.println("GET /log.php?n=" + String(n));
    client.println("HOST: ");
    client.println(server);
    client.println("Connection: close");
    client.println();
 
    /*
    while (client.connected() &amp;amp;&amp;amp; !client.available()) delay(1);
    while (client.connected() || client.available()) {
      char c = client.read();
      Serial.print(c);
    }
    */
    client.stop();
    Serial.println();
 
    digitalWrite(BUILTIN_LED, HIGH);
  }
 
  delay(5000); // Beri delay 5 detik sebelum polling berikutnya
}
#include <ESP8266WiFi.h>
     
const char* server = "192.168.1.106";
const char* ssid = "DARUSALAM C8";
const char* password = "asro4520";
const char* SensorID = "ESP001";
 
WiFiClient client;
 
void setup() {
  Serial.begin(115200);
  delay(10);
 
  pinMode(BUILTIN_LED, OUTPUT);
  digitalWrite(BUILTIN_LED, HIGH);
 
  WiFi.begin(ssid, password);
  Serial.println();
  Serial.println();
  Serial.print("Connecting to ");
  Serial.print(ssid);
  WiFi.begin(ssid, password);
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }
  Serial.println("");
  Serial.println("WiFi Connected");
}
 
void loop() {
float n = random(300);
 
Serial.print("Random Number: ");
Serial.println(n);
 
  if (client.connect(server,80)) {
    Serial.print("Posting data...");
    digitalWrite(BUILTIN_LED, LOW);
    Serial.println("Random Number: " + String(n));
    client.println("GET /log.php?n=" + String(n));
    client.println("HOST: ");
    client.println(server);
    client.println("Connection: close");
    client.println();
 
    client.stop();
    Serial.println();
 
    digitalWrite(BUILTIN_LED, HIGH);
  }
 
  delay(5000);
}
Source Link

Problem sending data from arduino with ESP8266 to a local mysql database

i'm currently trying to send a randomly generated number from Arduino via ESP8266 wifi module to a local mysql database estabilished with xampp, but having a problem with it. Here is my arduino and php receiving code. I should mention that i'm extremely unfamiliar with mysql, php, and the whole server & database things, so any help would be greatly appreciated.

Arduino Code:

#include <ESP8266WiFi.h>

//#define DHTPIN D2
//#define DHTTYPE DHT11
//DHT dht(DHTPIN, DHTTYPE);
 
/* Parameters:
* t = temperature
* h = humidity
* i = ID
*/
const char* server = "192.168.1.106"; // ganti dengan alamat servermu
const char* ssid = "DARUSALAM C8"; // ganti dengan SSID modem/router wifimu
const char* password = "asro4520"; // ganti dengan password utk konek ke wifimu
const char* SensorID = "ESP001"; // ini sekedar identitas sensormu
 
WiFiClient client;
 
void setup() {
  Serial.begin(115200);
  delay(10);
//  dht.begin();
 
  pinMode(BUILTIN_LED, OUTPUT);
  digitalWrite(BUILTIN_LED, HIGH);
 
  WiFi.begin(ssid, password);
  Serial.println();
  Serial.println();
  Serial.print("Connecting to ");
  Serial.print(ssid);
  WiFi.begin(ssid, password);
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }
  Serial.println("");
  Serial.println("WiFi Connected");
}
 
void loop() {
//  float h = dht.readHumidity();
//  float t = dht.readTemperature();
float n = random(300);
//  if (isnan(h) || isnan(t)) {
//    Serial.println("Gagal membaca sensor DHT");
//    return;
//  }
 
//  Serial.print("Temperature: ");
//  Serial.print(t);
//  Serial.print(" *C. Humidity: ");
//  Serial.println(h);
Serial.print("Random Number: ");
Serial.println(n);
 
  if (client.connect(server,80)) {
    Serial.print("Posting data...");
    digitalWrite(BUILTIN_LED, LOW);
//    Serial.println("Temperature: " + String(t) + ", Humidity: " + String(h));
      Serial.println("Random Number: " + String(n));
//    client.println("GET /dht.php?t=" + String(t) + "&amp;amp;h=" + String(h) + "&amp;amp;i=" +SensorID+ " HTTP/1.1");
    client.println("GET /log.php?n=" + String(n));
    client.println("HOST: ");
    client.println(server);
    client.println("Connection: close");
    client.println();
 
    /*
    while (client.connected() &amp;amp;&amp;amp; !client.available()) delay(1);
    while (client.connected() || client.available()) {
      char c = client.read();
      Serial.print(c);
    }
    */
    client.stop();
    Serial.println();
 
    digitalWrite(BUILTIN_LED, HIGH);
  }
 
  delay(5000); // Beri delay 5 detik sebelum polling berikutnya
}

PHP code:

<?php
 
$db_amb = mysqli_connect("127.0.0.1", "root", "", "wemos");
if (!$db_amb) die("Gagal terkoneksi ke DB Utama. Error : " . mysqli_connect_error());
 
$n = $_REQUEST['n'];
if (!empty($n) &amp;&amp;)
{  
  $s = "insert into data_random set value1='$n'";
  $r = mysqli_query($db_amb, $s);
  echo "OK";
}
else echo "ERR";
?>;

The database is named 'wemos', and the table where i intend to store the data is named 'data_random' with 4 columns named value1-value4. My intentions is to store the random number to the 'value1' field.