Last active
August 29, 2015 14:04
-
-
Save ik5/59355ea92fab025bb4a8 to your computer and use it in GitHub Desktop.
arduino based red color alarm for israeli missiles alert - a PoC video: http://youtu.be/AdF2AGIjtvY
This file contains 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
int led = 13; | |
int in = 0; | |
void setup() { | |
pinMode(led, OUTPUT); | |
Serial.begin(9600); | |
} | |
void loop() { | |
if (Serial.available() == 0) { | |
return; | |
} | |
in = Serial.read() - 48; | |
Serial.print("I received: "); | |
Serial.println(in, DEC); | |
if (in == 1) { | |
Serial.write("in == 1"); | |
digitalWrite(led, HIGH); | |
delay(1500); | |
digitalWrite(led,LOW); | |
delay(100); | |
} else { | |
digitalWrite(led,LOW); | |
} | |
} |
This file contains 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' | |
require 'json' | |
require 'serialport' # gem install serialport | |
PKR_URL = 'http://www.oref.org.il/WarningMessages/alerts.json' | |
AREA_FMT = 'מרחב: %s, קוד מרחב: %s' | |
LOG_FMT = '[%s] id: %s, %s' | |
def to_json | |
request = Time.now | |
data = open(PKR_URL).read.force_encoding('utf-16').encode('utf-8') | |
answer = Time.now | |
print "Took #{answer - request} time to retrive data " | |
JSON.parse(data) | |
end | |
def exec | |
log = open(File.expand_path(File.dirname(__FILE__), 'alarm2.log'), 'a+') | |
serial = SerialPort.new('/dev/ttyACM3') | |
serial.baud = 9600 | |
while true do | |
json = to_json | |
next if json['title'].strip == 'בדיקה' | |
p json | |
unless json['data'].empty? || json['data'].include?('בדיקה') | |
# sometimes they break things :( | |
if json['data'].length == 1 && json['data'].include?(',') | |
json['data'] = json['data'][0].split(/,\s{0,}/) | |
end | |
json['data'].map! do |x| | |
x =~ /^([\p{hebrew}\s]+[^\s])\s(\d+)$/ | |
x = AREA_FMT % [$1, $2] rescue x | |
end | |
list = json['data'].join(' | ') | |
line = LOG_FMT % [Time.now.strftime('%D %T'), json['id'], list] | |
puts line | |
log.puts line | |
serial.write(1) | |
end | |
log.flush | |
sleep 1 | |
end | |
ensure | |
log.close | |
serial.close | |
end | |
exec | |
#job = fork do | |
# exec | |
#end | |
# | |
#Process.detach(job) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment