Hello guys and many thanks for the replies.
@JackZ Hi Jacques, yes, that does indeed offer a workaround. Nice one. A very useful function. I had tried a simple string.sub but the problem was that the length of the string is not constant. Your solution is perfect. Very much appreciated. Thank you.
I am now using the following as a basis for extracting the information and it certainly seems to work.
Code: Select all
-- This function will be called when a message is received from the Arduino.
function new_message(id, payload,len) -- NOTE ! (Joe) 'len' as I have called it - is undocumented and I see no other way of getting the data ??
print("received new message with id " .. id)
print("len ".. len)
local x,y -- temp storage for test
--x = tonumber(string.sub(len,5,5)) -- wont work due to variable length of string - do not use.
x = tonumber((string.match(len, '%d+'))) -- ref: Jacques %d is digit, %d+ is digit(S)
y = string.sub(len,1,1) -- Get first character of 'len' to determine type
print("Type = (B = BYTE, I = INT, F = FLOAT ) "..y) -- test of intended type extraction from HWMP
print("Number of elements (len) = "..x) -- test of 'len' or number/quantity of the 'type' intended to be sent from HWMP
I must confess I am still totally baffled as to what
@Corjan intended / is intending for this. As said, at no place can I find ANY reference to anything that AM does in response to a new message from a HWMP device apart from function new_message(id, payload)
I added the third argument and called it 'len' just for the sake of it and was surprised to find the string returned in such a format.
There is plenty of documentation for sending multiple values from the HWMP device so there HAS to be appropriate data for the multiple values and intended types from the AM new_message function - but absolutely nothing about the reception is documented (that I can find). In the past I have just used single values or just an ID but wanted to use multiple values as the decoding of the data in code is far faster than sending the data over a slooooooooooooooow serial link.
Very interesting. I am sure I am missing something but I simply cannot find any reference at all in this area. At least with your help I can actually get the data. I need to think of another name instead of 'len' as it is not just 'len'
@Ralph Understood and no problem. He deserves the break
. I am very much looking forward to hearing his thoughts on this when he returns to work.
Thanks again guys.
Oh, and have you guys seen the new ESP32-S3 ! ?
a little stunner. FAR more I/O than the ESP32 and on chip flash. Very very nice.
Joe