Skip to content

Instantly share code, notes, and snippets.

@dgtm
Last active August 29, 2015 14:06
Show Gist options
  • Save dgtm/18e46133b51659dc33bb to your computer and use it in GitHub Desktop.
Save dgtm/18e46133b51659dc33bb to your computer and use it in GitHub Desktop.
Alert Ignition
# !/usr/local/bin/ruby
require 'rubygems'
require 'json'
require 'httparty'
# Change modem_id at your will
modem = "MO-2"
lat = -119.7579390625
lon = 36.1208411143
# Change the seconds value (24 here) every time you run this
time = Time.new(2014,11,2,2,2,ARGV[0], "-11:00")
speed = 20
class Movement
attr_accessor :modem_id, :speed, :gps_location, :point
def initialize(modem_id, speed, pos, point)
token = "d9d049a2db3e8056bb360debf1aebd348a3a9857cc3ee996bb4181e3f40870cb515fea92606ab51ad685675dd3c4f872c031d115c9501069940e35bd2f7f1dd8"
puts "New Position #{point}"
::HTTParty.post("http://localhost:4000/asset_management/telematic/#{modem_id}/gps_positions",
headers: {
'Content-Type' => 'application/vnd.agrian+json',
'Accept' => 'application/vnd.agrian+json; version=1',
'Authorization' => "Token #{token}"
},
query: { gps_position:
{
position_at: pos,
speed: speed,
gps_location: point
}
})
end
end
incr = proc do
5.times do |i|
lon += 0.01
speed += 5
time += 2
point = "POINT(#{lat} #{lon})"
current_time = time.strftime("%FT%T%:z")
Movement.new(modem, speed, current_time, point)
sleep 1
end
end
decr = proc do
6.times do |i|
lon += 0.01
speed -= 5
time += 2
point = "POINT(#{lat} #{lon})"
current_time = time.strftime("%FT%T%:z")
Movement.new(modem, speed, current_time, point)
sleep 1
end
end
incr.call
decr.call
incr.call
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment