Skip to content

Commit

Permalink
Merge pull request #64 from konnected-io/beta
Browse files Browse the repository at this point in the history
2.2.1 beta
  • Loading branch information
heythisisnate authored Jun 22, 2018
2 parents 8c53c98 + 50e2b9f commit 7e760c4
Show file tree
Hide file tree
Showing 30 changed files with 185 additions and 420 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
* for the specific language governing permissions and limitations under the License.
*
*/

metadata {
definition (name: "Konnected Temperature & Humidity Sensor (DHT)", namespace: "konnected-io", author: "konnected.io") {
capability "Temperature Measurement"
Expand All @@ -21,7 +22,7 @@ metadata {

preferences {
input name: "pollInterval", type: "number", title: "Polling Interval (minutes)",
defaultValue: 3,
defaultValue: defaultPollInterval(),
description: "Frequency of sensor updates"
}

Expand Down Expand Up @@ -78,5 +79,9 @@ def updateStates(states) {
}

def pollInterval() {
return pollInterval
return pollInterval.isNumber() ? pollInterval : defaultPollInterval()
}

def defaultPollInterval() {
return 3 // minutes
}
14 changes: 8 additions & 6 deletions firmware/2.2.0/app/include/user_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,9 @@ extern void luaL_assertfail(const char *file, int line, const char *message);

#define ICACHE_STORE_TYPEDEF_ATTR __attribute__((aligned(4),packed))
#define ICACHE_STORE_ATTR __attribute__((aligned(4)))
#define ICACHE_RAM_ATTR __attribute__((section(".iram0.text")))
#define ICACHE_RAM_STRING(x) ICACHE_RAM_STRING2(x)
#define ICACHE_RAM_STRING2(x) #x
#define ICACHE_RAM_ATTR __attribute__((section(".iram0.text." __FILE__ "." ICACHE_RAM_STRING(__LINE__))))
#ifdef GPIO_SAFE_NO_INTR_ENABLE
#define NO_INTR_CODE ICACHE_RAM_ATTR __attribute__ ((noinline))
#else
Expand All @@ -61,7 +63,7 @@ extern void luaL_assertfail(const char *file, int line, const char *message);

// SSL buffer size used only for espconn-layer secure connections.
// See https://github.com/nodemcu/nodemcu-firmware/issues/1457 for conversation details.
#define SSL_BUFFER_SIZE 6178
#define SSL_BUFFER_SIZE 4196

#define CLIENT_SSL_ENABLE
//#define MD2_ENABLE
Expand All @@ -78,7 +80,7 @@ extern void luaL_assertfail(const char *file, int line, const char *message);
// maximum number of open files for SPIFFS
#define SPIFFS_MAX_OPEN_FILES 4

// Uncomment this next line for fastest startup
// Uncomment this next line for fastest startup
// It reduces the format time dramatically
// #define SPIFFS_MAX_FILESYSTEM_SIZE 32768
//
Expand Down Expand Up @@ -114,10 +116,10 @@ extern void luaL_assertfail(const char *file, int line, const char *message);
#define WIFI_SDK_EVENT_MONITOR_ENABLE
#define WIFI_EVENT_MONITOR_DISCONNECT_REASON_LIST_ENABLE

////#define ENABLE_TIMER_SUSPEND
//#define PMSLEEP_ENABLE
//#define PMSLEEP_ENABLE // Enable wifi.suspend() and node.sleep() (NOTE: node.sleep() is dependent on TIMER_SUSPEND_ENABLE)
//#define TIMER_SUSPEND_ENABLE //Required by node.sleep()


#define STRBUF_DEFAULT_INCREMENT 32

#endif /* __USER_CONFIG_H__ */
#endif /* __USER_CONFIG_H__ */
4 changes: 4 additions & 0 deletions firmware/2.2.0/app/include/user_modules.h
Original file line number Diff line number Diff line change
Expand Up @@ -86,5 +86,9 @@
//#define LUA_USE_MODULES_WS2812_EFFECTS
//#define LUA_USE_MODULES_XPT2046

//debug modules
//#define LUA_USE_MODULES_SWTMR_DBG //SWTMR timer suspend Debug functions


#endif /* LUA_CROSS_COMPILER */
#endif /* __USER_MODULES_H__ */
Binary file modified firmware/konnected-filesystem-0xa0000-32mb.bin
Binary file not shown.
Binary file not shown.
2 changes: 1 addition & 1 deletion scripts/build-firmware
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/bin/bash

FIRMWARE_PATH=${PWD}/../nodemcu-firmware
IMAGE_NAME=konnected-firmware-2-2-0
IMAGE_NAME=konnected-firmware-2-2-1

cp firmware/2.2.0/app/include/* $FIRMWARE_PATH/app/include/
cp src/* $FIRMWARE_PATH/local/fs
Expand Down
2 changes: 1 addition & 1 deletion scripts/flash
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/bash

FIRMWARE_NAME=konnected-firmware-2-2-0
FIRMWARE_NAME=konnected-firmware-2-2-1
FILESYSTEM_NAME=konnected-filesystem-0xa0000-32mb
PORT=/dev/cu.wchusbserial1410

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
* for the specific language governing permissions and limitations under the License.
*
*/
public static String version() { return "2.2.1" }

definition(
name: "Konnected (Connect)",
namespace: "konnected-io",
Expand All @@ -29,6 +31,7 @@ preferences {
page(name: "mainPage", title: "Konnected Devices", install: true, uninstall: true) {
section {
app(name: "childApps", appName: "Konnected Service Manager", namespace: "konnected-io", title: "Add a Konnected device", multiple: true)
paragraph "Konnected (Connect) v${version()}"
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
* for the specific language governing permissions and limitations under the License.
*
*/
public static String version() { return "2.2.1" }

definition(
name: "Konnected Service Manager",
parent: "konnected-io:Konnected (Connect)",
Expand Down Expand Up @@ -102,6 +104,7 @@ def pageWelcome() {
name: "device_" + device.mac,
image: "https://docs.konnected.io/assets/favicons/apple-touch-icon.png",
title: "Device status",
description: getDeviceIpAndPort(device),
url: "http://" + getDeviceIpAndPort(device)
)
} else {
Expand All @@ -116,12 +119,13 @@ def pageWelcome() {
section("Help & Support") {
href(
name: "pageWelcomeManual",
title: "Instructions & Documentation",
description: "Tap to view the online documentation at http://docs.konnected.io",
title: "Instructions & Knowledge Base",
description: "Tap to view the support portal at help.konnected.io",
required: false,
image: "https://raw.githubusercontent.com/konnected-io/docs/master/assets/images/manual-icon.png",
url: "http://docs.konnected.io/security-alarm-system/"
url: "https://help.konnected.io"
)
paragraph "Konnected Service Manager v${version()}"
}
}
}
Expand Down Expand Up @@ -170,7 +174,7 @@ private pageSelectHwType() {
description: "Tap to select",
page: "pageConfiguration",
params: [hwType: "alarmPanel"],
image: "https://s3.us-east-2.amazonaws.com/konnected-io/icon-alarmpanel.jpg",
image: "https://s3.us-east-2.amazonaws.com/konnected-io/konnected-alarm-panel-st-icon-t.jpg",
)
href(
name: "NodeMCU Base",
Expand Down Expand Up @@ -224,6 +228,22 @@ private pageAssignPins() {
}
}
}
section(title: "Advanced settings") {
input(
name: "blink",
type: "bool",
title: "Blink LED on transmission",
required: false,
defaultValue: true
)
input(
name: "enableDiscovery",
type: "bool",
title: "Enable device discovery",
required: false,
defaultValue: true
)
}
}
}

Expand Down Expand Up @@ -379,7 +399,7 @@ def updateSettingsOnDevice() {
def mac = device.mac

getAllChildDevices().each {
def pin = it.deviceNetworkId.split("\\|")[1]
def pin = Integer.parseInt(it.deviceNetworkId.split("\\|")[1])
if (it.name.contains("DHT")) {
dht_sensors = dht_sensors + [ pin : pin, poll_interval : it.pollInterval() ]
} else if (sensorsMap()[it.name]) {
Expand All @@ -391,10 +411,14 @@ def updateSettingsOnDevice() {

log.debug "Configured sensors on $mac: $sensors"
log.debug "Configured actuators on $mac: $actuators"
log.debug "Configured DHT sensors on $mac: $dht_sensors"

log.debug "Blink is: ${settings.blink}"
def body = [
token : state.accessToken,
apiUrl : apiServerUrl + "/api/smartapps/installations/" + app.id,
blink: settings.blink,
discovery: settings.enableDiscovery,
sensors : sensors,
actuators : actuators,
dht_sensors : dht_sensors
Expand Down
4 changes: 2 additions & 2 deletions spec/device_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ describe("device", function()
end)

it("has expected properties", function()
assert.equal(device.swVersion, "2.1.4")
assert.equal(device.hwVersion, "2.0.5")
assert.equal(device.swVersion, "2.2.1")
assert.equal(device.hwVersion, "2.2.1")
assert.equal(device.name, "Konnected")
end)

Expand Down
6 changes: 6 additions & 0 deletions spec/nodemcu_stubs.lua
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,12 @@ _G.net = {
listen = function() end,
on = function() end
}
end,
createUDPSocket = function()
return {
listen = function() end,
on = function() end
}
end
}

Expand Down
16 changes: 7 additions & 9 deletions spec/server_device_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,51 +2,49 @@ describe("server_device", function()
local server, response

setup(function()
_G.sjson = require("sjson")
_G.sjson = require("cjson")
_G.blinktimer = mock({ start = function() end })
server = require("server_device")
require("spec/nodemcu_stubs")
end)

describe("updating a device pin state", function()
before_each(function()
spy.on(_G.gpio, 'write')
response = mock({ send = function(str) end })
end)

describe("a normal switch", function()
before_each(function()
server.process({
response = require("server_device")({
contentType = "application/json",
method = "PUT",
body = {
pin = 1,
state = 1
}
}, response)
})
end)

it("updates the state of the pin", function()
assert.spy(_G.gpio.write).was.called_with(1, 1)
end)

it("responds with the new pin state", function()
assert.stub(response.send).was.called_with(sjson.encode({ pin = 1, state = 1 }))
assert.are.equal(response, sjson.encode({ pin = 1, state = 1 }))
end)

end)

describe("a momentary switch", function()
before_each(function()
server.process({
response = require("server_device")({
contentType = "application/json",
method = "PUT",
body = {
pin = 1,
state = 1,
momentary = 500
}
}, response)
})
end)

it("updates the state of the pin on and then off", function()
Expand All @@ -58,7 +56,7 @@ describe("server_device", function()
end)

it("responds with the new pin state", function()
assert.stub(response.send).was.called_with(sjson.encode({ pin = 1, state = 0 }))
assert.are.equal(response, sjson.encode({ pin = 1, state = 0 }))
end)
end)
end)
Expand Down
6 changes: 3 additions & 3 deletions spec/server_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ describe("server", function()
MAN: "ssdp:discover"
HOST:239.255.255.250:1900
ST: urn:schemas-konnected-io:device:Security:1
]])
]], 17234, '192.168.1.111')
end

setup(function()
require("spec/nodemcu_stubs")
_G.net.createServer = function()
_G.net.createUDPSocket = function()
return {
listen = function() end,
on = function(_, event, fn)
Expand All @@ -24,7 +24,7 @@ describe("server", function()
end)

before_each(function()
conn = mock({send = function(_, resp) response = resp end})
conn = mock({send = function(_, port, ip, resp) response = resp end})
nodemcu.wifi.sta.ip = '192.168.1.100'
require("server")
end)
Expand Down
4 changes: 2 additions & 2 deletions spec/ssdp_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ describe("ssdp", function()
before_each(function()
require("spec/nodemcu_stubs")
nodemcu.wifi.sta.ip = '192.168.1.100'
upnp_response = dofile("src/ssdp.lua")
upnp_response = require("ssdp")()
end)

it("contains the IP address and port", function()
Expand All @@ -15,7 +15,7 @@ describe("ssdp", function()
it("contains the updated IP address after it changes", function()
assert.is.truthy(upnp_response:find("<URLBase>http://" .. nodemcu.wifi.sta.ip .. ":8000</URLBase>"))
nodemcu.wifi.sta.ip = '192.168.1.200'
upnp_response = dofile("src/ssdp.lua")
upnp_response = require("ssdp")()
assert.is.truthy(upnp_response:find("<URLBase>http://" .. nodemcu.wifi.sta.ip .. ":8000</URLBase>"))
end)
end)
Expand Down
29 changes: 22 additions & 7 deletions spec/variables_build_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,35 @@ describe("variables_build", function()
return s:gsub('%c','')
end

setup(function()
variables_build = require('variables_build')
it("returns a string that makes a lua list of lists", function()
local thing = {{pin=1},{pin=2}}
local str = require('variables_build')(thing)
assert.same(thing, load("return " .. str)())
end)

it("returns a string that makes a lua list", function()
local str = variables_build.build({{pin=1},{pin=2}})
assert.same("{ { pin = 1, },{ pin = 2, },}", trim(str) )
it("returns a sting that makes a lua list", function()
local thing = {foo="bar", baz=5}
local str = require('variables_build')(thing)
assert.same(thing, load("return " ..str)())
end)

it("allows for any values", function()
local expected = {{pin=1,trigger=1},{pin=2,trigger=0}}
local str = variables_build.build(expected)
local result = loadstring("return " .. str)()
local str = require('variables_build')(expected)
local result = load("return " .. str)()
assert.same(expected, result)
end)

it("allows for boolean and nil values", function()
local thing = {happy=true, tired=false, hungry=nil}
local str = require('variables_build')(thing)
assert.same(thing, load("return " ..str)())
end)

it("checks for nil", function()
local thing
local str = tostring(require('variables_build')(thing))
assert.same(thing, load("return " ..str)())
end)
end)

Loading

0 comments on commit 7e760c4

Please sign in to comment.