Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

I am not able to make IF condition #2002

Closed
Regdr opened this issue Nov 29, 2023 · 3 comments
Closed

I am not able to make IF condition #2002

Regdr opened this issue Nov 29, 2023 · 3 comments
Labels
question v6 ArduinoJson 6

Comments

@Regdr
Copy link

Regdr commented Nov 29, 2023

Hello I am trying to make a condition from a value taken from http://......./ test.json
usually I put all the connection settings and print immediately on tft, but now I need to make a condition depending of the value received

part of the code:

//JSON HTTP_REQUEST
  WiFiClient client;
  HTTPClient http;  
// Send request
  http.useHTTP10(true);
  http.begin(client, "http://........../2CF432C2560E.json");
  http.GET();
// Parse response
  DynamicJsonDocument doc(2048);
  deserializeJson(doc, http.getStream());
// Read values
  tft.setTextSize(1);
  tft.setCursor(250,45);
  tft.setTextColor(TFT_BLUE, TFT_BLACK);
  tft.println(doc["T.cpu"].as<float>(), 1); 

example:

  if (doc["switch.fan"].as<const char*>() == on) {
    tft.println("X");
 }

my intention is to print some simbol if the condition of the switch is ON, many thanks

@Regdr Regdr added the question label Nov 29, 2023
@bblanchon
Copy link
Owner

Hi @Regdr,

Assuming your input looks like this:

{
  "switch": {
    "fan": "on"
  }
}

Then, you can use the following:

if (doc["switch"]["fan"] == "on")

Best regards,
Benoit

@Regdr
Copy link
Author

Regdr commented Nov 30, 2023

Thanks @bblanchon is working

@bblanchon
Copy link
Owner

You're welcome, @Regdr.
Thank you for using ArduinoJson!
Don't forget to cast a star to support the project 😉

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jan 1, 2024
@bblanchon bblanchon added the v6 ArduinoJson 6 label Feb 6, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
question v6 ArduinoJson 6
Projects
None yet
Development

No branches or pull requests

2 participants