MP70 - string.unpack() problem

Hello All,

I am using MP70 gateway in my project. Applications are built using Lua scripting.
There is some problem with the “string.unpack()” function.

I have a sample program,


local myStr = string.char(0x31)
myStr = myStr … string.char(0x32)
myStr = myStr … string.char(0x33)
myStr = myStr … string.char(0x34)
print(string.unpack(“I4”,myStr))

I expect the following output,
875770417 5
(The above output is seen in the online lua interpreter)

But the MP70 throws an error as follows,
/bin/lua: main.lua:29: bad argument #1 to ‘unpack’ (bad code `1’)
stack traceback:
[C]: in function ‘unpack’
main.lua:29: in function ‘main’
main.lua:48: in main chunk
[C]: ?

Could anyone please help me out to resolve this issue?

Hi @c-nv

You need to require “pack” library for for packing and unpacking binary data.
Usage:
require “pack”
local _,mystring,myfloat = string.unpack(bindata, “zf”)

Please refer to this link for more details https://source.sierrawireless.com/resources/airlink/aleos_af/refdoc_aleos_af_api/#sthash.ii8H7eWB.4jUOmSSD.dpbs=&url=~/media/Support_Downloads/AirLink/AAF/aleos_af-1_0_0-api/API_Utilities_pack.html&id=iframe0

Can you share your AAF application (main.lua file) and Firmware version MP70 so I can give it a try?

Hi Donald,

Thanks a lot.
Its working after adding “pack” library.
:+1: