@Delta_G
Your correction made the code work, thanks.
And the global variable thing made me think about how to go on with the next problem, thank you.
I just tried to implement this code in another greater code block.
// Print the data extracted from the JSON
void printUserData(const struct UserData* userData) {
int tweet = 0;
int number = 1023;
Serial.print("data = ");
Serial.println(userData->pressure);
int intPressure = atoi(userData->pressure);
Serial.print("intPressure = ");
Serial.println(intPressure);
//if (*(userData->pressure) == number) // ==number brings HIGH and !=number brings LOW
int print() {
if(intPressure != 0)
{
Serial.println("HIGH");
tweet = HIGH;
}
else
{
Serial.println("LOW");
tweet = LOW;
}
return tweet;
}
void loop() {
int tweetStatus = print();
val = digitalRead(LED_BUILTIN);
// tweetStatus makes LED_BUILTIN either HIGH or LOW
digitalWrite(LED_BUILTIN, tweetStatus);
Serial.println("---");
Serial.println(val);
Serial.println("---");
...
}
The output is the following error message:
test_bed: In function 'void printUserData(const UserData*)':
test:175: error: a function-definition is not allowed here before '{' token
^
test_bed:239: error: expected '}' at end of input
^
exit status 1
a function-definition is not allowed here before '{' token
According to the error above, you cannot place the function int(print(){} ) inside the function void printUserData(const struct UserData* userData){}. Generally speaking, you cannot put a function inside a function. I chose the if statement if(intPressure != 0)|{} to be inside the void printUserData function because I wanted this if statement to use the variable int intPressure = atoi(userData->pressure); . This variable decides about whether the LED_BUILTIN is LOW or HIGH.
Maybe one way to solve this is to make int intPressure = atoi(userData->pressure); to a global variable, so that it can be easily accessed by any function, particularly the void loop() function? This way, I could also just move the If statement if(intPressure != 0)|{} to the void loop() function. If this a good way to go, how would you do that?