Created
December 2, 2014 06:00
-
-
Save edy555/5318766393b6dd832f69 to your computer and use it in GitHub Desktop.
FlashAirでLチカ4種類。html+javascript, python, ruby, shell script http://youtu.be/GXY_FRvI-vY
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN"> | |
| <html> <head> | |
| <title>FlashAir GPIO Test</title> | |
| </head> | |
| <body> | |
| <p> | |
| <input type="button" id="on" value="On"> | |
| <input type="button" id="off" value="Off"> | |
| </p> | |
| <p> | |
| <input type="button" id="start" value="Start"> | |
| <input type="button" id="stop" value="Stop"> | |
| </p> | |
| <script> | |
| function gpio_out(data, callback) { | |
| var url = "/command.cgi?op=190&CTRL=0x1f&DATA=" + String(data) | |
| var xhr = new XMLHttpRequest(); | |
| var length = 0; | |
| xhr.onreadystatechange = function () { | |
| if ( xhr.readyState === xhr.DONE ) { | |
| if ( xhr.status === 200 || xhr.status === 0 ) { | |
| if (callback) { | |
| var json = JSON.parse(xhr.responseText); | |
| callback(json); | |
| } | |
| } else { | |
| console.error("fail to set gpio ["+url+"] ["+xhr.status+"]"); | |
| } | |
| } | |
| }; | |
| xhr.open("GET", url, true); | |
| xhr.withCredentials = this.withCredentials; | |
| xhr.send(null); | |
| }; | |
| var enable = 0; | |
| var flag = 0; | |
| function start() { | |
| enable = 1; | |
| function fire() { | |
| if (!enable) | |
| return; | |
| flag = !flag; | |
| gpio_out(flag ? 0x1f : 0, | |
| function() { | |
| setTimeout(fire, 500); | |
| }); | |
| } | |
| fire(); | |
| } | |
| function stop() { | |
| enable = 0; | |
| } | |
| btn = document.getElementById('on'); | |
| btn.addEventListener('click', function() { gpio_out(0x1f); }); | |
| btn = document.getElementById('off'); | |
| btn.addEventListener('click', function() { gpio_out(0x00); }); | |
| btn = document.getElementById('start'); | |
| btn.addEventListener('click', start); | |
| btn = document.getElementById('stop'); | |
| btn.addEventListener('click', stop); | |
| </script> | |
| </body> | |
| </html> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env python | |
| import urllib2 | |
| import time | |
| #gpiourl="http://flashair.local/command.cgi?op=190&CTRL=0x1f&DATA=" | |
| gpiourl="http://192.168.0.1/command.cgi?op=190&CTRL=0x1f&DATA=" | |
| def gpio_set(x): | |
| resp = urllib2.urlopen(gpiourl + str(x)) | |
| resp.close() | |
| while True: | |
| gpio_set(0x1f) | |
| time.sleep(0.5) | |
| gpio_set(0x00) | |
| time.sleep(0.5) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env ruby | |
| require 'open-uri' | |
| def gpio_set(x) | |
| gpiourl="http://192.168.0.1/command.cgi?op=190&CTRL=0x1f&DATA=" | |
| #gpiourl="http://flashair.local/command.cgi?op=190&CTRL=0x1f&DATA=" | |
| open(gpiourl + x.to_s) | |
| end | |
| while true do | |
| gpio_set(0x1f) | |
| sleep(0.5) | |
| gpio_set(0x00) | |
| sleep(0.5) | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/sh | |
| gpiourl='http://192.168.0.1/command.cgi?op=190&CTRL=0x1f&DATA=' | |
| function gpio_set() { | |
| curl -s ${gpiourl}$1 >/dev/null | |
| } | |
| while true; do | |
| gpio_set 0x1f | |
| sleep 0.5 | |
| gpio_set 0x00 | |
| sleep 0.5 | |
| done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment