MultiScene Demo
I've put together a little multi-scene demo and included a few other trinkets to get your excited about you can do. This demo connects to my house which is exposed on the internet so it should work for you guys too.
Enjoy,
Update: I installed this on my android and noticed 1 bug, the bar at the bottom of the screen is OFF the screen. (you see it in the emulator but not on a real device).
I've uploaded new source - or you can manually amend the offending code in main.lua
local segmentedControl = widget.newSegmentedControl
{
left = 0,
top = _H-30, -- bottom of screen minus the size of the default height for the segment.
segments = labels,
segmentWidth = _W/#labels, -- Size the number of labels to fill the screen width.
defaultSegment = 1,
onPress = onControlPress
}
Update: 13-Sep
In order for socket.tcp() to work correctly the APP is required to be granted internet access permission. Included an additional file build.settings to sort this out, I also fix a few other bugs whilst I was at it.
Replaced demo attachment
Update: 24-Sep
Added handling for ApplicationResume/Suspend restructure main.lua, made changes to xap.lua to prevent xap events from being sent when suspended.
Update 26-Sep
Handle Sleep/Resume events - required a bit of a rework.
Put in error handler scene to display stack traces on the screen.
Attachment | Size |
---|---|
xapMultiScene.zip | 65.63 KB |
xapMultiScene.zip | 65.8 KB |
Hi Brett,
Thanks for the new demo however i am having some issues getting it running on my handset
The behaviour is just a black screen when run on any of my Android devices (samsung galaxy S4 / Scroll pocket 4.3 / Archos Cobalt 80)
In the Simulator it works fine, i also see the same issue with the multiscreen update you provided for Mark in the Removing screen items thread - http://www.homeautomationhub.com/content/remove-screen-items
Up until yesterday the error was "This application encountered a Lua error (see logs) or has been corrupted"
I then updated Corona to the latest version as i suspected this could possibly be a widget task bar issue
now i just see the black screen as mentioned above...
I dont have any ADB Logcat dumps as i wasnt able to filter out the logs for just the multiscreen errors (do you have any tips?)
thanks as always
Andrew
Brett,
Is there a way to filter aLogcat to show just your demo logs?
thanks
Edit - adb logcat Corona:v *:s
(Corona is case sensitive)
Hi Brett,
is this issue http://www.homeautomationhub.com/content/building-android-interfaces-usi...
reflected in your multiscene demo?
i can see references to "attempt to index field 'txSocket' (a nil value)" in my logcat logs, i will try to upload some log later this evening (UK time)
thanks
Andrew
Hi Brett,
Logs taken from my Samsung whilst running your multiscene demo
a possible txSocket (nil value) as i mentioned above
--------- beginning of /dev/log/system
--------- beginning of /dev/log/main
V/Corona ( 8973): > Class.forName: network.LuaLoader
V/Corona ( 8973): < Class.forName: network.LuaLoader
V/Corona ( 8973): Loading via reflection: network.LuaLoader
I/Corona ( 8973): Runtime error
I/Corona ( 8973): ...kers\Downloads\xapMultiScene_0\xapMultiScene\xap.lua:179:
attempt to index field 'txSocket' (a nil value)
I/Corona ( 8973): stack traceback:
I/Corona ( 8973): [C]: ?
I/Corona ( 8973): ...kers\Downloads\xapMultiScene_0\xapMultiScene\xap.lua:
179: in function '_init'
I/Corona ( 8973): ...rs\Downloads\xapMultiScene_0\xapMultiScene\class.lua:
27: in function 'call_ctor'
I/Corona ( 8973): ...rs\Downloads\xapMultiScene_0\xapMultiScene\class.lua:
93: in function 'TCPServer'
I/Corona ( 8973): ...ers\Downloads\xapMultiScene_0\xapMultiScene\main.lua:
18: in main chunk
V/Corona ( 9028): > Class.forName: network.LuaLoader
V/Corona ( 9028): < Class.forName: network.LuaLoader
V/Corona ( 9028): Loading via reflection: network.LuaLoader
and the logcat output for your mods to Marks multiscene
--------- beginning of /dev/log/main
--------- beginning of /dev/log/system
V/Corona ( 9704): > Class.forName: network.LuaLoader
V/Corona ( 9704): < Class.forName: network.LuaLoader
V/Corona ( 9704): Loading via reflection: network.LuaLoader
V/Corona ( 9704): > Class.forName: CoronaProvider.licensing.google.LuaLoader
V/Corona ( 9704): < Class.forName: CoronaProvider.licensing.google.LuaLoader
V/Corona ( 9704): Loading via reflection: CoronaProvider.licensing.google.Lua
ader
I/Corona ( 9704): Runtime error
I/Corona ( 9704): ...abickers\Downloads\MultiScene_2\MultiScene_2\xap.lua:171
attempt to index field 'txSocket' (a nil value)
I/Corona ( 9704): stack traceback:
I/Corona ( 9704): [C]: ?
I/Corona ( 9704): ...abickers\Downloads\MultiScene_2\MultiScene_2\xap.lu
171: in function '_init'
I/Corona ( 9704): ...ickers\Downloads\MultiScene_2\MultiScene_2\class.lu
27: in function 'call_ctor'
I/Corona ( 9704): ...ickers\Downloads\MultiScene_2\MultiScene_2\class.lu
93: in function 'TCPServer'
I/Corona ( 9704): ...bickers\Downloads\MultiScene_2\MultiScene_2\main.lu
26: in main chunk
I/Corona ( 9704): Runtime error
I/Corona ( 9704):
I/Corona ( 9704): stack traceback:
I/Corona ( 9704): [C]: ?
I/Corona ( 9704): ...abickers\Downloads\MultiScene_2\MultiScene_2\xap.lu
171: in function '_init'
I/Corona ( 9704): ...ickers\Downloads\MultiScene_2\MultiScene_2\class.lu
27: in function 'call_ctor'
I/Corona ( 9704): ...ickers\Downloads\MultiScene_2\MultiScene_2\class.lu
93: in function 'TCPServer'
I/Corona ( 9704): ...bickers\Downloads\MultiScene_2\MultiScene_2\main.lu
26: in main chunk
thanks
Andrew
Brett,
Thank you, both demos run up fine for me now :)
Andrew
I don't know if anyone else has noticed this but if my tablet goes to sleep with the app running, it seems to loose connection to the HAH. No errors but all fields are empty and RF commands not sent.
It's not a problem, I'm quite happy to quit and restart but can see SWMBO getting miffed when she is in darkness :)
Hi Brett,
I have a similar issue when i leave the app running by going back to my home screen or into another app without quitting
on returning to the app i will have no connection - maybe it needs to reconnect when in focus?
Andrew
Need a corona app restart after standby for a while.
logcat logs don't show anything for coming out of standby. Iserver shows no clients connected until app closed and restarted
Not much help, I know!
Garry
what about modding the main.lua to include the following?? or am I on the wrong track. (ill give it a go anyhow)
-- Capture application events
local onSystem = function( event )
if event.type == "applicationExit" then
xap_server:stop()
elseif event.type == "applicationSuspend" then
xap_server:stop()
elseif event.type == "applicationResume" then
xap_server = xap.TCPServer("192.168.0.8")
xap_server:setSource("dbzoo.corona.applet")
xap_server:start()
end
end
Runtime:addEventListener( "system", onSystem )
This seems to work on the simulator, will test for real later.
seems that the following code now finally works for me. The issue I think is that the Wifi takes a while to reconnect, therefore have added a delay to stop reconnection attempts for 10secs. This may be overkill but its working on my system.
Brett, like you say, may be better to add these to xap.lua as functions.
Garry
Code I modded into main.lua:
-- Capture application events
local onSystem = function( event )
if event.type == "applicationExit" then
xap_server:stop()
elseif event.type == "applicationSuspend" then
xap_server:stop()
elseif event.type == "applicationResume" then
timer.performWithDelay(10000, restart, 1)
end
end
Runtime:addEventListener( "system", onSystem )
function restart()
xap_server = xap.TCPServer("192.168.0.8")
xap_server:start()
end
EDIT: 5 secs seems to work. Think I will add a reconnecting screen while the timer is active.
will post code once I've tested it!
G.
Brett, thanks for the updates, reconnection on wake is now working ok excpet the toggles sometimes take the inverse state.
Can you tell me what is the best way to display the status of a xap endpoint using this framework?
I just want to be able to display, say the total power value for the house at a certain position on one of the scenes. I know the toggles and buttons display the state but I would just like to display data in a list on one of my scenes. I have tried to upload my WIP version of app but the 1M upload limit is stopping me :)
I also have a scene that has an image of an area of a room i.e. the TV stand. On that image I have overlay images for 'over' 'on' and 'off' and would like to use the state of an endpoint to display either the on or off image. I know this moves towards a more bespoke app but it is more appealing to SWMBO :)
I'll get on with the minor issue then, while you dig :)
Hadn't noticed the lack of endpoint updating post suspend, hope its not as massive an issue as it sounds.
Mark, while Brett is obviously otherwise engaged with bigger issues, try this for adding endpoint text.
using the scene1 example, add the following into the helper functions section:
function textview(v)
local activetext = display.newText("", 0, 0, native.systemFont, v.size)
activetext:setTextColor(255,255,255)
local f = xap.Filter()
f:add("xap-header","source", v.xapSource)
f:callback(function(frame)
local texttoview = frame:getValue(v.xapType..".state","text") or 0
activetext.text = v.prefixtext..texttoview
end
)
xap_server:addFilter(f)
local grp = display.newGroup()
grp:insert(activetext)
grp.x = v.x
grp.y = v.y
return grp
end
then in the grid section add an entry like:
{c=textview, xapSource="dbzoo.livebox.williams:Heating.Watertemptop", prefixtext="Water Temperature ", xapType="input", x=172, y=190, size=22},
this has x and y co-ordinates that break out of the grid format, not sure this is too elegent but does get text to display. Also the xapType variable needs to match the xap massage, ie input.state or output.state
thanks
Garry
PS managed to get a xively chart displayed yesterday, just working on a picker wheel to select the required datastream and i'll publish. all exiting stuff.
There has been a change to the way that the ui.newLabel bounds are taken. The width and height bounds are handled differently now but no biggie, soon got around that one
As for the over, hover or over was not what I meant to say. It is more of a 'touched' option as a confirmation that command made before endpoint updates. It's purely an aesthetic thing.
See the lounge.lua scene (accessed by pressing the Living Room button on the floorplan) and click the TV or lamp. They change to confirm the click (not active yet)
Here is my WIP....
Attachment | Size |
---|---|
Home Automation 3.zip | 1.43 MB |
I've added an active image function
function activeImage(v)
v.x = v.x
v.y = v.y
v.size = v.size or 20
v.default = v.default
v.on = v.on
return bsc.newToggle(v)
end
I then call the image in the grid but break out of the grid positioning like this
{c=activeImage, xapSource="dbzoo.livebox.Controller:rf.5", default = "images/Lounge_03_off.png", on = "images/Lounge_03_on.png", x = 750, y = 280},
See files in post above for this in action.
Select 'Living room' from the floorplan..
Click on the TV or Lamp to toggle their state (attached to Brett's relay 1 to 4)
Excited :)
Now your house will go haywire ;)