Help needed for a lua script.

openTx has introduced a range of new features, ideas and bling. It is fast becoming the firmware of choice for many users. openTx will run on ALL current hardware platforms, including the gruvin9x and sky9x boards. Work has already started to support the new FrSky X9D radio!
Post Reply
mstrens
Posts: 1435
Joined: Fri Dec 27, 2013 7:49 pm
Country: -

Help needed for a lua script.

Post by mstrens »

I would like to let my taranis send some commands to a sensor (openXsensor) connected to the Rx on the SPORT bus.

I installed the latest version of openTx 2.2 on the taranis and I activated the options lua and luac in companion.

I wrote a short lua script (here below).

Code: Select all

local timeprev 
local running = false

local function init()
	
end

local function run()
  if not running then
      running = true
	  timeprev = getTime()
  end
  local timenow = getTime() -- 10ms tick count
  if timenow - timeprev > 50 then -- more than 500 msec since previous run 
	timeprev = timenow
	sportTelemetryPush( 0x48 , 0x32 , 0x52FF , 0) 
  end
end

return { init=init, run=run }
This script is supposed to push some bytes on the SPORT bus.
The name of the script is short rstful.lua
The script is installed on the SD card in the folder SCRIPTS/FUNCTIONS.
In the special function screen, I added en entry saying that when SA is up, the script must run.

This script seems to run in simulator in companion (e.g. if I add a line of code with print("test") just before the line sportTelemetryPush(), the debugger windows from companion shows the text "test" when the switch is activated).

Still, when I try the script on the Tx and if I connect a digital analyser on the SPORT bus from the Rx, I only see the normal polling code (0X7E + the device ID) and I never see the bytes that the Tx is supposed to send.

I do not know where I make a mistake.
Perhaps there are some special codes to use in the sportTelemetryPush() in order to let the RX output them on the SPORT?
Has someone already thy some similar functionality?

User avatar
rcdiy
Posts: 190
Joined: Fri Jul 01, 2016 6:13 am
Country: Canada
Contact:

Re: Help needed for a lua script.

Post by rcdiy »

Would the S6R lua scripts be of any help?
http://downloads.open-tx.org/2.2/nightly/sdcard/
Unzip and look for S6R folder. Two scripts, both use s.port to configure and calibrate the S6R

May be even the betaflight/clean flight scripts.. I forget which one because I don't use them but have seen discussions...
http://www.nitbeatfpv.com/frsky-taranis-pid-settings
RCdiy.ca
Stay Safe & Have Fun
OpenTX Manual http://rcdiy.ca
Paying it forward by sharing my Lua scripts, documentation and videos.
User avatar
rcdiy
Posts: 190
Joined: Fri Jul 01, 2016 6:13 am
Country: Canada
Contact:

Re: Help needed for a lua script.

Post by rcdiy »

Also forgot, the developers on Rocket Chat and openRCgroups are helpful...
https://www.rcgroups.com/forums/showthr ... discussion

https://opentx.rocket.chat/home
Group OpenTX_General
RCdiy.ca
Stay Safe & Have Fun
OpenTX Manual http://rcdiy.ca
Paying it forward by sharing my Lua scripts, documentation and videos.
mstrens
Posts: 1435
Joined: Fri Dec 27, 2013 7:49 pm
Country: -

Re: Help needed for a lua script.

Post by mstrens »

Thanks for your info.
I just modified my script in order to use 0x0D as sensor ID in the sportTelemetryPush() and it works.

If it is required to use this value, it should be useful to add it in the openTX documentation for this function.
User avatar
Kilrah
Posts: 11109
Joined: Sat Feb 18, 2012 6:56 pm
Country: Switzerland

Re: Help needed for a lua script.

Post by Kilrah »

It does not need to be 0x0D but has to be one of the 28 valid smart port physical IDs and not conflict with something else.

mstrens
Posts: 1435
Joined: Fri Dec 27, 2013 7:49 pm
Country: -

Re: Help needed for a lua script.

Post by mstrens »

OK, thanks, it works with other ID's (from the 28 valid).

Perhaps that I had to replace
sportTelemetryPush( 0x48 , 0x32 , 0x52FF , 0)
by
ret = sportTelemetryPush( 0x48 , 0x32 , 0x52FF , 0)

Post Reply

Return to “openTx”