Hi guys first post here so forgive me if a lot of this is simple. Essentially, I am trying to find a elegant way for me to wirelessly set variables in the beginning of my sketch.
I have seen in blynk you can control pins, and read in data from pins. Is there a way to store a value and set it to a variable, not directly push that value to a pin.
Instead of having to update my code and recompile every time I change a parameter, I want to write into the code to “go to blynk and check the value of this variable.” That way I can just set the parameters with Blynk and hit go on the WeMos D1 board I am using.
Example:
Currently I have varaible:
Hopadd = [0, 10, 20];
Hopinfo = [“2oz Saaz”. “1oz coloumbus”, “1oz cascade”];
I would like to set Hopadd and Hopinfo in the blynk app and then
Some sort of code that says:
read: Hopadd
read Hopinfo
…then my sketch
Using WiFimanager library to connect to WiFi as well.
Looks like Terminal Widget could work.
I have a question: What would the code below look like since I am asking for more than one variable? Should I input multiple terminal widgets to multiple virtual pins, or can I put it into a loop of some sort?
I saw the code I believe you suggested to someone else:
BLYNK_WRITE(V1) // Terminal Widget
{
String stringTerminal = param.asStr(); // get data entry from Terminal
float floatTerminal = stringTerminal.toFloat();
floatTerminal = floatTerminal + 12.3; // add a float to the ‘number’ entered into Terminal
char buffer[10];
stringTerminal = dtostrf(floatTerminal,5, 2, buffer); // width and precision
if(floatTerminal > 20)
{
terminal.println(“Sum is over 20”); // some random text
terminal.flush();
}
else
{
terminal.println(stringTerminal); // show in Terminal the result of the float entered into Terminal plus 12.3
terminal.flush();
}
}
Its for a brewing system, and yes every variable can be anything:
MASHTEMP: one number
MASHTIME: one number
BOILTIME: one number
HOPADD: [Array with the timing of several different hop adds, this array size can change]
HOPINFO: (Array of STRINGs corresponding to the timing of the hop adds above)
I was thinking i could just repeat the request for more information and set each one at a time, but I wonder if there is a more elegant solution such as an if statement etc
I guess you might be able to get away with just one Terminal.
You could prefix the string you post to Terminal A = MASHTEMP, B = MASHTIME etc and then if, if else, else statements will use Arduino “startsWith” function.
Are you manually feeding the data into Terminal and if so can’t this be automated somewhere in the brewing system?
So these are the so called “Brewing Parameters” that change for everytime I brew. So I would like to input these variables, rather than coding them into the sketch and have to recompile the sketch everytime as I update the set variables. Maybe I am wrong and that would be easier, but I think this would work if I can get the terminal to work.
As I am reading about toFloat() function, it seems that any string after numbers are dropped off. So could I say
I input my values into terminal as such: 60MASHTIME …etc for all variable I end it with the variable it is then the code is:
for x=1 to 5
String stringTerminal = param.asStr();
if stringTerminal = string.endsWith(MASHTEMP)
float MASHTEMP=stringTerminal.toFloat()
if stringTerminal = string.endsWith(MASHTIME)
float MASHTIME=stringTerminal.toFloat()
if stringTerminal = string.endsWith(BOILTIME)
float BOILTIME=stringTerminal.toFloat()
if stringTerminal = string.endsWith(HOPADDS)
float HOPADDS=stringTerminal.toFloat()
else
const char* HOPADDSINFO=stringTerminal
The for statement ensures that a terminal response is requested 5 times until all variables have been input. Would this code allow me to be prompted 5 times, ie what line of code is the one that prompts me to then input something into the terminal widget?
I see, so when the board is connected then terminal is active and thus everytime I input a value it will run these if statements. My concern is when this is at the top of a lot of other code, how do I get it to hang and wait for me to input all the necessary information before going ahead and executing every other code.
I suppose I could put a counter in all the if statements as well and then have a large if statements saying only proceed if counter = 5 etc
@Dave1829 we have VERY similar code to yours for our buttons (and sliders). Not sure why I didn’t suggest similar when the OP asked how it might be done. Maybe because I have been working on free apps i.e. 2000 energy units or less. Menu and Terminal Widgets cost a lot less than a dozen buttons and take up less space.
Thanks for the help guys, using Blynk is really nice and saves a lot of hardware. That code is nice, I will keep that in mind for future use or if I cant properly debug any issues I get with terminal.
The HOPADDS and HOPADDSINFO variables are the only two that have me worried since they are arrays.
I am wondering if for HOPADDS, the tofloat() function will work properly for an array when I input something like:
[10 , 60 , 90]HOPADDS
is it going to properly convert that to a float array of [10 , 60 , 90] ?
ok makes sense still trying to figure out how Blynk integrates with the rest of the sketch. My prior to void(setup) code look as follows: I am getting all sorts of errors when verifying due to variables not being declared; any ideas on how I can fix this?
//////////////////////USER INPUTS from Blynk Terminal
BLYNK_WRITE(V0) // Terminal
{
String fromTerminal = param.asStr();
if (fromTerminal.endsWith(“MASHTEMP”) ){
float MASHTEMP = fromTerminal.toFloat();
}
else if (fromTerminal.endsWith(“MASHTIME”) ) {
const int MASHTIME = fromTerminal.toFloat();
}
else if (fromTerminal.endsWith(“BOILTIME”) ) {
const int BOILTIME = fromTerminal.toFloat();
}
else if (fromTerminal.endsWith(“CHILLTIME”) ) {
const int CHILLTIME = fromTerminal.toFloat();
}
else if (fromTerminal.endsWith(“HOPADDS”) ) {
const int HOPADDS = fromTerminal.toFloat();
}
////////Setting up variables to be declared by Blynk app
const int MASHTEMP; // Desired Mash Temp(deg F)
const int MASHTIME; //Desired Mash Time(milli sec.)
const int BOILTIME; //Desired Boil Time(milli sec.)
const int CHILLTIME; //Desired time to pump all wort through the wort chiller (milli sec.)
//HOP ADDITIONS, HOPADDS and HOPADDSINFO must be the same array length
int HOPADDS []; //Hop times
const char* HOPADDSINFO []//Hop adds contents
float HopAddtime; //Creating variable for for loop below
int h; //Declare the for loop variable
Within each run all are constant but then between brew days they will be changed. So they need to be set one time at the beginning and then they are constants throughout the rest of the code
The only compilation error I get is with const char* HAPADDSINFO = fromTerminal;
All the rest is fine but this is with a blank sketch as I don’t know what else you have in your sketch.