[SOLVED] Data from Avery Scale

I have been banging my head against this problem for a week. I need help!

I am able to get the following weight from an avery scale and put it into a char array. but i want to push the data through a pushingbox api which is sent as a string. I cant for the life of me figure out the proper way to get this data formatted correctly so that it populates . Warning i’m a newb at coding so graphic content below!! Any suggestions on what im doing inefficient and wrong would be helpful.

the current output of this is 0.0000 no matter what the scale reads.
I know the scale reads the following: “####.#” in terms of digits

#include "ESP8266WiFi.h"

const char WEBSITE[] = "api.pushingbox.com"; //pushingbox API server
const String devid = "device id"; //device ID from Pushingbox 

const char* MY_SSID = "ssid";
const char* MY_PWD =  "password";

char receivedChar1[16]={'\0'};
char pWeight[6]={'\0'};
char cWeight[6]={'\0'};
float Weight = 0.0;
int Cycles = 0;
boolean newData = false;
boolean Datasend = false;

void setup()
{
  Serial.begin(9600, SERIAL_7E1);
  WiFi.begin(MY_SSID, MY_PWD);
  while (WiFi.status() != WL_CONNECTED) //not connected,..waiting to connect
    {
      delay(1000);
    }
}


void loop()
{
  Serial.write(0x57);
  Serial.write(0x0D);
  recvOneChar();
  showNewData();
  if (Datasend == true) 
  { 
    WiFiClient client;  //Instantiate WiFi object
    //Start or API service using our WiFi Client through PushingBox
    if (client.connect(WEBSITE, 80))
      { 
        
         //Serial.println("Im printing data: ");
        // Serial.print(counter);
         client.print("GET /pushingbox?devid=" + devid
       + "&Weight=" + Weight
       + "&Store=9048"      
       );

      client.println(" HTTP/1.1"); 
      client.print("Host: ");
      client.println(WEBSITE);
      client.println("User-Agent: ESP8266/1.0");
      client.println("Connection: close");
      client.println();
      delay(10000);
      } else {
        //Serial.println("Connection Failed");
      }
      Datasend = false;
      
      client.stop();
      client.flush();
  }
      
}

void recvOneChar() 
{
 if (Serial.available() > 0) 
  {
  
   for(int i=0;i<6;i++){pWeight[i]=cWeight[i];} 
   
  
   for(int i=0;i<16;i++)
   {      
        receivedChar1[i] = Serial.read();
        if( i >=3 and i<=7){
          cWeight[(i-3)]=  receivedChar1[i];
          }
   }
     newData = true;
  }
}

void showNewData() {
 if (newData == true and strcmp(cWeight, "  0.0")!=0) {
  if (strcmp(cWeight, pWeight)==0){
   Cycles=Cycles+1;
   Datasend = false;
 } else {  
  Datasend = false;
  Cycles = 0;
 }
 if (Cycles ==5)
 { 
  Weight = atof(cWeight);
  Datasend = true;
  newData = false;
}

}
}

Please follow the advice in read this before posting a programming question and put your code in code tags to remove the italics caused by using an array index of i

ok thanks for the heads up. I think i fixed it now.

You have what appears to be a classic error in recvOneChar. You check that there is one character waiting to read and then read sixteen. Serial is slow, especially at 9600 baud, so that's unlikely to work.

I'd suggest that you take a step back and use softwareserial to read the scale so that you can use serial to debug and see what you're actually getting.

   for (int i = 0; i < 16; i++)
    {
      receivedChar1[i] = Serial.read();
      if ( i >= 3 and i <= 7)
      {
        cWeight[(i - 3)] =  receivedChar1[i];
      }
    }

At this point in the program how do you know that there are 16 characters available to be read ?

I can consistently get the reading from the scale. The code works for that portion.

I originally had this code on a mega so I was getting data from the scale and then outputting it on the serial monitor and it was flawless. It was reporting the weight in the following format: ###.#

