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

Problems on migrating for V.5 to V.6 (ESP8266 HVAC / modbus) program) #1189

Closed
jascdk opened this issue Feb 19, 2020 · 7 comments
Closed

Problems on migrating for V.5 to V.6 (ESP8266 HVAC / modbus) program) #1189

jascdk opened this issue Feb 19, 2020 · 7 comments
Labels

Comments

@jascdk
Copy link

jascdk commented Feb 19, 2020

Hi Benoit

I am currently struggling to get a program up and running with Arduino JSON v.6 .

Im a noob at coding, but hoping you / others could help me on the way.

I have a program that I would like to put on a esp8266 microcontroller - it is going to control our local HVAC over modbus.

I simply can't figure out how to convert it - I have looked everywhere and also you nice videos on YouTube. I don't have any coding background at all :/

Looking forward to hear from you:)

@bblanchon
Copy link
Owner

Hi @jascdk,

I'd sincerely like to help you out.
To do that, I need you to:

  1. explain what the problem is,
  2. reduce the length of the code (50 lines max).

Thank you for your understanding.

Best regards,
Benoit

@jascdk
Copy link
Author

jascdk commented Feb 25, 2020

Sure ☺️ I’m abroad for a few days and will do it when I get home again :) thanks a lot

@jascdk
Copy link
Author

jascdk commented Mar 4, 2020

hi @bblanchon :)

First of all thanks for all your great work with the library.

In my house we have a HVAC system that communicates via modbus. I have attached an Wemos D1 mini to it to control it.

It uses this maincode : https://pastebin.com/QnEvGme9 (so you can se it as an reference)

1: My main problem was that the code used json 5 and I would update it to version 6, so it uses the latest version of the library. Make less trouble:)

I have tried asking help from my wife (she codes at her work - but often won't help me, as she hates all my home automation stuff :D )

I did though manage to persuade her to look at my problem. Which gave this result

Skærmbillede 2020-03-04 kl  10 09 29

It actually works, but I can't figure out why she did not change all the "root" to "doc" instead like mentioned in you videos.

She could not give me an answer of this.

Does it looks right to you?

@bblanchon
Copy link
Owner

Hi @jascdk,

What she wrote seems correct.

I use the name "doc" for the complete document and "root" for the root object, so using both names is fine.

There is just one thing that surprises me though: it's that the JsonDocument is passed by value and not by reference. To me it should be:

JsonObject HandleRequest(JsonDocument& doc);

To me, passing by value is not appropriate here because it's not a real copy.
It accidentally works because JsonDocument copies its internal pointers.
I'm surprised this was even possible, I'll fix that in the next release.

Lastly, you don't need to return the root object from HandleRequest() because the JsonDocument contains all the required information. Change the signature of writeResponse() to:

void writeResponse(WiFiClient& client, const JsonDocument& doc);

Does that make sense?

Best regards,
Benoit

@jascdk
Copy link
Author

jascdk commented Mar 4, 2020

hi @bblanchon :)

Thanks for a very quick reply. I will try make the changes you describe. And then I will talk to my wife and hear her about it, and come back to her with her answer:)

Thanks a lot!

Cheers:)

@bblanchon
Copy link
Owner

Copy-contructor of JsonDocument is now hidden in ArduinoJson 6.15.0.

@jascdk
Copy link
Author

jascdk commented Mar 28, 2020

@bblanchon Thanks Benoit:) I got my wife to help with the fixes as you mentioned - it just works now - thanks alot;)

All the best

Jacob / Denmark

@lock lock bot locked as resolved and limited conversation to collaborators May 5, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

2 participants