parsing arduinoJson 6 array to int-s.

Hello! Excuse ma - English is not my mother tongue and I am quite new in programming and Arduino world. But I am working in Botanical Garden and it needs very much different temperature controllers, moisture checking and etc...
Right now I am working on project, where Arduino reads from analog inputs readings from 9 soil moisture sensors. Sensors are calibrated, result is mapped and constrained, so the output can be only from 0 to 99.
Right now result will be displayed in lcd. But I want that I can can see data from my webpage. So, Arduino send data array through serial and WiFi module (NodeMCU) receives it and sends values to webpage. That I want. Of course values changing (interval is right now10 sec).
With code I can see array in NodeMCU (which receives it from Arduino):

void loop()
{
  if (Serial.available())
  {
    String msg = Serial.readString();
    Serial.println(msg);

I can see correctly Jsaon 6 array as it sent from Arduino serial:

{"MULLA_NIISKUS":[41,56,66,65,62,63,65,67,60]}
 // MULLA_NIISKUS means "soil dampness"

9 numbers are moisture sensor values flowerpot nr 1, flowerpot nr 2 and etc.

How I can get these values from Json 6 array to different int-s?

int flowerpot_1
int flowerpot_2...

I read three days different tutorials, tried tens of examples, but not success. I can see only full array as a string and this is quite useless as I understand.

We can't see all of your code. There seems to be no reason to have wrapped 9 ints in a JSON data structure. Why did you?

Many ways to do this. You could use strchr() to find the opening bracket ('[') and then search for the commas and break up the string. Or you could use strtok(). The first thing I would do is get rid of the String class variable msg and make is a char msg[] array. Once you've done that, study what you find here

econjack:
Many ways to do this. You could use strchr() to find the opening bracket ('[') and then search for the commas and break up the string. Or you could use strtok(). The first thing I would do is get rid of the String class variable msg and make is a char msg[] array. Once you've done that, study what you find here

Thank you, I will start from there.

The ability to create and parse an array can be done.

PaulS:
We can't see all of your code. There seems to be no reason to have wrapped 9 ints in a JSON data structure. Why did you?

Can you explain or refer to easier methods, how I can send these values to IoT webpages (as int-s).

danel32:
Can you explain or refer to easier methods, how I can send these values to IoT webpages (as int-s).

The link I provided shows a clear example of almost exactly what you are trying to do.

Seems that I’m doing something very wrong. NodeMCU code:

#include <ArduinoJson.h>
#include "ESP8266WiFi.h"

const size_t CAPACITY = JSON_ARRAY_SIZE(9);

void setup()
{
  Serial.begin(115200);
}
void loop()
{
   while (Serial.available() > 0)
  {
  StaticJsonDocument<CAPACITY> doc;
  deserializeJson(doc, "[1,2,3,4,5,6,7,8,9]");
  JsonArray array = doc.as<JsonArray>();
for(JsonVariant v : array) 
{
    Serial.println(v.as<int>());

}
}
}

Result is something like:

20:30:57.506 -> Soft WDT reset
20:30:57.506 -> 
20:30:57.506 -> >>>stack>>>
20:30:57.506 -> 
20:30:57.506 -> ctx: cont
20:30:57.506 -> sp: 3ffffc90 end: 3fffffc0 offset: 01b0
20:30:57.506 -> 3ffffe40:  3ffe85b5 00000000 3ffe85b4 40203216  
20:30:57.506 -> 3ffffe50:  3fffc200 40105370 00000000 3ffee2dc  
20:30:57.506 -> 3ffffe60:  3ffee284 00000001 3ffee284 40201d60  
20:30:57.506 -> 3ffffe70:  00000000 00000000 0000001f 40201f3d  
20:30:57.506 -> 3ffffe80:  3ffe85b3 00000005 3ffee284 40202024  
20:30:57.506 -> 3ffffe90:  40202fa8 00000030 3ffee284 40201f58  
20:30:57.540 -> 3ffffea0:  3ffee284 3fffff6c 3ffee284 40202058  
20:30:57.540 -> 3ffffeb0:  00000000 3fffff6c 3fffff1c 40201bdf  
20:30:57.540 -> 3ffffec0:  3ffffedc 3ffffedc 3ffffedc 3fffff6c  
20:30:57.540 -> 3ffffed0:  3fffff5c 3ffffedc 3ffee2c0 00000009  
20:30:57.540 -> 3ffffee0:  3fffdab0 00000006 00000000 00000008  
20:30:57.540 -> 3ffffef0:  00000000 ffff0006 00000000 00000007  
20:30:57.540 -> 3fffff00:  00000000 ffffda06 00000000 00000006  
20:30:57.540 -> 3fffff10:  feefeffe ffffef06 00000000 00000005  
20:30:57.574 -> 3fffff20:  feefeffe ffffef06 00000000 00000004  
20:30:57.574 -> 3fffff30:  402032b5 ffff3406 00000000 00000003  
20:30:57.574 -> 3fffff40:  40203575 ffff0006 00000000 00000002  
20:30:57.574 -> 3fffff50:  0001c200 ffff0006 00000000 00000001  
20:30:57.574 -> 3fffff60:  feefeffe ffff0006 00000000 3ffffec0  
20:30:57.574 -> 3fffff70:  3ffe85b2 3ffffec0 3f005d0a 00000000  
20:30:57.574 -> 3fffff80:  00000000 00000000 00000000 feefeffe  
20:30:57.608 -> 3fffff90:  00000000 00000000 00000001 3ffee2dc  
20:30:57.608 -> 3fffffa0:  3fffdad0 00000000 3ffee2ac 402024d0  
20:30:57.608 -> 3fffffb0:  feefeffe feefeffe 3ffe8524 40100461  
20:30:57.608 -> <<<stack<<<
20:30:57.608 -> 
20:30:57.608 ->  ets Jan  8 2013,rst cause:2, boot mode:(3,6)
20:30:57.608 -> 
20:30:57.608 -> load 0x4010f000, len 1384, room 16 
20:30:57.608 -> tail 8
20:30:57.642 -> chksum 0x2d
20:30:57.642 -> csum 0x2d
20:30:57.642 -> v8b899c12
20:30:57.642 -> ~ld
void loop()
{
   while (Serial.available() > 0)
  {

Why does the test depend on the arrival of serial data?

Why isn't the test code in setup, so it only executes once?

"[1,2,3,4,5,6,7,8,9]"

That is NOT valid JSON.

Go to Assistant | ArduinoJson 6

Paste the JSON into the box titled "Input".

{"MULLA_NIISKUS":[41,56,66,65,62,63,65,67,60]}

Page down and see the box titled "Parsing Program" for source code that extracts the first 4 elements of the array. Insert this code in the setup() function and add Serial.begin and Serial.println.

const size_t capacity = JSON_ARRAY_SIZE(9) + JSON_OBJECT_SIZE(1) + 20;
DynamicJsonDocument doc(capacity);

const char* json = "{\"MULLA_NIISKUS\":[41,56,66,65,62,63,65,67,60]}";

deserializeJson(doc, json);

JsonArray MULLA_NIISKUS = doc["MULLA_NIISKUS"];
int MULLA_NIISKUS_0 = MULLA_NIISKUS[0]; // 41
int MULLA_NIISKUS_1 = MULLA_NIISKUS[1]; // 56
int MULLA_NIISKUS_2 = MULLA_NIISKUS[2]; // 66
int MULLA_NIISKUS_3 = MULLA_NIISKUS[3]; // 65

Thank you, gbafamily!

It works, but how add "protection" that processor will not print out quantum of zeros?

...9:21:16.341 -> 0
09:21:16.341 -> 0
09:21:16.341 -> 0
09:21:16.341 -> 0
09:21:16.341 -> 0
09:21:16.850 -> 93
09:21:16.850 -> 89
09:21:16.850 -> 92
09:21:16.850 -> 90
09:21:16.850 -> 86
09:21:16.850 -> 87
09:21:16.850 -> 90
09:21:16.850 -> 83
09:21:16.850 -> 94
09:21:18.239 -> 0
09:21:18.239 -> 0
09:21:18.239 -> 0...

It works, but how add "protection" that processor will not print out quantum of zeros?

Why is the processor printing all those 0s? The other values that are being printed don't match the expected output from gbafamily's code, so you must be running different code against different data.

Anonymous printing sucks, and it strongly discouraged.