So if the weight was 120.2 then output was 120.2
if the weight was 20.2 then the output was 20.2

UKHeliBob:

   for (int i = 0; i < 16; i++)

{
     receivedChar1[i] = Serial.read();
     if ( i >= 3 and i <= 7)
     {
       cWeight[(i - 3)] =  receivedChar1[i];
     }
   }



At this point in the program how do you know that there are 16 characters available to be read ?

I agree it is an assumption on my part. At this point the only thing i know is that I had just sent the command to the scale that once it receives, it is supposed to send back 16 characters with the weight and scale status. I really don’t except for the fact that the scale outputs in the same format each time? Is there a check i can throw in there?

the only thing i know is that I had just sent the command to the scale that once it receives, it is supposed to send back 16 characters with the weight and scale status.

Bear in mind that serial comms is very slow compared to the rate at which the Arduino works so it is quite possible that when Serial.available() returns a value greater than 0 fewer than 16 bytes are available.

The classic way to deal with this is to use an end of message marker, perhaps a linefeed, carriage return or both, which, when received assures that you have all the data. To use it you read characters and save them and process the chars on receipt of the end of message marker.

What is the full format of the message that you receive ?

Ah ok that makes sense…here is what i should be receiving according to the scale’s documentation:

Command Sent:
W

Scale Response:
xxxx.xxuu
hh

xxxx.xx is the weight
uu is the unit of measure…in this case lb
hh is Two status bytes of the scale.

I guess what you are saying is that i should be exiting my loop when I read “”?

I guess what you are saying is that i should be exiting my loop when I read “”?

No, not really

set a boolean to false
if data is available then read one character
if it is an then discard it but set the boolean to true and set an index variable to zero

if the boolean is true save the character to an array of chars and increment the index
if the index is now 16
terminate the character array with ‘\0’ and use the data in the array
keep reading until you get an ETX character (0x03)

Now you are ready for the next reading

NOTE : do not block execution of the code so no for loops or whiles. Let loop() do the looping for you

Ok I think I accomplished what you suggested. I went back to my mega so I could get a serial monitor readout. the code is below and this is my current readout on the serial monitor. This looks much cleaner than what I had before.

So now that I can reliably get the parts of the readout I want. IE index3-index7. How do I go about getting that captured data as a float? so I can do comparisons… !=0 or == and then most importantly. when I go to create my string to send to the api I need to be able to do the following: “&Weight=” + and the api gets the string “&Weight=0.0” or “&Weight=125.5” depending on what the scale reads.

Index 1:
Index 2:
Index 3:
Index 4:
Index 5: 0
Index 6: .
Index 7: 0
Index 8: l
Index 9: b
Index 10:
Index 11:

Index 12: 2
Index 13: 0
Index 14:
Index 15:

char receivedChar1[16]={'\0'};
char pWeight[6]={'\0'};
char cWeight[6]={'\0'};
float Weight = 000.0;
int Cycles = 0;
int charindex = 0;
boolean readData = false;
boolean newData = false;
boolean Datasend = false;

void setup()
{
  Serial2.begin(9600, SERIAL_7E1);
  Serial.begin (9600);
}


void loop()
{
  Serial2.write(0x57);
  Serial2.write(0x0D);
  recvOneChar();
  showNewData();  
  delay(1000);    
}

void recvOneChar() 
{
 if (Serial2.available() > 0) 
  {
   //for(int i=0;i<6;i++){pWeight[i]=cWeight[i];} 
   receivedChar1[charindex] = Serial2.read();
   Serial.print("Index ");
   Serial.print(charindex);
   Serial.print(": ");
   Serial.print(receivedChar1[charindex]);
   Serial.println();
   if (receivedChar1[charindex] == 0x0A){readData = true;}
   if (receivedChar1[charindex] == 0x03){readData = false; newData = true; charindex=0;}
   if (readData == true){charindex++; }
  }
}

