Invalid JSON Object

I was able to run this program but suddenly it became "Invalid JSON Object". Where did it go wrong?
//Arduino 1

//Include Lib for Arduino to Nodemcu
#include <ArduinoJson.h>

int temp;

//Timer to run Arduino code every 5 seconds
unsigned long previousMillis = 0;
unsigned long currentMillis;
const unsigned long period = 10000;  

void setup() {
  // Initialize Serial port
  Serial.begin(115200);
  Serial1.begin(9600);
  while (!Serial) continue;
}

void loop() {
  //Get current time
  currentMillis = millis();

  if ((currentMillis - previousMillis >= period)){
    
    StaticJsonDocument<1000> doc;
    DeserializationError error = deserializeJson(doc, Serial1);
  
    // Test parsing
    while (error) {
      Serial.println("Invalid JSON Object");
      delay(500);
      DeserializationError error = deserializeJson(doc, Serial1);
    }
  
    temp = doc["temperature"];
    Serial.println(temp);
    
    previousMillis = previousMillis + period;
  }
}

//Arduino 2

// wire i2c
#include <Wire.h> 
#include <LiquidCrystal_I2C.h>
#include <ArduinoJson.h>

LiquidCrystal_I2C lcd(0x27,16,2);  // set the LCD address to 0x27 for a 16 chars and 2 line display

// bme280
#include <SPI.h>
#include <Adafruit_BMP280.h>

#define BMP_SCK  (13)
#define BMP_MISO (12)
#define BMP_MOSI (11)
#define BMP_CS   (10)

Adafruit_BMP280 bmp; // I2C
//Adafruit_BMP280 bmp(BMP_CS); // hardware SPI
//Adafruit_BMP280 bmp(BMP_CS, BMP_MOSI, BMP_MISO,  BMP_SCK);
// end

// bh1750
#include <BH1750.h>

BH1750 lightMeter;
//end

// tm1637
#include <TM1637Display.h>
#define CLK PB15
#define DIO PA8
TM1637Display display(CLK, DIO);
// end

const int ledPin =  PC15;
const int ledSTM32 =  LED_BUILTIN;
int ledState = HIGH;
int state ;

const int sensorMin = 0;     // sensor minimum
const int sensorMax = 4096;  // sensor maximum

int analogInput = PB0;
float vout = 0.0;
float vin = 0.0;
float R1 = 22000.0;
float R2 = 3000.0;
int value = 0;
int i = 0;
int temp;

unsigned long previousMillis1 = 0;
const long interval1 = 8000;

unsigned long previousMillis2 = 0;
const long interval2 = 500;

unsigned long sensorMilis_1 = 0;
const long sensorinterval_1 = 500;

unsigned long sensorMilis_2 = 0;
const long sensorinterval_2 = 500;

const uint8_t maxvolt[] = {
  SEG_G,
  SEG_G,
  SEG_G,
  SEG_G
};

void setup() {
  analogReadResolution(12);
  Serial.begin(115200); // on PA9 PA10
  Serial1.begin(9600); // on PA9 PA10
  
  Wire.begin();
  lightMeter.begin();
  
  lcd.init();
  lcd.backlight();

  display.setBrightness(5);
  
  // Clear the display
  display.clear();

  pinMode(analogInput, INPUT);
  pinMode(ledPin, OUTPUT);
  pinMode(ledSTM32, OUTPUT);
  digitalWrite(ledPin, HIGH);
  digitalWrite(ledSTM32, HIGH);
  
  if (!bmp.begin(0x76)) {
    Serial.println("Tidak ada sensor BME280, cek rangkaianmu!");
    while (1);
  }
  /*
  bmp.setSampling(Adafruit_BMP280::MODE_FORCED,         // Operating Mode
                  Adafruit_BMP280::SAMPLING_X1,         // Temp. oversampling
                  Adafruit_BMP280::SAMPLING_X1,         // Pressure oversampling
                  Adafruit_BMP280::FILTER_OFF);         // Filtering
                  // Adafruit_BMP280::STANDBY_MS_4000); // Standby time
  */
  bmp.setSampling(Adafruit_BMP280::MODE_NORMAL,     /* Operating Mode. */
                Adafruit_BMP280::SAMPLING_X2,     /* Temp. oversampling */
                Adafruit_BMP280::SAMPLING_X16,    /* Pressure oversampling */
                Adafruit_BMP280::FILTER_X16,      /* Filtering. */
                Adafruit_BMP280::STANDBY_MS_500); /* Standby time. */

  lcd.clear();
  for (i = 16; i >= 0; i--) //program increamental nilai i dari 0 sampai 15
  {
    lcd.setCursor(i, 0); //setting posisi kursor kolom sesuai nilai i
    lcd.print("Weather Station"); //menampilkan karakter
    delay(500); //menunda tampilan selama 500 ms
    lcd.clear(); //menghapus semua karakter
  }
}


