As the title says... Chat on...

User avatar
By ardhuru
#16369 Hello all,

I have a simple file saved on the ESP that has only six characters.

On boot up, this file is read, and fills up an arry a[1] to a[6].

Now, I recive a string of characters over wifi, and what I want is to suucessively compare each incoming character with its corresponding elemnt in the array.

That is, only if
1st character = a[1]
2nd character = a[2]
-
-
-
6th character = a[6]

Switch on gpio0 for 2 seconds.

I have been struggling with this and made absolutely no headway.

Any advice would be highly appreciated, folks!
User avatar
By ardhuru
#16667 Okay, I have now reached a stage where I can send characters from an Android app, and the can be seen received by the ESP8266.

What I'm trying to do is fill up an array with 5 elements, as and when the come in from the Android. As I said, the reception is happenning.

But, when I use the following code,

for i=1, 5 do
a[i] = x
print(i)
end
print(a[1],a[2],a[3],a[4],a[5])

I see the whole array filled up with the same character thats just been received!

For example, if I transmit "4" from the Android, the print line delivers 4 4 4 4 4,

And this happens for *every* character received; since the print statement is outside the loop, I'd have expected it to be executed after the for loop reaches 5?

Obviously, there's something drastically wrong with my understanding of how lua operates.

Can someone nudge me in the right direction, please?

Regards.
User avatar
By TerryE
#16688 I am not sure why you are storing a six character field as an array of 6 x 1-character variables, rather than simply one single six character variable, but just answering your direct Q: how do I test if a six char variable resp is the same as the six element array a, the simplest way is:
Code: Select allif resp == table.concat(a) then
  --whatever you want to do
end