void showNewData() {
 if (newData == true and strcmp(cWeight, "  0.0")!=0) {
  if (strcmp(cWeight, pWeight)==0){
   Cycles=Cycles+1;
   Datasend = false;
 } else {  
  Datasend = false;
  Cycles = 0;
 }
 if (Cycles ==5)
 { 
  Weight = atof(cWeight);
  newData = false;
}

}
}

UKHeliBob:

   for (int i = 0; i < 16; i++)

{
     receivedChar1[i] = Serial.read();
 :



At this point in the program how do you know that there are 16 characters available to be read ?

Possibly by changing the test condition above from

if (Serial.available() > 0)

to

if (Serial.available() >=16)

The the float value we need is fortunatly at a fixed position in this string. So discard the first one with a dummy Serial.read(), then unleash the ( Serial.parseFloat() and then do Serial.reads until an ETX is seen (possibly capturing the status bytes.

This code is allowed to loop, without blocking (on more Serial input), as we know we have 16 characters (or more)

This should simplify the code some, but there is the flaw that a dropped character (communication noise) will make it miss a reading or two before syncing up again at the ETX. Making code resilient to data faults usually makes code twice/triple the size.

It looks like you are close, but what became of receivedChar1[0] ?

To turn the first 7 characters of the received string (index 0 to 6) into a float put a '\0' in position 7 of the char array to terminate it then use the atof() function to convert the string to a float but be careful when comparing floats as they may not be as accurate as you would want. You can compare strings using strcmp() and as the "floats" will always have the form xxxx.xx will provide a more certain way of doing the comparison.

thanks for your help. I tried to add the '\0' to the char at the correct position..now im running into another issue....It seems im able to get the correct weight from the scale 4 loops in a row then after that it gets stuck.....illl try to show you:

for 4 cycles outputs this:

Index 0:

Index 1:
Index 2:
Index 3:
Index 4:
Index 5: 0
Index 6: .
Index 7: 4
Index 8: l
Index 9: b
Index 10:

Index 11:

Index 12: 0
Index 13: 0
Index 14:

Index 15:

after the Fifth cycle outputs this:

Index 0:

Index 1:
Index 2:
Index 3:

Index 4:

Index 5:

Index 6:

Index 7:
Index 8:

Index 9:

Index 10:

Index 11:

Index 12:

Index 13:
Index 14: 0
Index 15:

Index 10:

Index 11:

Index 12:

Index 13:

Index 14:

Index 15:

loops 10-15 over and over again. the HEX codes it is recording is as follows:

Index 0: A
Index 1: 20
Index 2: 20
Index 3: A
Index 4: A
Index 5: A
Index 6: A
Index 7: A
Index 8: A
Index 9: A
Index 10: A
Index 11: A
Index 12: A
Index 13: A
Index 14: A
Index 15: A
Index 10: A
Index 11: A
Index 12: A
Index 13: A
Index 14: A
Index 15: A

So it looks like it starts normal with new line feed, space, space, then new line feed forever. Now i am officially lost because i never had a problem reading the scale. I wonder if i'm overloading it with requests?

char receivedChar1[16]={'\0'};
char pWeight[6]={'\0'};
char cWeight[6]={'\0'};
float Weight = 000.0;
int Cycles = 0;
int charindex = 0;
boolean readData = false;
boolean newData = false;
boolean Datasend = false;

void setup()
{
  Serial2.begin(9600, SERIAL_7E1);
  Serial.begin (9600);
}


void loop()
{
  Serial2.write(0x57);
  Serial2.write(0x0D);
  recvOneChar();
 
  //showNewData();  
 delay(500);    
}

void recvOneChar() 
{
 if (Serial2.available() > 0) 
  {
   receivedChar1[charindex] = Serial2.read();
   Serial.print("Index ");
   Serial.print(charindex);
   Serial.print(": ");
   Serial.print(receivedChar1[charindex], HEX);
   Serial.println();
   if (receivedChar1[charindex] == 0x0A){readData = true;}
   if (charindex == 6){receivedChar1[charindex] = '\0';}
   if (receivedChar1[charindex] == 0x03){readData = false; charindex=0;}
   if (readData == true){charindex++; }
  }
}
/*
void showNewData() {
 if (newData == true and strcmp(cWeight, "  0.0")!=0) {
  if (strcmp(cWeight, pWeight)==0){
   Cycles=Cycles+1;
   Datasend = false;
 } else {  
  Datasend = false;
  Cycles = 0;
 }
 if (Cycles ==5)
 { 
  Weight = atof(cWeight);
  newData = false;
}

}
}*/

Try this :

#include <SoftwareSerial.h>

const byte rxPin = 10;
const byte txPin = 11;
const byte CR = 0x0D;
const byte LF = 0x0A;
const byte ETX = 0x03;
char rxChar;
char weightDataChars[17];
float weightDataFloat;
byte charIndex = 0;

enum
{
  WAIT_FOR_START,
  READING_WEIGHT,
  PROCESS_WEIGHT,
  SKIP_TO_NEXT
};
byte currentState = WAIT_FOR_START;

SoftwareSerial rxSS(rxPin, txPin);

void setup()
{
  Serial.begin(115200);
  rxSS.begin(9600);
}

void loop()
{
  switch (currentState)
  {
    case WAIT_FOR_START:
      if (rxSS.available())
      {
        rxChar = rxSS.read();
      }
      if (rxChar == LF)   //start of message
      {
        charIndex = 0;
        currentState = READING_WEIGHT;
      }
      break;
    //===========================================================
    case READING_WEIGHT:
      if (rxSS.available())
      {
        rxChar = rxSS.read();
        if (rxChar == CR)
        {
          currentState = PROCESS_WEIGHT;
        }
        else
        {
          weightDataChars[charIndex] = rxChar;
          charIndex++;
          weightDataChars[charIndex] = '\0';  //terminate the string
        }
      }
      break;
    //===========================================================
    case PROCESS_WEIGHT:
      Serial.print("\nraw weight data :\t\t");
      Serial.println(weightDataChars);
      weightDataChars[6] = '\0';
      Serial.print("weight as a string :\t\t");
      Serial.println(weightDataChars);
      weightDataFloat = atof(weightDataChars);
      Serial.print("weight as a float :\t\t");
      Serial.println(weightDataFloat);
      currentState = SKIP_TO_NEXT;
      break;
    //===========================================================
    case SKIP_TO_NEXT:
      if (rxSS.available())
      {
        rxChar = rxSS.read();
        if (rxChar == ETX)
        {
          charIndex = 0;
          currentState = WAIT_FOR_START;
        }
      }
      break;
  }
}

NOTE 1 : the code uses SoftwareSerial because it has been run on a Nano with only one UART. Change that on your system

NOTE 2 : as I don’t have an Avery scale I generated the serial data using this program

//record layout
//<LF>xxxx.xxuu<CR>
//<LF>hh<CR><ETX>

#include <SoftwareSerial.h>

const byte rxPin = 10;
const byte txPin = 11;

const byte CR = 0x0D;
const byte LF = 0x0A;
const byte ETX = 0x03;

float weightFloat = 123.45;
char tempChars[17];
char weightChars[17];

SoftwareSerial txSS(rxPin, txPin);

void setup()
{
  Serial.begin(115200);
  txSS.begin(9600);
}

void loop()
{
  dtostrf(weightFloat, 6, 2, tempChars);  //convert float to string
  sprintf(weightChars, "%slb", tempChars);  //add the units characters
  txSS.write(LF);
  txSS.write(weightChars);
  txSS.write(CR);
  txSS.write(LF);
  txSS.write("XX");
  txSS.write(ETX);
  delay(200);
  weightFloat += 0.07;  //change the weight
}

IMPORTANT NOTE : the receiving program needs work to make it more robust. An ERROR state should be added that is invoked should unexpected characters or an impossible number of characters be received either when reading the weight data or skipping to the next record.

Thanks for the new code structure. They way you did it makes much more sense. I made some minor changes to get the complete weight and also had to add code to actual trigger the weight request from the scale. The code now reads the scale flawlessly and i think it is storing the data properly. But after all this i am having the same issue. The weight im trying to add to the API call still isnt in the right format for it. I’m going to post the complete code at the bottom but start with the part of the code that is giving me the issue.

         client.print("GET /pushingbox?devid=" + devid
       + "&Weight=" + cWeight
       + "&Store=9048"
       );

      client.println(" HTTP/1.1"); 
      client.print("Host: ");
      client.println(WEBSITE);
      client.println("User-Agent: ESP8266/1.0");
      client.println("Connection: close");
      client.println();
      client.stop();
      client.flush();

Specifically it does like the line where i add the weight to the string.
the following doesnt work:

client.print("GET /pushingbox?devid=" + devid
       + "&Weight=" + cWeight
       + "&Store=9048"
       );

this doesn’t work either:

client.print("GET /pushingbox?devid=" + devid
       + "&Weight=" + weightDataChars
       + "&Store=9048"
       );

Even tried this, but no luck:

client.print("GET /pushingbox?devid=" + devid
       + "&Weight=" + (String) cWeight
       + "&Store=9048"
       );

but when i send it a preset number it works everytime:

client.print("GET /pushingbox?devid=" + devid
       + "&Weight=23.1" 
       + "&Store=9048"
       );

but when i send it a preset number with leading spaces it doesnt work. for example:

client.print("GET /pushingbox?devid=" + devid
       + "&Weight=  23.1" 
       + "&Store=9048"
       );

So im thinking that when i create weightDataChars im keeping some of the leading spaces and thats why that doesnt work. I dont know why sending it cWeight doesnt work. I feel like i need to run some sort of trim function on weightDataChars to clean up any leading blanks. Obviously i googled and the only solution i found was to just run through the char array and copy it back into a new one. But i feel that it is inefficient and am wondering if im missing something else. thanks for your help!

full code:

#include "ESP8266WiFi.h"
#include <Wire.h>
#include <Adafruit_SSD1306.h>
#include <Adafruit_GFX.h>
#define OLED_ADDR   0x3C

Adafruit_SSD1306 display(-1);

#if (SSD1306_LCDHEIGHT != 32)
#error("Height incorrect, please fix Adafruit_SSD1306.h!");
#endif

const byte CR = 0x0D;
const byte LF = 0x0A;
const byte ETX = 0x03;
char rxChar;
char weightDataChars[17];
float cWeight=0; //Current Weight
float pWeight=0; //Previous Weight
float rWeight=0; //Read Weight
//String Weight="";
double Cycles = 0; //Cycles previous weight has == current weight
byte charIndex = 0;

WiFiClient client;  //Instantiate WiFi object

enum
{
  WAIT_FOR_START,
  READING_WEIGHT,
  PROCESS_WEIGHT,
  SKIP_TO_NEXT
};
byte currentState = WAIT_FOR_START;


const char WEBSITE[] = "api.pushingbox.com"; //pushingbox API server
const String devid = "devid"; //device ID from Pushingbox 

const char* MY_SSID = "SSID";
const char* MY_PWD =  "password";



void setup()
{
  display.begin(SSD1306_SWITCHCAPVCC, OLED_ADDR);
  display.clearDisplay();
  display.setTextSize(1);
  display.setTextColor(WHITE);
  display.setCursor(0,0);
  display.print("Screen Ready");
  display.display();
  delay(2000);
  WiFi.begin(MY_SSID, MY_PWD);
  while (WiFi.status() != WL_CONNECTED){delay(1000);}
  
  Serial.begin(9600, SERIAL_7E1);
  Serial.write(0x57);
  Serial.write(0x0D);
}

void loop()
{
    
  switch (currentState)
  {
    case WAIT_FOR_START:
      if (Serial.available())
      {
       rxChar = Serial.read();        
      }
      if (rxChar == LF)   //start of message
      {
        charIndex = 0;
        currentState = READING_WEIGHT;
      }
      break;
    //===========================================================
    case READING_WEIGHT:
      if (Serial.available())
      {
       
        rxChar = Serial.read();
        if (rxChar == CR)
        {
          currentState = PROCESS_WEIGHT;
        }
        else
        {
          
          weightDataChars[charIndex] = rxChar;
          charIndex++;
          weightDataChars[charIndex] = '\0';  //terminate the string
        }
      }
      break;
    //===========================================================
    case PROCESS_WEIGHT:
      weightDataChars[7] = '\0';
      
      rWeight = atof(weightDataChars);
      if (rWeight != 0){
        pWeight =cWeight;
        cWeight = rWeight;
        Cycles++;}else{Cycles=0;}
      
      if (Cycles==20){
        
        
   
   
    //Start or API service using our WiFi Client through PushingBox
    if (client.connect(WEBSITE, 80))
      { 
        display.clearDisplay();
        display.setTextSize(1);
        display.setTextColor(WHITE);
        display.setCursor(0,0);
        display.print("Sending Locked Weight: ");
        display.print(weightDataChars);
        display.display();
         
         client.print("GET /pushingbox?devid=" + devid
       + "&Weight=  23.2" 
       + "&Store=9048"
       );

      client.println(" HTTP/1.1"); 
      client.print("Host: ");
      client.println(WEBSITE);
      client.println("User-Agent: ESP8266/1.0");
      client.println("Connection: close");
      client.println();
      client.stop();
      client.flush();
      
             
       }else{

        display.clearDisplay();
        display.setTextSize(1);
        display.setTextColor(WHITE);
        display.setCursor(0,0);
        display.print("Connection Failed");
        display.display();
        delay(2000);
       }
       
      }
        
      currentState = SKIP_TO_NEXT;
      break;
    //===========================================================
    case SKIP_TO_NEXT:
     if (Serial.available())
      {
        rxChar = Serial.read();
        if (rxChar == ETX)
        {
          charIndex = 0;
          currentState = WAIT_FOR_START;
          Serial.write(0x57);
          Serial.write(0x0D);
        }
      }
      break;
  }

  
}

Specifically it does like the line where i add the weight to the string.

The first thing that I would do is to put the String to be sent in a variable so that you can print it and see what is being sent. Once you know what the String looks like you can tackle any problems that become apparent.

Ok i followed what you said and it wasnt the string being sent to the api but it was some code i had that was flushing and stopping the client. i will post my final code at the bottom incase anyone has my very specific problem. Again thanks for all your help. Hopefully one day i can pay it forward.

#include "ESP8266WiFi.h"
#include <Wire.h>
#include <Adafruit_SSD1306.h>
#include <Adafruit_GFX.h>
#define OLED_ADDR   0x3C

Adafruit_SSD1306 display(-1);

#if (SSD1306_LCDHEIGHT != 32)
#error("Height incorrect, please fix Adafruit_SSD1306.h!");
#endif

const byte CR = 0x0D;
const byte LF = 0x0A;
const byte ETX = 0x03;
char rxChar;
char weightDataChars[17];
char weightNoBlanks[7];
String apiString;
float cWeight=0; //Current Weight
float pWeight=0; //Previous Weight
float rWeight=0; //Read Weight
String Store="9048";
double Cycles = 0; //Cycles previous weight has == current weight
byte charIndex = 0;
byte nbIndex =0;

WiFiClient client;  //Instantiate WiFi object

enum
{
  WAIT_FOR_START,
  READING_WEIGHT,
  PROCESS_WEIGHT,
  SKIP_TO_NEXT
};
byte currentState = WAIT_FOR_START;


const char WEBSITE[] = "api.pushingbox.com"; //pushingbox API server
const String devid = "devid"; //device ID from Pushingbox 

const char* MY_SSID = "SSID";
const char* MY_PWD =  "Password";



void setup()
{
  display.begin(SSD1306_SWITCHCAPVCC, OLED_ADDR);
  display.clearDisplay();
  display.setTextSize(1);
  display.setTextColor(WHITE);
  display.setCursor(0,0);
  display.print("Screen Ready");
  display.display();
  delay(2000);
  WiFi.begin(MY_SSID, MY_PWD);
  while (WiFi.status() != WL_CONNECTED){delay(1000);}
  
  Serial.begin(9600, SERIAL_7E1);
  Serial.write(0x57);
  Serial.write(0x0D);
}

void loop()
{
    
  switch (currentState)
  {
    case WAIT_FOR_START:
      if (Serial.available())
      {
       rxChar = Serial.read();        
      }
      if (rxChar == LF)   //start of message
      {
        charIndex = 0;
        nbIndex =0;
        currentState = READING_WEIGHT;
      }
      break;
    //===========================================================
    case READING_WEIGHT:
      if (Serial.available())
      {
       
        rxChar = Serial.read();
        if (rxChar == CR)
        {
          currentState = PROCESS_WEIGHT;
        }
        else
        {
          
          weightDataChars[charIndex] = rxChar;
          if (weightDataChars[charIndex]!=' '){
            weightNoBlanks[nbIndex]=weightDataChars[charIndex];
            nbIndex++;
            weightNoBlanks[nbIndex] = '\0';
          }
          charIndex++;
          weightDataChars[charIndex] = '\0';  //terminate the string
        }
      }
      break;
    //===========================================================
    case PROCESS_WEIGHT:
      weightDataChars[7] = '\0';
      
      rWeight = atof(weightDataChars);
      if (rWeight != 0){
        pWeight =cWeight;
        cWeight = rWeight;
        Cycles++;}else{Cycles=0;}
      
      if (Cycles==20){
        
        
   
   
    //Start or API service using our WiFi Client through PushingBox
    if (client.connect(WEBSITE, 80))
      { 
        apiString = "GET /pushingbox?devid="+devid+"&Weight=" + weightNoBlanks + "&Store="+ Store;
       
        client.print(apiString);
        client.println(" HTTP/1.1"); 
        client.print("Host: ");
        client.println(WEBSITE);
        client.println("User-Agent: ESP8266/1.0");
        client.println("Connection: close");
        client.println();
        display.clearDisplay();
        display.setTextSize(1);
        display.setTextColor(WHITE);
        display.setCursor(0,0);
        display.print(apiString);
        display.display();
        delay(2000);
             
       }else{

        display.clearDisplay();
        display.setTextSize(1);
        display.setTextColor(WHITE);
        display.setCursor(0,0);
        display.print("Connection Failed");
        display.display();
        delay(2000);
       }
       
      }
        
      currentState = SKIP_TO_NEXT;
      break;
    //===========================================================
    case SKIP_TO_NEXT:
     if (Serial.available())
      {
        rxChar = Serial.read();
        if (rxChar == ETX)
        {
          charIndex = 0;
          nbIndex =0;
          weightDataChars[0]='0';
          weightNoBlanks[0]='0';
          currentState = WAIT_FOR_START;
          Serial.write(0x57);
          Serial.write(0x0D);
        }
      }
      break;
  }

  
}

I am glad that you got it working and I hope that you learned some techniques that will be useful in future projects. State machines using switch/case and an enum can be used for a surprising number of projects but are, of course, not applicable to all situations.