aREST icon indicating copy to clipboard operation
aREST copied to clipboard

aREST returning arrays

Open thboomsma opened this issue 7 years ago • 3 comments

I have a sensed value that is an array of measured statuses

Looks like this int FLowOn[]={1,0,1,1,1,0,1,1}; Is it viable as an arest.variable(FLowOn, &FlowOn) ??

Thanks Theo

thboomsma avatar Jun 18 '18 16:06 thboomsma

Looking at the code, arrays are not supported. Only simple type are. But String are. So you can just declare a string and serialize the data in it. Based on your example, it would look like that: String FlowOn="0101111"; you'll then add the setup of the string into the setup function: rest.variable("FlowOn", &FlowOn); and when you'll call the arest function you'll get Something like: {"variables": {"temperature": 24, "humidity": 40, "FlowOn": "0101111"}, "id": "1", "name": "esp8266", "hardware": "esp8266", "connected": true} I just added the 2 lines of code in the basic ESP8266 example and run it. You'll then have to convert your serialized string into a table again

Ellerbach avatar Jun 21 '18 13:06 Ellerbach

Hello, indeed for now at least arrays are not supported, but the method given by @Ellerbach is great! :) I'll mark that as a feature request :)

marcoschwartz avatar Jun 26 '18 17:06 marcoschwartz

Hi @marcoschwartz I found a way to allow the functions to return String. I modified the arest.h and additionally I had to comment out one of the templates that are in the end of the file. How can I make sure if what I did is ok or if I need to rename the function in order not to comment out that template? Are those templates in the end of the file mandatory?

areyalp avatar Apr 12 '20 16:04 areyalp