void loop() {
  bmp.takeForcedMeasurement();

  StaticJsonDocument<1000> doc;
  temp = bmp.readTemperature();
  Serial.println(temp);
  doc["temperature"] = temp;
  serializeJson(doc, Serial1);

  if(millis() - previousMillis1 >= interval1) {
    previousMillis1 = millis();
    state++;
  }
  
  if(state==4){
    state=1;
  }

  int sensorReading = analogRead(PA1);
  int range = map(sensorReading, sensorMin, sensorMax, 0, 3);

  float lux = lightMeter.readLightLevel();
  
  switch (state){
    case 1:
      if(millis() - sensorMilis_1 >= sensorinterval_1) {
        sensorMilis_1 = millis();
        int suhu_udara = bmp.readTemperature();
        if(suhu_udara < 20){
          lcd.clear();
          lcd.setCursor(0,0);
          lcd.print("SUHU");
          lcd.setCursor(0,1);
          lcd.print(suhu_udara);
          lcd.print(" *C!");
        }else if(suhu_udara > 40){
          lcd.clear();
          lcd.setCursor(0,0);
          lcd.print("SUHU");
          lcd.setCursor(0,1);
          lcd.print(suhu_udara);
          lcd.print(" *C!");
        }else{
          lcd.clear();
          lcd.setCursor(0,0);
          lcd.print("SUHU");
          lcd.setCursor(0,1);
          lcd.print(suhu_udara);
          lcd.print(" *C");
        }
      }
    break;
    case 2:
      if(millis() - sensorMilis_1 >= sensorinterval_1) {
        sensorMilis_1 = millis();
        int pressure = bmp.readPressure() / 100.0;
        lcd.clear();
        lcd.setCursor(0,0);
        lcd.print("TEKANAN UDARA");
        lcd.setCursor(0,1);
        lcd.print(pressure);
        lcd.print(" hPa");
      }
    break;
    /*
    case 3:
        if(millis() - sensorMilis_1 >= sensorinterval_1) {
          sensorMilis_1 = millis();
          int ketinggian = bmp.readAltitude(1013.25);
          lcd.clear();
          lcd.setCursor(0,0);
          lcd.print("KETINGGIAN");
          lcd.setCursor(0,1);
          lcd.print(ketinggian);
          lcd.print(" m");
        }
    break;
    */
    case 3:
      if(millis() - sensorMilis_2 >= sensorinterval_2) {
        sensorMilis_2 = millis();
          switch (range){
            case 0:
              lcd.clear();
              lcd.setCursor(0,0);
              lcd.print("CURAH HUJAN");
              lcd.setCursor(0,1);
              lcd.print("HUJAN");
            break;
            case 1:
              lcd.clear();
              lcd.setCursor(0,0);
              lcd.print("CURAH HUJAN");
              lcd.setCursor(0,1);
              lcd.print("PERINGATAN HUJAN");
            break;
            case 2:
              lcd.clear();
              lcd.setCursor(0,0);
              lcd.print("CURAH HUJAN");
              lcd.setCursor(0,1);
              lcd.print("TIDAK HUJAN");
            break;
          }
      }
    break;
  }
  if(lux < 100){
    if (millis() - previousMillis2 >= interval2) {
      // save the last time you blinked the LED
      previousMillis2 = millis();
    
        // if the LED is off turn it on and vice-versa:
        if (ledState == HIGH) {
          ledState = LOW;
        } else {
          ledState = HIGH;
        }
    
        // set the LED with the ledState of the variable:
        digitalWrite(ledSTM32, ledState);
    }
    digitalWrite(ledPin, HIGH);
  }else if(lux > 100){
    digitalWrite(ledSTM32, HIGH);
    digitalWrite(ledPin, LOW);
  }
}

Before the error
379116540_3675485712679962_176016320026089929_n

This is like a machine gun on Serial1, you are blasting the JSON on Serial1 at the speed of the loop (until the send buffer is saturated the baud rate is the limiting factor)

How often do you need to send that ? Use millis to define a sending period that makes sense

Should I add a mailing list to postpone it?

A mailing list ? Not sure what this has to do with coding

You need something like

if(millis() - previousTempMillis >= tempInterval) {
    previousTempMillis = millis();
    … // here acquire and send the temperature 
}

That's what I mean, sorry my English is bad. What causes Invalid JSON Object?

I’m not sure if that’s the bug but the serial buffer does not have infinite depth. (64 bytes)

So if the receiving buffer is full and you keep receiving data, then the oldest byte gets lost. Imagine you loose the opening { and then the JSON is malformed. That’s what I would double check by slowing down the pace at which the JSON is sent

I've added it and it's still invalid json

can you post the codes again?

also can you post (as text, no picture of text) what you see in the Serial monitor?

(reading on my iPhone at the moment, I'll be on my Mac later and will have a better look at what you do)

Look at this example.

Why is it invalid? Analyze the character string to determine what is wrong with it.

Better, post the string.

this is what happened

deserializeJson() returned EmptyInput

Do you use the same port twice? Has the Arduino 2 u(s)art ports? Use the first for programming and Serial.print and the other one to communicate with the other board.

A datasheet from the used board is helpful.

Yes, I use the same port twice, does it have to be split?

What’s your arduino?

Arduino Nano and Arduino Uno

[quote="bimosora, post:15, topic:1169251]
Arduino Nano and Arduino Uno
[/quote]

➜ that's a lot of memory then for your small arduinos

you should make them much smaller esp if you only want to hold something like {"temperature":32}

The same port one times @ 115200Bd and the second times @ 9600Bd. It isn't a good idea to use the same port for programming/debugging and using for other reasons. Both boards have only one U(S)ART. Use Software serial ore switch to another board with two ore more U(S)ART.

The code is using Serial and Serial1 - this can't compile on those machines...

are you sharing the real information??

I just want to display via Hardwareserial, receiver and sender. When the sender issues writing, the recipient can get the results. Another example is that the Arduino is connected via Bluetooth, either Hardwareserial or Softwareserial, then from Bluetooth it is sent to a smartphone application such as Blynk or Remotexy.

How can you get a json error message when the code cannot compile for your arduino?