madmax55 | Bonjours a tous , j'ai un petit soucie dans mon projet .
Le projet : je veut avoir les données d'un accéléromètre a signal analogique sur un Fichier html de ma raspberry pi , or je passe par l'intermédiaire d'une carte arduino .
Voici les programmes que j'ai trouver sur le web : Programme arduino : Code :
- ------------------------------domotique.ino
- // Speak to arduino with PHP
- // CC BY-NC-SA 2012 lululombard
- // Made to work with statebeta.php and serial.sh
- // Not yet commented, it's beta !
- void setup() {
- Serial.begin(115200);
- for (byte i = 2; i <= 13; ++i)
- pinMode(i, OUTPUT);
- }
- void loop() {
- if (Serial.available()) {
- byte cmd = Serial.read();
- switch (cmd) {
- case '1':
- Serial.println();
- for (byte i = 2; i <= 13; ++i){
- Serial.print(digitalRead(i));
- if (i != 13)
- Serial.write(';');
- }
- break;
- case '2':
- for (byte i = 0; i <= 25; ++i){
- Serial.println("BOOT FILLING LINES FOR SCREEN" );
- }
- break;
- case 'a'...'l': // GCC only (Not C standard)
- byte pin = cmd - 'a' + 2;
- if (digitalRead(pin) == LOW)
- digitalWrite(pin, HIGH);
- else
- digitalWrite(pin, LOW);
- break;
- }
- }
- }
|
Php et fichier sh pour la raspberry pi :
Code :
- ---------------------statebeta.php
- <?php
- // Speak to arduino with PHP
- // CC BY-NC-SA 2012 lululombard
- // You need serial.sh with chmod 777 in /var/www to use this.
- // You need to disable terminal on /dev/ttyAMA0 : "nano /boot/cmdline.txt", and delete "console=ttyAMA0,115200 kgdboc=ttyAMA0,115200". CTRL+X to save.
- // Then, "nano /etc/inittab", go to the last line and add "#" in front of "2:23:respawn:/sbin/getty -L ttyAMA0 115200 vt100"
- // Made to work with "domotique.ino", with ardunio connected to rx/tx of the GPIOs
- // Not yet commented, as the name says, it's beta !
- $screen_name = "arduino";
- $user = "www-data";
- $list = shell_exec("ls /var/run/screen/S-".$user);
- if (strpos($list, $screen_name) == FALSE) {
- exec('screen15
- -dmS arduino /dev/ttyAMA0 115200');
- sleep(1);
- exec('screen -S arduino -X height 1');
- exec('/var/www/serial.sh 2');
- header('Location: '.$_SERVER['PHP_SELF']);
- }
- elseif ($_GET['pin']) {
- $allowed = array("a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l" );
- if (in_array($_GET['pin'], $allowed)) {
- exec('/var/www/serial.sh '.$_GET['pin']);
- header('Location: '.$_SERVER['PHP_SELF']);
- }
- else {
- echo "Caractere non pris en charge.<br />";
- }
- }
- else {
- exec('/var/www/serial.sh 1');
- exec('screen -S arduino -X hardcopy /var/www/status.txt');
- $serial = exec('tail -1 /var/www/status.txt');
- $status = explode(";", $serial);
- $on="ON";
- $off="OFF";
- $checked_pin = 0;
- foreach ($status as $actual_pin) {
- if($actual_pin == 1){$text[$checked_pin]=$off;}else{$text[$checked_pin]=$on;}
- $checked_pin++;
- }
- $pin = 2;
- $checked_pin = 0;
- $pins_order = array("a","b","c","d","e","f","g","h","i","j","k","l" );
- foreach ($text as $actual_pin) {
- echo "PIN ".$pin.": ".$status[$checked_pin]." <a href=\"?pin=".$pins_order[$checked_pin]."\">". $actual_pin ."</a><br />";
- $checked_pin++;
- $pin++;
- }
- }
- ?>
- -------------------------------serial.sh
- #!/bin/bash
- # Made to work along with statebeta.sh
- if [ $# = 0 ]
- then
- echo Usage : $0 *data*
- else
- screen -S arduino -X eval "stuff $1"
- echo screen -S arduino -X eval "stuff $1"
- fi
|
Voila maintenant la question est comment avoir les données sur un HTML , je voudrais comprendre comment sa marche et que mettre en place pour que cela fonctionne car je débute dans le milieux . Un grand merci pour vos réponses XD |