A simple runtime setup for IoT and other RPi apps

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9801
Joined: Sat Apr 08, 2006 7:05 am
Location: Los Angeles
Contact:

A simple runtime setup for IoT and other RPi apps

Post by FourthWorld » Fri Jul 07, 2017 7:31 pm

At our SoCal LiveCode User Group meeting last night one of our attendees brought a really cool demo of an IoT system involving Arduino, Alexa, an Android phone, and a laptop, coordinating and sharing data.

One of the opportunities we discussed for enhancing the system was to consider replacing the Arduino board with a Raspberry Pi Zero W, so we get a full OS and one that can run LiveCode.

I told Daniel I'd put a note together on a simple setup to facilitate quick and easy development on the RPi by bypassing installation of the IDE on the device altogether, developing on his laptop and merely copying runtime files to the RPi.

This particular setup is even simpler by requiring that you build the standalone only one, with most of the app in a separate stack file that's easy to update:

I just opened LC v7.0,4, the most recent build for Raspberry Pi, and indeed it seems you can build standalones for RPi from any of the other platforms (if building for Windows you may need to set the executable bit on the standalone after copying to the RPi). So to make updates super-simple, you can have a simple stack as your standalone with this script:

Code: Select all

on startup
   put the filename of this stack into tPath
   set the itemdel to "/"
   put "MyLibrary.livecode" into last item of tPath -- your stack name goes here
   if there is a stack tPath then
       start using tPath
   else
       put "Can't find main library"
       quit
   end if
end startup
In your MyLibrary.livecode stack (or whatever you choose to call it):

Code: Select all

on libraryStack
   -- do whatever you want to do

end libraryStack
With that setup you can build a standalone once and copy it to the RPi, and place the MyLibrary stack file in the same folder. When the app is launched it'll look for that stack and if found bring it into use as a library, where the real meat of your application can be stored.

This way you can update your app by just replacing the MyLibrary.livecode stack file for small, quick simple updates.
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9801
Joined: Sat Apr 08, 2006 7:05 am
Location: Los Angeles
Contact:

Re: A simple runtime setup for IoT and other RPi apps

Post by FourthWorld » Fri Jul 07, 2017 8:49 pm

Tip: You can run any LiveCode standalone without a GUI by including a "-ui" flag in the command line, e.g.:

Code: Select all

MyStandalone -ui
For server apps this is essential, since most servers don't include GUI components so attempting to run a LiveCode app without that flag will generate an error about missing libs.

For IoT this is very useful because even if you use an OS that includes GUI support you'll find the standalone opens much more quickly and consumers far less RAM when unencumbered by GUI stuff. On my Linux box here a barebones faceless LC app launches in under a millisec and takes less than 3 MB RAM.

Just remember to add a "quit" command somewhere wherever you need it, since of course you'll have no File -> Quit menu item to click on. :)

Tip 2: If you want to measure run time and RAM usage, you can run a standalone with the Linux time program, with the -v flag for "verbose":

Code: Select all

/usr/bin/time -v MyStandalone -ui
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

Post Reply

Return to “Raspberry Pi”