Queste sono le differenze tra la revisione selezionata e la versione attuale della pagina.
| Prossima revisione | Revisione precedente | ||
|
raspberry:relay [2017/10/05 22:40] stefano creata |
raspberry:relay [2023/04/17 14:25] (versione attuale) |
||
|---|---|---|---|
| Linea 63: | Linea 63: | ||
| per un totale con tutte e 8 le bobine eccitate di 2,8 watt\\ | per un totale con tutte e 8 le bobine eccitate di 2,8 watt\\ | ||
| ed un assorbimento minimo di 27 milliampere e un massimo di circa 220 milliampere\\ | ed un assorbimento minimo di 27 milliampere e un massimo di circa 220 milliampere\\ | ||
| + | |||
| + | ==== Esperienza con gpio ==== | ||
| + | su raspbian versione 9\\ | ||
| + | Abilitazione degli strumenti gpio e del python\\ | ||
| + | poi installazione di apache2 e del php5\\ | ||
| + | attenzione di default viene installato il php7 e per mezza giornata non ha funzionato nulla fino a che ho installato anche il php5\\ | ||
| + | creare su / | ||
| + | <file html index.html> | ||
| + | <!-- | ||
| + | Bootstrap | ||
| + | Switch buttons | ||
| + | Jquery | ||
| + | --> | ||
| + | |||
| + | < | ||
| + | < | ||
| + | <meta charset=" | ||
| + | <!-- for mobile version --> | ||
| + | <meta name=" | ||
| + | <link href=" | ||
| + | <link href=" | ||
| + | <script src=" | ||
| + | <script src=" | ||
| + | |||
| + | </ | ||
| + | |||
| + | |||
| + | < | ||
| + | <h3>4 Array relay Web App</ | ||
| + | ^M | ||
| + | < | ||
| + | < | ||
| + | <!-- creating table -->^M | ||
| + | < | ||
| + | < | ||
| + | < | ||
| + | <!-- creating button for the relay -->^M | ||
| + | < | ||
| + | </ | ||
| + | < | ||
| + | < | ||
| + | < | ||
| + | </ | ||
| + | < | ||
| + | < | ||
| + | < | ||
| + | </ | ||
| + | < | ||
| + | < | ||
| + | < | ||
| + | </ | ||
| + | ^M | ||
| + | ^M | ||
| + | </ | ||
| + | ^M | ||
| + | <!-- feedback paragraphs -->^M | ||
| + | ^M | ||
| + | < | ||
| + | ^M | ||
| + | < | ||
| + | ^M | ||
| + | < | ||
| + | ^M | ||
| + | < | ||
| + | </ | ||
| + | ^M | ||
| + | <script type=" | ||
| + | ^M | ||
| + | ^M | ||
| + | //setting all buttons off state to be red color^M | ||
| + | $.fn.bootstrapSwitch.defaults.offColor=" | ||
| + | |||
| + | // | ||
| + | $(" | ||
| + | $(" | ||
| + | $(" | ||
| + | $(" | ||
| + | |||
| + | //this will be execute when the html is ready | ||
| + | $(document).ready(function(){ | ||
| + | |||
| + | //ajax request with post method (better to be GET) | ||
| + | $.ajax({ | ||
| + | method: " | ||
| + | url: " | ||
| + | data: {} | ||
| + | }; | ||
| + | .done(function( msg ) { | ||
| + | // we need to parse the responce 2 times | ||
| + | msg = JSON.parse(msg); | ||
| + | msg = JSON.parse(msg); | ||
| + | |||
| + | //for loop that is implemented for the feedback divs and buttons state | ||
| + | for(var i = 0 ; i < 4; i++){ | ||
| + | |||
| + | // setting the feedback divs | ||
| + | if(msg[i] == true){ | ||
| + | $("# | ||
| + | }else{ | ||
| + | $("# | ||
| + | } | ||
| + | //setting the current button state | ||
| + | $(" | ||
| + | } | ||
| + | }); | ||
| + | }); | ||
| + | |||
| + | // making onclick event listener for the buttons ^M | ||
| + | $(' | ||
| + | ' | ||
| + | ' | ||
| + | ' | ||
| + | |||
| + | // checking whitch button is clicked | ||
| + | var relayID = event.target.id.substring(event.target.id.length - 1); | ||
| + | |||
| + | //ajax POST request | ||
| + | $.ajax({ | ||
| + | method: " | ||
| + | url: " | ||
| + | data: { clicked :state , relayId: | ||
| + | }) | ||
| + | .done(function( msg ) { | ||
| + | // changing the feedback paragraphs | ||
| + | if(msg == " | ||
| + | $("# | ||
| + | }else{ | ||
| + | $("# | ||
| + | } | ||
| + | |||
| + | }); | ||
| + | |||
| + | |||
| + | }); | ||
| + | </ | ||
| + | |||
| + | </ | ||
| + | |||
| + | </ | ||
| + | |||
| + | </ | ||
| + | |||
| + | |||
| + | |||
| + | Di default | ||