Skip to content

Commit

Permalink
Build version v1.1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Nicklas2751 committed Mar 8, 2017
1 parent 5eafaf4 commit 5304ac9
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 1 deletion.
13 changes: 13 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Version v1.1.0

## Improved usability

The script saves now the device codes in the config and listens to pseudo codes consisting of the device number and the state.
Like `10` for the first device `1` and the state off `0`. It also listens for other commands like `restart`which restarts the NodeMCU.
If the device gets an command which is unkown it logs help text with all codes and commands.

# Version v1.0.0

## First stable version 1.0.0.

The script sends directly the recived codes.
13 changes: 13 additions & 0 deletions config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,16 @@ config.broker.pass = ''
config.topic.switch433mhz.path = 'switches/433mhz/' -- include trailing slash!
config.topic.switch433mhz.qos = 0
config.topic.switch433mhz.retain = 0

-- Codes
config.codes.device1.on = 4527445
config.codes.device1.off = 4527444

config.codes.device2.on = 4539733
config.codes.device2.off = 4539732

config.codes.device3.on = 4542805
config.codes.device3.off = 4542804

config.codes.device4.on = 4543573
config.codes.device4.off = 4543572
49 changes: 48 additions & 1 deletion run.lua
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,12 @@ config.net = {}
config.broker = {}
config.topic = {}
config.topic.switch433mhz = {}
config.codes = {}
config.codes.device1 = {}
config.codes.device2 = {}
config.codes.device3 = {}
config.codes.device4 = {}

dofile('config.lua')

-------------------------------------------------------------------------------
Expand Down Expand Up @@ -61,6 +67,10 @@ function mqtt_offline(client)
log('MQTT disconnected')
end

function sendCode(code)
rc.send(4,code,24,185,1,2) --Sends the data via GPIO pin 4 to the rc switch.
end

function startListen()
log('Start listening...')
-- MQTTC:publish(config.topic.inp.path,'Test',config.topic.inp.qos,config.topic.inp.retain)
Expand All @@ -71,7 +81,44 @@ function startListen()
MQTTC:on("message", function(conn, topic, data)
if data ~= nil and topic == config.topic.switch433mhz.path then
log("Recived: "..data)
rc.send(4,data,24,185,1,10) --Sends the data via GPIO pin 4 to the rc switch.

--Set off
if data == "10" then -- Device 1 off
sendCode(config.codes.device1.off)
elseif data == "20" then -- Device 2 off
sendCode(config.codes.device2.off)
elseif data == "30" then -- Device 3 off
sendCode(config.codes.device3.off)
elseif data == "40" then -- Device 4 off
sendCode(config.codes.device4.off)

--Set on
elseif data == "11" then -- Device 1 on
sendCode(config.codes.device1.on)
elseif data == "21" then -- Device 2 on
sendCode(config.codes.device2.on)
elseif data == "31" then -- Device 3 on
sendCode(config.codes.device3.on)
elseif data == "41" then -- Device 4 on
sendCode(config.codes.device4.on)

--Special commands
elseif data == "restart" then -- Restart the nodeMCU
node.restart()
else
log("Got invalid data: "..data)
log("-------------------------")
log("This are the codes for the devices: ")
log("Device 01: 10 OFF | 11 ON")
log("Device 02: 20 OFF | 21 ON")
log("Device 03: 30 OFF | 31 ON")
log("Device 04: 40 OFF | 41 ON")
log("-------------------------")
log("This are the special commands:")
log("restart | Restarts the nodeMCU")
log("-------------------------")
end

end
end)
end
Expand Down

0 comments on commit 5304ac9

Please sign in to comment.