Is it correct to assume the NV table can’t hold an array because it’s table?
What I’m looking to do is have an array survive a deepsleep. Suggestions appreciated.
Thanks.
Is it correct to assume the NV table can’t hold an array because it’s table?
What I’m looking to do is have an array survive a deepsleep. Suggestions appreciated.
Thanks.
I am successfully saving arrays in the NV table.
You can put the array into a table. a table can hold other tables as well.
This code is in the agent but the tables and arrays will work in the Device as well - just not the jsonencode function
`Anewtable <- {}
newarray <- [5, 6, 7];
Anewtable[“myarray”] <- newarray;
server.log(http.jsonencode(Anewtable));
server.log(http.jsonencode(Anewtable.myarray));
Anewtable.myarray.push(5);
server.log(http.jsonencode(Anewtable));`
returns
{ “myarray”: [ 5, 6, 7 ] }
[ 5, 6, 7 ]
{ “myarray”: [ 5, 6, 7, 5 ] }
Thanks for your help, I’m making headway now.
For better of worse here’s my working test code if it helps anyone in the future.
PS: I feel a bit embarrassed asking newbie questions, perhaps the forum needs a “beginners” category.
`
function startup()
{
if (!(“nv” in getroottable() && “count” in nv))
{
nv <- { count = 0 }
newarray <- [0, 5, 10, 15, 20]
nv[“myarray”] <- newarray
}
server.log ("count: " + nv.count)
if (nv.count < nv.myarray.len() )
{
server.log (“array test [” + nv.count + "]: " + nv.myarray[nv.count])
}
nv.count++
imp.onidle(function(){imp.deepsleepfor(5.0)})
}
startup()
`
Don’t feel bad asking beginner questions. I have been programming as a hobby for quite some time with many languages and still run into areas of programming I haven’t ventured before. Sometimes these questions help.
Thanks.