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
Member for
16 years 5 monthsThanks
Excited :)
Now your house will go haywire ;)
Member for
16 years 10 monthsI knew somebody had
I knew somebody had downloaded and played with it almost immediately. All I could hear in the background was the gentle clicking of relays. Luckily they are not connected to anything so click away.
This demo should be enough to get you moving with creating mutiple pages. I wanted to get something out by the end of this weekend to keep you guys keen.
Brett
Member for
13 years 11 monthsHi Brett,Thanks for the new
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 - /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
Member for
16 years 10 monthsAndrew,I've only tested this
Andrew,
I've only tested this demo on my HP Touchpad (ex WebOS - now hacked to run Android 4.0 ICS) and it works fine for me. Install from the "play shop" aLogCat and see what you can find from the logs about why it shutdown.
I'm using simulator 2013.1202 (the latest) when I build my .apk package for transfer.
As it works for you in the simulator we'll need some logs.
Brett
Member for
13 years 11 monthsBrett,Is there a way to
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)
Member for
13 years 11 monthsHi Brett,is this issue
Hi Brett,
is this issue /content/building-android-interfaces-us…
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
Member for
13 years 11 monthsHi Brett,Logs taken from my
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
Member for
16 years 10 monthsThis is a permissions issue
This is a permissions issue compounded by bad error handling in xap.lua - I've fixed both grab the demo from the 1st posting on this thread.
Thanks for the detailed stack trace that helped me nail the problem.
Brett
Member for
13 years 11 monthsBrett, Thank you, both demos
Brett,
Thank you, both demos run up fine for me now :)
Andrew
Member for
14 years 5 monthsreconnection after sleep
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 :)
Member for
16 years 10 monthsMark I've never left the demo
Mark I've never left the demo running long enough to notice this - thanks for the heads up I'll take a peek into why this happens.
Brett
Member for
13 years 11 monthsHi Brett,I have a similar
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
Member for
16 years 10 monthsOnce again my Tablet is
Once again my Tablet is foiling my attempts to reproduce this. Can you send me some logs if there are some to be had like we did last time? It would seem my tablet is more forgiving that those that you are using, it didn't need permission before opening a socket and it seems to recover without doing any additional tricks.
Brett
Member for
15 years 7 monthsMe too
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.
Member for
16 years 10 monthsThis feels about right I
This feels about right I should have an xap_server:suspend() and xap_server:resume() function that handle whatever needs to happen automatically. I'll have a play too.
http://forums.coronalabs.com/topic/19021-socket-connection-lost-after-s…
Brett
Member for
15 years 7 monthsafter alot of pissing about
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.
Member for
16 years 10 monthsGary I amended the demo
Gary I amended the demo pasted on the first link to restructure this a little more.
The entire application is now only started when the ApplicationStart Event is seen too, this makes the design a little cleaner, have a look. From what you are saying thou there still might be a delay issue. The blocking on connect is in the xap.lua code and by default this is 3 seconds. If longer is required for WIFI to settle then this should be made into a parameter that can be passed in.
Brett
Member for
14 years 5 monthsStatus text
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 :)
Member for
16 years 10 monthsMark I increased allowable filesize for an upload so post away.
Mark I increased allowable filesize for an upload so post away.
I ran some tests and the bug is actually deeper and more severe. When the unit goes to sleep the xap_server object to which all the buttons was connect drop outs from underneath them, the xap-objects now can only send events they no longer repond to changes that happen to their bound endpoint.
Saying that again another way.
You press the button and it toggles the local state is updated and a xAPBSC.cmd (toggle) is sent to the endpoint.
If I use my joggler to toggle that same endpoint the phone gui will not get the xAPBSC.event and update its state !
I have to solve this, as it breaks the entire framework. Its why when you press your phone the endpoint and its state can be out of sync.
Using your own images should just be a matter of following the example you see scene1.lua.
For now that a minor issue compared to what has just been brought to my attention.
Brett
Member for
14 years 5 monthsThanks Brett
I'll get on with the minor issue then, while you dig :)
Member for
15 years 7 monthsOuch
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.
Member for
16 years 10 monthsSee 1st post for new code to
See 1st post for new code to correct these issues:
I would advise you take this framework in total and drop in your scenes LUA files and just tweak where this connects. There are a number of xap.lua changes and main.lua changes in here.
Brett
Member for
16 years 10 monthsRead only toggle object.
If you want to only show the state of an "output" endpoint like a relay and not allow control you can do something like this.
-- Its an output.state endpoint but we don't to allow user control of it.
-- so we WIPE off the touch handler after its created.
function readonlyToggle(v, xpos, ypos)
local btn = toggle(v, xpos, ypos)
btn.touch = nil
return btn
end
Now we can define out grid like this:
local grid = {
{ -- ROW 1
{c=readonlyToggle, text="Relay 1", xapSource="dbzoo.livebox.Controller:relay.1", size=18},
{c=toggle, text="Relay 2", xapSource="dbzoo.livebox.Controller:relay.2", size=18},
{c=toggle, text="Relay 3", xapSource="dbzoo.livebox.Controller:relay.3", size=18},
{c=toggle, text="Relay 4", xapSource="dbzoo.livebox.Controller:relay.4", size=18},
},
The toggle object allows you to define an on/off image, how do you hover (aka over) with your finger?
Brett
Member for
14 years 5 monthsThese daily updates are definitely helping me with LUA :)
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....
Member for
14 years 5 monthsActive images
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)
Member for
16 years 10 monthsThat function is just
That function is just this:
function activeImage(v)
v.size = v.size or 20
return bsc.newToggle(v)
end
You don't need to copy the same thing back to itself if there is no default being supplied.
Given that is so tiny you might as well just remove it and include size with your definition and use bsc.newtoggle direct.
{c=bsc.newToggle, size=20, xapSource="dbzoo.livebox.Controller:rf.5", default = "images/Lounge_03_off.png", on = "images/Lounge_03_on.png", x = 750, y = 280},
UPDATE:
If you look in toggle.lua you'll see that 20 is the default if you don't supply anything.
if ( params.size and type(params.size) == "number" ) then size=params.size else size=20 end
So you can just write this:
{c=bsc.newToggle, xapSource="dbzoo.livebox.Controller:rf.5", default = "images/Lounge_03_off.png", on = "images/Lounge_03_on.png", x = 750, y = 280},
Brett