Hello Guest, Welcome to Apnea Board !
As a guest, you are limited to certain areas of the board and there are some features you can't use.
To post a message, you must create a free account using a valid email address.

or Create an Account


New Posts   Today's Posts

LUA Scripting on FlashAir 3
#1
Brick 
LUA Scripting on FlashAir 3
LUA scripting
---
Scraped from http://www.lua.org/about.html
What is Lua?

Lua is a powerful, efficient, lightweight, embeddable scripting language. It supports procedural programming, object-oriented programming, functional programming, data-driven programming, and data description.
---

FlashAir 3.0 supports some of LUA but it does have limitations due to the size of its memory.
Flashair 3.0 doesn't support coroutine, OS library, math or the debug.
This is flashair developers text on LUA: https://flashair-developers.com/en/documents/api/lua/
Functions that Flashair supports: https://flashair-developers.com/en/docum...reference/


After another user here had issues locating the IP address of their DHCP enabled card, I whipped up a small script, albeit a little late, to write the IP information to a text file.

Feel free to steal it if you are having issues trying to locate the card's IP. Script grabs a list of SSIDs of the wifi routers it discovered, useful to tell if your card even sees your wifi router, and the IP info of the card then writes it to a text file on the FlashAir.

Copy the script below to the root of the FlashAir card (I named it wifistatus.lua) and add this line to your CONFIG:
LUA_RUN_SCRIPT=/wifistatus.lua

This script will run at boot up.

If you put the card into your SD card reader and wait about 15 to 30 seconds, you can open the ssid.txt file that this script creates and find what IP the card was given. The chances of your card getting a different IP after that are slim and the card should have the same IP after you return it to your CPAP. If you can connect to your card through webdav you can open the file from there and find the IP as well.

Here is the script:

Code:
--[[
This script will scan for wifi networks and lists all SSID it finds
Will also attempt to log the IP, subnetmask and gateway of the card
]]--

ssidfile  = "ssid.txt"

local function waitWlanConnect()
   while 1 do
       local res = fa.ReadStatusReg()
       local a = string.sub(res, 13, 16)
       a = tonumber(a, 16)
       if (bit32.extract(a, 15) == 1) then
           print("connect")
           break
       end
       if (bit32.extract(a, 0) == 1) then
           print("mode Bridge")
           break
       end
       if (bit32.extract(a, 12) == 1) then
           print("mode AP")
           break
       end
       sleep(2000)
   end
end

local function writeInfo(_oFile)
local sfile = io.open(_oFile, "w")
count = fa.Scan()

ip, mask, gw = fa.ip()
sfile:write("IP: "..ip.."\r\n")
sfile:write("mask: "..mask.."\r\n")
sfile:write("gw: "..gw.."\r\n")
sfile:write("SSID list:".."\r\n")
for i=0, (count-1), 1 do
ssid, other = fa.GetScanInfo(i)
sfile:write(i..": "..ssid.."\r\n")
end
sfile:close()
end

-- Main script
waitWlanConnect()
writeInfo(ssidfile)
collectgarbage()


This is what the script writes to the ssid.txt file:
IP: 192.168.0.40
mask: 255.255.255.0
gw: 192.168.0.1
SSID list:
0: xxxxxx
1: xfinitywifi
2: X
Using FlashAir W-03 SD card in machine. You can download your data through wifi with FlashPAP or Sleep Master utilities.

I wanted to learn Binary so I enrolled in Binary 101. I seemed to have missed the first four courses. Big Grinnie

Stick it to the man, Download OSCAR and take back control of your data!

Thanks Ian. Like I didn't have enough Honey-Do projects to tackle. Mornincoffee
Post Reply Post Reply
#2
RE: LUA Scripting on FlashAir 3
like that's actually awesome - thanks very much for sharing this.

as you obviously have 'some' experience with the flash-card:
how much useable RAM is there (in terms of useable from "inside" lua / cgi - not before)? and how much does it affect heat? (I'm more talking about some excessive scripts)
Post Reply Post Reply
#3
RE: LUA Scripting on FlashAir 3
Not sure on the memory. I read somewhere someone did a mem dump of about 2mb. The script above runs at boot and never again until next card cycle. Never tried a script that would run continuously such as one that fires on an "event". Should try it and see how hot it gets.
Using FlashAir W-03 SD card in machine. You can download your data through wifi with FlashPAP or Sleep Master utilities.

I wanted to learn Binary so I enrolled in Binary 101. I seemed to have missed the first four courses. Big Grinnie

Stick it to the man, Download OSCAR and take back control of your data!

Thanks Ian. Like I didn't have enough Honey-Do projects to tackle. Mornincoffee
Post Reply Post Reply
#4
RE: LUA Scripting on FlashAir 3
Copied from the Flashair developer page:

Memory size (HTTPDBUFF)
"By reducing the amount of memory used in the HTTP server, you can increase the amount of memory used in Lua script execution. Note that in the case of reducing the memory of the HTTP server, the download throughput will decrease. The range of value is from 2920 to 23360. Default value is 23360."

Example:
Code:
HTTPDBUFF=2920
Post Reply Post Reply
#5
RE: LUA Scripting on FlashAir 3
if this numbers would be KB and not Bytes that would really be promising. ... but in the end it depends a bit on the heat the scripts (can) produce.
Post Reply Post Reply


Possibly Related Threads...
Thread Author Replies Views Last Post
  Flashair - Dreamstation -> Airsense 11 Autoset todivefor 14 664 02-28-2024, 07:22 PM
Last Post: Crimson Nape
  [split] FYSETC SD Wifi - Possible FlashAir Replacement Psikic 131 21,238 01-12-2024, 11:59 AM
Last Post: scowell
  FlashPAP - FlashAir WiFi SD card utility TiredToo 296 94,924 10-05-2023, 06:54 AM
Last Post: olddog27
  looking for FlashAir W-04 16GB SD_card image Dog Slobber 3 795 06-03-2023, 08:21 AM
Last Post: Dog Slobber
  Transfering FlashAir card to new machine. foxfire 1 494 04-30-2023, 10:21 AM
Last Post: Crimson Nape
  FlashAir card and changing SSID todivefor 12 1,096 03-28-2023, 07:12 PM
Last Post: todivefor
  Flashair W-04 32GB doesn't works anymore Filippods 12 1,342 10-18-2022, 03:15 PM
Last Post: NesporBellisRM


New Posts   Today's Posts


About Apnea Board

Apnea Board is an educational web site designed to empower Sleep Apnea patients.