0

Programming for similar feeds
Moderators: adafruit_support_bill, adafruit

Forum rules
If you're posting code, please make sure your code does not include your Adafruit IO Active Key or WiFi network credentials.
Please be positive and constructive with your questions and comments.

Programming for similar feeds

by john87 on Sun Jan 05, 2020 3:16 pm

I think my app may be similar to XovorIoT's; I have a few devices, e.g. Huzzah Feathers reporting temperature and humidity. I'd like to call them "Indoor", "Outdoor", and "Greenhouse".

Now, I'm keeping separate ino files for each, with lines like:

AdafruitIO_Feed *t_out = io.feed("t_out");
t_out->save(Temps[1]);

I'd like to make one change in the file, for example to change all of the instances of t_out to t_tgreenhouse. I suppose I can use a variable for the io.feed(location) but is there a way to handle the code at the other positions.

Thanks,

John

john87
 
Posts: 4
Joined: Sun Jul 21, 2019 11:20 pm

Re: Programming for similar feeds

by brubell on Mon Jan 06, 2020 11:34 am

I suppose I can use a variable for the io.feed(location) but is there a way to handle the code at the other positions.


Totally valid way of doing it, it'll work.


I thought about an alternative for you, too. I'd go about it by making a "template" .ino file which contains t_greenhouse, t_out, etc. This would reduce the amount of changes you'd need to make as you'll only be modifying/compiling/uploading one .ino file.

At the top of the file, I'd create #define's for your nodes like:

Code: Select all | TOGGLE FULL SIZE

//types of sensor nodes, uncomment if used:
#define GREENHOUSE
// #define OUTDOORS
// #define INDOORS


In the code, I'd add a pre-processor conditional like:

Code: Select all | TOGGLE FULL SIZE
#ifdef GREENHOUSE:
 AdafruitIO_Feed *t_out = io.feed("t_greenhouse");
#elif OUTDOORS:
 AdafruitIO_Feed *t_out = io.feed("t_out");



The idea is - your code would only reference t_out, but the value of t_out would changed based on how you set your definition (#DEFINE)

- brent r.

brubell
 
Posts: 696
Joined: Fri Jul 17, 2015 10:33 pm

Please be positive and constructive with your questions and comments.