Skip to main content
deleted 213 characters in body; edited title
Source Link
dda
  • 1.6k
  • 1
  • 12
  • 18

Problem regarding getting split data of JSON - Another ISSUEissue

In my recent project, I'm working with Arduino and JSON. In that, I've successfully split the JSON data which I want.Here, my My JSON Datadata length is fixed. So, here I used the length() function and I'm getting the length of my data.

Now, my input JSON Datadata is:

And so usingUsing the length() function, its length is 39.

But when I use an if statement like if(len == 39) and put my logic inside this, I'm not getting the split data. Below is my whole code.

#include<LiquidCrystal.h>

LiquidCrystal lcd(12, 11, 7, 6, 5, 4);
 
String data_TPS_Json = "";
String data_MAP_Json = "";
String data_LOAD_TM_Json = "";
 
String response = "";
bool begin = false;
 
int counter = 0;
int len = 0;
char in;
 
float TPS_Json;
float MAP_Json;
float LOAD_TM_Json;

void setup()
  {
  Serial.begin(9600);
  lcd.begin(16, 2);
}

void loop()
{
  {
  while(Serial.available() || !begin)
  {
    in = Serial.read();
 
    if (in == '{')
    {
      begin = true;
    }
    
    if(begin)
    {
      counter++;
      response += (in);
 
      len = response.length();
 
      if(len == 39)
      {
        if(counter >= 9 && counter <= 12)
        {
          data_TPS_Json += (in);
        }
 
        if(counter >= 22 && counter <= 25)
        {
          data_MAP_Json += (in);
        }
      
        if(counter >= 36 && counter <= 37)
        {
          data_LOAD_TM_Json += (in);
        }   
      }
    }

    if(in == '}')
    {
        break;
    }
    delay(1);
  }
 
    TPS_Json = data_TPS_Json.toFloat();
    MAP_Json = data_MAP_Json.toFloat();
    LOAD_TM_Json = data_LOAD_TM_Json.toFloat();
    
    lcd.setCursor(0, 0);
    lcd.print(TPS_Json);
    lcd.setCursor(8, 0);
    lcd.print(MAP_Json);
    lcd.setCursor(0, 1);
    lcd.print(LOAD_TM_Json);
}

Problem regarding getting split data of JSON - Another ISSUE

In my recent project, I'm working with Arduino and JSON. In that, I've successfully split JSON data which I want.Here, my JSON Data length is fixed. So, here I used length() function and getting the length of my data.

Now, my input JSON Data is:

And so using length() function its length is 39.

But when I use if statement like if(len == 39) and put my logic inside this, I'm not getting split data. Below my whole code.

#include<LiquidCrystal.h>

LiquidCrystal lcd(12, 11, 7, 6, 5, 4);
 
String data_TPS_Json = "";
String data_MAP_Json = "";
String data_LOAD_TM_Json = "";
 
String response = "";
bool begin = false;
 
int counter = 0;
int len = 0;
char in;
 
float TPS_Json;
float MAP_Json;
float LOAD_TM_Json;

void setup()
 {
  Serial.begin(9600);
  lcd.begin(16, 2);
}

void loop()
{
  
  while(Serial.available() || !begin)
  {
    in = Serial.read();
 
    if (in == '{')
    {
      begin = true;
    }
    
    if(begin)
    {
      counter++;
      response += (in);
 
      len = response.length();
 
      if(len == 39)
      {
        if(counter >= 9 && counter <= 12)
        {
          data_TPS_Json += (in);
        }
 
        if(counter >= 22 && counter <= 25)
        {
          data_MAP_Json += (in);
        }
      
        if(counter >= 36 && counter <= 37)
        {
          data_LOAD_TM_Json += (in);
        }   
      }
    }

    if(in == '}')
    {
        break;
    }
    delay(1);
  }
 
    TPS_Json = data_TPS_Json.toFloat();
    MAP_Json = data_MAP_Json.toFloat();
    LOAD_TM_Json = data_LOAD_TM_Json.toFloat();
    
    lcd.setCursor(0, 0);
    lcd.print(TPS_Json);
    lcd.setCursor(8, 0);
    lcd.print(MAP_Json);
    lcd.setCursor(0, 1);
    lcd.print(LOAD_TM_Json);
}

Problem regarding getting split data of JSON - Another issue

In my recent project, I'm working with Arduino and JSON. I've successfully split the JSON data I want. My JSON data length is fixed. So, I used the length() function and I'm getting the length of my data.

Now, my input JSON data is:

Using the length() function, its length is 39.

But when I use an if statement like if(len == 39) and put my logic inside this, I'm not getting the split data. Below is my whole code.

#include<LiquidCrystal.h>

LiquidCrystal lcd(12, 11, 7, 6, 5, 4);
String data_TPS_Json = "";
String data_MAP_Json = "";
String data_LOAD_TM_Json = "";
String response = "";
bool begin = false;
int counter = 0;
int len = 0;
char in;
float TPS_Json;
float MAP_Json;
float LOAD_TM_Json;

void setup() {
  Serial.begin(9600);
  lcd.begin(16, 2);
}

void loop() {
  while(Serial.available() || !begin) {
    in = Serial.read();
    if (in == '{') {
      begin = true;
    }
    if(begin) {
      counter++;
      response += (in);
      len = response.length();
      if(len == 39) {
        if(counter >= 9 && counter <= 12) {
          data_TPS_Json += (in);
        }
        if(counter >= 22 && counter <= 25) {
          data_MAP_Json += (in);
        }
        if(counter >= 36 && counter <= 37) {
          data_LOAD_TM_Json += (in);
        }   
      }
    }

    if(in == '}') {
      break;
    }
    delay(1);
  }
  TPS_Json = data_TPS_Json.toFloat();
  MAP_Json = data_MAP_Json.toFloat();
  LOAD_TM_Json = data_LOAD_TM_Json.toFloat();
  lcd.setCursor(0, 0);
  lcd.print(TPS_Json);
  lcd.setCursor(8, 0);
  lcd.print(MAP_Json);
  lcd.setCursor(0, 1);
  lcd.print(LOAD_TM_Json);
}
Source Link
Hasan
  • 1.5k
  • 14
  • 28

Problem regarding getting split data of JSON - Another ISSUE

In my recent project, I'm working with Arduino and JSON. In that, I've successfully split JSON data which I want.Here, my JSON Data length is fixed. So, here I used length() function and getting the length of my data.

Now, my input JSON Data is:

{"TPS":"0.40","MAP":"0.95","LOAD":"14"}

And so using length() function its length is 39.

But when I use if statement like if(len == 39) and put my logic inside this, I'm not getting split data. Below my whole code.

Here, I'm displaying my data on LCD.

#include<LiquidCrystal.h>

LiquidCrystal lcd(12, 11, 7, 6, 5, 4);

String data_TPS_Json = "";
String data_MAP_Json = "";
String data_LOAD_TM_Json = "";

String response = "";
bool begin = false;

int counter = 0;
int len = 0;
char in;

float TPS_Json;
float MAP_Json;
float LOAD_TM_Json;

void setup()
{
  Serial.begin(9600);
  lcd.begin(16, 2);
}

void loop()
{
  
  while(Serial.available() || !begin)
  {
    in = Serial.read();

    if (in == '{')
    {
      begin = true;
    }
    
    if(begin)
    {
      counter++;
      response += (in);

      len = response.length();

      if(len == 39)
      {
        if(counter >= 9 && counter <= 12)
        {
          data_TPS_Json += (in);
        }

        if(counter >= 22 && counter <= 25)
        {
          data_MAP_Json += (in);
        }
      
        if(counter >= 36 && counter <= 37)
        {
          data_LOAD_TM_Json += (in);
        }   
      }
    }

    if(in == '}')
    {
        break;
    }
    delay(1);
  }

    TPS_Json = data_TPS_Json.toFloat();
    MAP_Json = data_MAP_Json.toFloat();
    LOAD_TM_Json = data_LOAD_TM_Json.toFloat();
    
    lcd.setCursor(0, 0);
    lcd.print(TPS_Json);
    lcd.setCursor(8, 0);
    lcd.print(MAP_Json);
    lcd.setCursor(0, 1);
    lcd.print(LOAD_TM_Json);
}