Skip to content

Instantly share code, notes, and snippets.

@ik5 ik5/ard_red.ino
Last active Aug 29, 2015

Embed
What would you like to do?
arduino based red color alarm for israeli missiles alert - a PoC video: http://youtu.be/AdF2AGIjtvY
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);
}
}
#!/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
You can’t perform that action at this time.