Pokud, ale napíši do prohlížeče https://mujweb.cz/logger.php/?hodnota=1000 data se načtou.
Můj kód:
Kód: Vybrat vše
// připojení knihoven
#include <OneWire.h>
#include <SPI.h>
#include <ESP8266WiFi.h>
const char* ssid = "SSID";
const char* password = "heslo";
char host []= "mujweb.cz";
WiFiClient client;
void setup() {
Serial.begin(115200);
delay(10);
senzoryDS.begin();
delay(5000);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.println("WiFi pripojena");
Serial.println("IP adresa: ");
Serial.println(WiFi.localIP());
}
void loop() {
if(client.connect(host, 80)){
delay(1000);
Serial.println("OK");
client.print("GET http://mujweb.cz/logger.php/?hodnota=");
client.print("125");
client.print(" HTTP/1.1\r\n"); //tohle ve verzi na arduino.cz neni, zkousela jsem hledat dalsi zdroje
client.println("Host: mujweb.cz");
client.println("Accept: text/html, application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8");
client.println("Connection: close");
client.println();
client.stop();
delay(5000);
}
}
Kód: Vybrat vše
<?php
$server = "localhost";
$user = "user";
$pass = "heslo";
$db = "data";
$mysqli = mysqli_connect($server, $user, $pass, $db); //připojení k MySQL
if($mysqli and isset($_GET['hodnota'])){ //pokud GET obsahuje 'hodnota', pokračuj
$hodnota = sanitize($_GET['hodnota']);
$sql = "INSERT INTO data (hodnota) VALUES (".$hodnota.")"; //sestavení SQL
$doSql = $mysqli->query($sql); //vykonání SQL
if($doSql){ //test úspěchu
echo 'Zápis byl úspěšný';
}
else{
echo 'Něco se nepovedlo';
}
}
else{
echo "Neco je špatně";
}
function sanitize($input){ //ořízne řetězec
$input = htmlspecialchars($input);
$input = htmlentities($input);
$input = strip_tags($input);
$input = trim($input);
return $input;
}
?>