v arduinu mám :
Kód: Vybrat vše
#include <SPI.h>
#include <UIPEthernet.h> // Used for Ethernet
byte mac[] = { 0x90, 0xA2, 0xDA, 0x0D, 0x78, 0xEE };
unsigned long cas = 0;
// ********************************************
// ***************EDITACE *********************
// ********NUTNO DODRŽET ADRESU SOUBORU *******
// ********/reset1.php reset2.php *******
// ********************************************
// **** NASTAVENI SITE****
IPAddress ip(192, 168, 1, 82); //IP ADRESA
IPAddress gateway(192, 168, 1, 1); // VYCHOZI BRANA
IPAddress subnet(255, 255, 255, 0); // MASKA
IPAddress dnServer(8, 8, 4, 4); // DNS
int ID_MODULU = 2;
char serverName[] = "xxx.eu"; // webserver
// ********************************************
// ********************************************
// ********************************************
EthernetClient client;
void setup() {
Serial.begin(9600);
pinMode(4, OUTPUT);
Ethernet.begin(mac, ip, dnServer, gateway, subnet);
Serial.print("ip-");
Serial.println( Ethernet.localIP());
Serial.print("Subnet mask-");
Serial.println( Ethernet.subnetMask());
Serial.print("Gateway-");
Serial.println( Ethernet.gatewayIP());
Serial.print("DNS-");
Serial.println( Ethernet.dnsServerIP());
}
void loop() {
if (millis() - cas >= 6000 || cas == 0) {
cas = millis();
if (client.connect(serverName, 80)) { //starts client connection, checks for connection
client.print("GET http://xxx.eu/reset");
client.print(ID_MODULU);
client.println(".php HTTP/1.0");
client.println("Host: xxx.eu");
client.println("Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8");
client.println("Connection: close");
client.println();
delay(1000);
while (client.connected()) {
String line = client.readStringUntil('\n');
// Serial.println(line); //ak chceme vypísať HTTP header
if (line == "\r") {
break;
}
}
String line = client.readStringUntil('\n');
Serial.println("Nacitany payload response:");
Serial.println(line); //odpoveď webservera - naše dáta
if(line=="0"){
digitalWrite(4, LOW);
if (client.connect(serverName, 80)) {
client.print("GET http://xxx.eu/logger.php?text=Čidlo číslo ");
client.print(ID_MODULU);
client.println(" vypnuto");
client.println("Host: kxxx.eu");
client.println("Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8");
client.println("Connection: close");
client.println();
}
}
else if(line=="1"){
digitalWrite(4, HIGH);
if (client.connect(serverName, 80)) {
client.print("GET http://xxx.eu/logger.php?text=Čidlo číslo ");
client.print(ID_MODULU);
client.println(" zapnuto");
client.println("Host: xxx.eu");
client.println("Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8");
client.println("Connection: close");
client.println();
}
}
}
} else {
Serial.println("Pripojenie na webserver sa nepodarilo");
}
client.stop();
}
Kód: Vybrat vše
<?php
$server = "localhost";
$user = "kony";
$pass = "heslo";
$db = "jirka";
$mysqli = mysqli_connect($server, $user, $pass, $db); //připojení k MySQL
$datum = StrFTime("%Y-%m-%d_%H:%M:%S", Time());
if($mysqli && isset($_GET['text'])){ //pokud GET obsahuje 'hodnota', pokračuj
$text = sanitize($_GET['text']);
$sql = "INSERT INTO log (text, time) VALUES ('".$text."', '".$datum."')"; //sestavení SQL
$doSql = $mysqli->query($sql); //vykonání SQL
if($doSql){ //test úspěchu
echo 'Zápis byl úspěšný';
echo $datum;
}
else{
echo 'Něco se nepovedlo';
echo $datum;
}
}
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;
}
?>
ID : ID
time : Timestamp
text : prosty text
a ani zaboha nemůžu přijít co je špatně