Sending Data from a Structure to Firebase

(post deleted by author)

as a general rule:
post always your complete sketches

The probalitiy that the bug is somewhere else than you are assuming is twice as high as in the code-snippet you are looking at.

So post your complete arduino-sketch
and
post your complete ESP-01-sketch

As you have an ESP8266-01 connected to an arduino you also have to post a schematic how the ESP-01 is connected to your Arduino.

By the way: things will become much much easier if you use a ESP8266 nodeMCU or a ESP32-nodeMCU for both:
receiving the data from your 433 MHz receiver and sending the data over WiFi

The nodeMCU-board can do all the things your arduino is doing.

best regards Stefan

1 Like

since you're sending data as a comma separate string, on approach is to use strtok() to break the string into substrings and translate each substring into a value

following contains a generic routine, tokenize() that can easily be modified to translate each substring into a float. (doesn't matter if this fails on the first sub-string).

once tokenized, it would be easy to do a strcmp() on the first token, "NodeBB" or "NodeDD" to identify the contents

char s [80];

// -----------------------------------------------------------------------------
#define MaxTok  10
char *toks [MaxTok];
int   vals [MaxTok];

int
tokenize (
    char       *s,
    const char *sep )
{
    unsigned n = 0;
    toks [n] = strtok (s, sep);
    vals [n] = atoi (toks [n]);

    for (n = 1; (toks [n] = strtok (NULL, sep)); n++)
        vals [n] = atoi (toks [n]);

    return n;
}

// -----------------------------------------------------------------------------
void dispToks (
    char * toks [])
{
    char s [40];
    for (unsigned n = 0; toks [n]; n++)  {
        sprintf (s, " %6d  %s", vals [n], toks [n]);
        Serial.println (s);
    }
}

// -----------------------------------------------------------------------------
void loop ()
{
    if (Serial.available ())  {
        int n = Serial. readBytesUntil ('\n', s, sizeof(s)-1);
        s [n] = 0;      // terminate string

        tokenize (s, ",");
        dispToks (toks);
    }
}

// -----------------------------------------------------------------------------
void setup ()
{
    Serial.begin (9600);
}
1 Like

Where should I implement this? I just posted the full codes for my arduino and esp. Thank you so much for this tip!

without quoting the post your answer is related to your writing

"Where should I implement this?" stays completely unclear.

Does "this" mean implement using a nodeMCU? Or does it mean implement
strok()?

Does you second sentence writing "Thank you so much for this tip!" mean
Thank you for the tip with nodeMCU
or
does it mean thank you for the tip with stok()?

You are working on an informatic project ans what is really needed most in an informaic project is precise information.

where you recognize the '\n'.

you would pass a c-string to tokenize and operate on the "vals[]".

but you're reading the received chars into a "String" instead of a c-string (char array).

instead of just reading 1 char at a time with Serial.read(), you could use Serial.readBytesUntil('\n', charBuf, sizeof(charBuf)-1) (charBuf[] needs to be defined instead of values)

1 Like

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.