Decoding json data and sending it to another Arduino

Hi,

this is my first topic here, maybe sombody can help me.

My project is about to store solar energy in a lithium accumulator during daytime when there is enough sun and use this energy during the night or when more power is needed than produced by my solar system during the day.
Therefore the system needs to know if the consumtion in my house is higher then the production of my solar system.
I’m running two Fronius Inverters (one with a smartmeter), so it’s possible to get all necessary data from them (fronius inverters have an API).

Now I want to get the API data by an Arduino Uno with a W5100 ethernet shield and pass it on the another Arduino by I2C that should do all the other stuff (switching the inverter or charger, controlling a lcd display and so on). The Arduino with the ethernet connection should be a slave.

I allready managed to get a single value out of on of the inverters to the other Arduino with really dirty, dirty code but I need some more values and decided to switch to a new solution where I can modify things easier. Therefore I found the “ArduinoJson” lib and with some modifications I got the http-client example of that app to read the values from both inverters and print them to the serial interface.
Trouble starts when I tried to setup the next step: the I2C interface. Even if I only add the include statement at the top of my sketch it stops doing it’s work.
The sketch is using 20422 bytes of program memory and 794 bytes of dynamic memory when I run the compiler with I2C lib and 19676/687 bytes when I run it without I2C lib (that sketch produces correct output).

Any ideas what the problem could be and how I can solve it?

I attached my script and the json where the data is extraced.

thanks for your help
Juergen

Arduino_API_neu.ino (3.97 KB)

json.txt (1.01 KB)

The UNO is the wrong hardware choice to process JSON data because it doesn't have enough memory. If you're stick to that hardware you should not use the ArduinoJson library but use a stream parser (parsing while reading the stream) that doesn't store the complete document in RAM.

BTW: Are you sure that I2C is a good choice for an inter-Arduino connection? You should use it only if you're sure you never need to send any data from the slave to the master except the master explicitly asked for that data in advance.

Hi,

I allready had an idea that it might be the issue because I allready had issues with that when using lots of Serial.print commands during testing of another script.
Would a Mega 2560 be better (it has double of the RAM) or should I try it with a Nodemcu (with ESP12E), I allready found a script for that one but also found out that I2C (especially as slave) might not be so easy. With that script I got valid output on serial console after 10 minutes.

The communication will always be triggered by the master, so the slave with the ethernet or wifi will only have to do the API handling.

Another idea: Get rid of the Arduino <=> Arduino Connection and only use the Nodemcu for everything? In that case I’ll need more I2C devices because I need some analog measurements. At the moment there will be the following things:
4x20 LCD, RTC, DAC and then also an ADC

Would a Mega 2560 be better (it has double of the RAM) or should I try it with a Nodemcu (with ESP12E),

The Mega2560 has 4 times the RAM of an UNO, so that might work but I would eliminate the second Arduino then and use just the Mega2560. That might work. A NodeMCU is more difficult to connect to an Ethernet network.

The communication will always be triggered by the master, so the slave with the ethernet or wifi will only have to do the API handling.

But you cannot request information from the slave and that requests that from the inverter. There are a lot of limitations. I2C is definitely wrong here.

pylon:
The Mega2560 has 4 times the RAM of an UNO, so that might work but I would eliminate the second Arduino then and use just the Mega2560. That might work. A NodeMCU is more difficult to connect to an Ethernet network.

Ok then I'll try if the Mega2560 can manage the API and the rest of the tasks.
The NodeMCU has Wifi, so the cable connection wouldn't be needed, even if I usually prefer wired connections.

pylon:
But you cannot request information from the slave and that requests that from the inverter. There are a lot of limitations. I2C is definitely wrong here.

My dirty "working" connection works the following way:
The Arduino gets the data from the API every 10 seconds. When the second Arduino (Master) asks for the value it is sent from the first one.

The Arduino gets the data from the API every 10 seconds. When the second Arduino (Master) asks for the value it is sent from the first one.

So the information might be up to 10 seconds old.

Use a Mega2560, it has enough pins to connect all your devices and flash memory to hold more than enough program code. So eliminate complexity and use just that one board.