Skip to content
Permalink
Browse files

add imperial march

  • Loading branch information...
vvzvlad committed Apr 5, 2018
1 parent a2f5579 commit 10364cea7f3e1490ac3eb916b4f4b4c095bec705
Showing with 22 additions and 1 deletion.
  1. +20 −0 iot_scada.lua
  2. +2 −1 templates/dashboard.html
@@ -1,5 +1,6 @@
#!/usr/bin/env tarantool
local mqtt = require 'mqtt'
local fiber = require 'fiber'

local config = {}
config.MQTT_WIRENBOARD_HOST = "192.168.1.59"
@@ -9,6 +10,23 @@ config.HTTP_PORT = 8080

io.stdout:setvbuf("no")

local function play_star_wars()
local function play()
local imperial_march = {{392, 350}, {392, 350}, {392, 350}, {311, 250}, {466, 100}, {392, 350}, {311, 250}, {466, 100}, {392, 700}, {392, 350}, {392, 350}, {392, 350}, {311, 250}, {466, 100}, {392, 350}, {311, 250}, {466, 100}, {392, 700}, {784, 350}, {392, 250}, {392, 100}, {784, 350}, {739, 250}, {698, 100}, {659, 100}, {622, 100}, {659, 450}, {415, 150}, {554, 350}, {523, 250}, {493, 100}, {466, 100}, {440, 100}, {466, 450}, {311, 150}, {369, 350}, {311, 250}, {466, 100}, {392, 750}}
for i = 1, #imperial_march do
local delay = imperial_march[i][2]
local freq = imperial_march[i][1]
mqtt.wb:publish("/devices/buzzer/controls/frequency/on", freq, mqtt.QOS_0, mqtt.NON_RETAIN)
mqtt.wb:publish("/devices/buzzer/controls/enabled/on", 1, mqtt.QOS_0, mqtt.NON_RETAIN)
fiber.sleep(delay/1000*2)
mqtt.wb:publish("/devices/buzzer/controls/enabled/on", 0, mqtt.QOS_0, mqtt.NON_RETAIN)
fiber.sleep(delay/1000/3)
end
end
fiber.create(play)
end


local function http_server_action_handler(req)
local type_param, action_param = req:param("type"), req:param("action")

@@ -19,6 +37,8 @@ local function http_server_action_handler(req)
command = "1"
elseif (action_param == "off") then
command = "0"
elseif (action_param == "sw") then
play_star_wars()
end
local result = mqtt.wb:publish("/devices/buzzer/controls/enabled/on", command, mqtt.QOS_1, mqtt.NON_RETAIN)
return req:render{ json = { mqtt_result = result } }
@@ -38,9 +38,10 @@
<main role="main" class="col-md-11 ml-sm-auto col-lg-11 pt-3 px-4">
<form>
<div class="row input-group">
<div class="col-md-3 mb-1">
<div class="col-md-11 mb-1">
<button type="button" action-button="on" class="btn btn-success mqtt-buttons">On buzzer</button>
<button type="button" action-button="off" class="btn btn-success mqtt-buttons">Off buzzer</button>
<button type="button" action-button="sw" class="btn btn-success mqtt-buttons">Play Imperial march</button>
</div>
</div>
</form>

0 comments on commit 10364ce

Please sign in to comment.
You can’t perform that action at this time.