Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- PHP:
- <?php
- $server = "localhost";
- $user = "uzivatel";
- $pass = "heslo";
- $db = "jmeno_databaze";
- $mysqli = mysqli_connect($server, $user, $pass, $db); //připojení k MySQL
- if($mysqli and and isset($_GET['hodnota1']) and isset($_GET['hodnota2'])){
- $hodnota1 = sanitize($_GET['hodnota1']);
- $hodnota2 = sanitize($_GET['hodnota2']);
- $sql = "INSERT INTO arduino_data (hodnota1, hodnota2) VALUES (".$hodnota1.",".$hodnota2.")"; //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;
- }
- ?>
- V Arduinu:
- #include <SPI.h>
- #include <Ethernet.h>
- byte mac[] = {0x90, 0xA2, 0xDA, 0x00, 0x9C, 0xB7}; //MAC adresa
- IPAddress ip(10,0,0,3); //IP adresa
- char server[] = "arduino.cz"; //URL adresa serveru
- EthernetClient client;
- void setup() {
- Serial.begin(9600);
- if (Ethernet.begin(mac) == 0) {
- Ethernet.begin(mac, ip);
- }
- delay(1000);
- }
- void loop() {
- if(client.connect(server, 80)){
- delay(1000);
- Serial.println("OK");
- client.print("GET https://arduino.cz/data/logger.php?hodnota1=");
- client.print(analogRead(A5));
- client.print("&hodnota2=")
- client.println(analogRead(A6));
- client.println("Host: arduino.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);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment