These are chat archives for esp8266/Arduino

2nd
Sep 2018
Develo
@devyte
Sep 02 2018 01:13
I'd do something like this as a first attempt:
std::vector<uint8> buff;
while(serverClients[I].available())
{
   uint8 c = serverClients[i].read();
   buff.push_back(c);
   Serial.write(c);
}
...
//do something with buff
...
//buff goes out of scope so gets destroyed
...
den har
@denman0000_gitlab
Sep 02 2018 01:14
@devyte thank you , I see that will place it in a uint8 format
This message was deleted
This message was deleted
den har
@denman0000_gitlab
Sep 02 2018 01:19
This message was deleted
@devyte
from there can i use sscanf like this
char allDroid[18] = {'\0' }; //total array count including NULL's
sscanf(allDroid, "%s,%s,%s,%s", &hDroid1, &pDroid1, &ooDroid1, &devDroid1);
This message was deleted
@devyte
if data received from cleint is
1234,12,123,999
den har
@denman0000_gitlab
Sep 02 2018 01:28
This message was deleted
den har
@denman0000_gitlab
Sep 02 2018 02:34

@devyte

I'd do something like this as a first attempt:

std::vector<uint8> buff;
while(serverClients[I].available())
{
   uint8 c = serverClients[i].read();
   buff.push_back(c);
   Serial.write(c);
}
...
//do something with buff
...
//buff goes out of scope so gets destroyed
...

This works but still in unint8 :-( and how do I do something similar to client.readStringUntil('\r'); ??

Develo
@devyte
Sep 02 2018 02:42
Check c after writing to serial. If (c == '\r') break; or return; or whatever depending on your intent.
den har
@denman0000_gitlab
Sep 02 2018 02:46
@devyte
from there can i use sscanf like this
char allDroid[18] = {'\0' }; //total array count including NULL's
sscanf(allDroid, "%s,%s,%s,%s", &hDroid1, &pDroid1, &ooDroid1, &devDroid1);
Develo
@devyte
Sep 02 2018 02:47
I'm just guessing off the top of my head here, my own usage doesn't go along these lines, but one thing to beware is depending on a char in the incoming byte stream to finish. If that key char somehow never arrives, you'll have trouble. I personally don't like the readStringUntil() concept as it is implemented. In addition to depending on one key char to "finish reading", the amount of data accumulated is not really under your control, so a malformed incoming byte stream could make your app crash.
But that's just me and my paranoia :p
den har
@denman0000_gitlab
Sep 02 2018 02:49
@devyte I agree.... so apart from \r check what else would you suggest I add in ?
Develo
@devyte
Sep 02 2018 02:51
I'd check for a max number of bytes read, after which if I haven't received the key char, I'd say "screw you stream, I'm dropping you"
den har
@denman0000_gitlab
Sep 02 2018 02:52
@devyte I m so close to completion now
Develo
@devyte
Sep 02 2018 02:52
So close that connection due to protocol error
den har
@denman0000_gitlab
Sep 02 2018 02:52
aha
@devyte but how do i count the bytes .. do you possibly have an example for me please ?
Develo
@devyte
Sep 02 2018 02:54
come on, you're iterating on each byte read! just count the iterations! ++bytecount; or something
just don't forget to declare the counter inside the scope of that particular client. Same for the vector. That's to make sure they get a clean init for each client. Scope is your friend!
den har
@denman0000_gitlab
Sep 02 2018 02:59

@devyte and then last question which would probably solve this who dilemma and the mysery so far ..
I was assembling the packed on the sender die like this :

//declare vars for send
char hDroid[5] = {
    "1234" }; //4 or less digits/keys eg 1234 + NULL
char pDroid[3] = {
    "21" }; //2 digits/keys eg 12 + NULL
char ooDroid[4] = {
    "123" }; //3 or less digits/keys eg 123 + NULL
char devDroid[5] = {
    "1234" }; //4 or less digits/keys eg 9999 + NULL 
char allDroid[18] = {
    '\0' }; //total array count including NULL's

sprintf(allDroid, "%s,%s,%s,%s", hDroid, pDroid, ooDroid, devDroid);
    Serial.println("This is allDroid "); //show content of allDroid 
    Serial.println(allDroid); //show content of allDroid

Do i need to set client as uint8 as well or is it fine as is there since receive side now comes out as you kindly showed as uint8 ? Or is there a quick way to bring the received in a Char array so I can use SSCANF like here :

 sscanf(allDroid, "%s,%s,%s,%s", &hDroid1, &pDroid1, &ooDroid1, &devDroid1); 

    Serial.println("this is hDroid1,pDroid1,ooDroid1,devDroid1 "); //show content of allDroid

    Serial.println(hDroid1);

    Serial.println(pDroid1);

    Serial.println(ooDroid1);

    Serial.println(devDroid1);

@devyte

come on, you're iterating on each byte read! just count the iterations! ++bytecount; or something
the counter loop I can figure out
but not being a C++ coder I have ZERO idea of what this means >>>
just don't forget to declare the counter inside the scope of that particular client. Same for the vector. That's to make sure they get a clean init for each client. Scope is your friend!

@devyte It's taken 10 x 18 or more hour days just to get a 'working'TCP client /server going
den har
@denman0000_gitlab
Sep 02 2018 03:04
@devyte I just wanted the simplest smallest reliable TCP server so I can receive some data and compare it
@devyte > come on, you're iterating on each byte read! just count the iterations! ++bytecount; or something
ITERATING where ? It's not in the WiFiTelnetToSerial example ocde .. is it in the library in the read function ?
Develo
@devyte
Sep 02 2018 03:22
The code I posted avove, the while(available) loop, you're iterating over the bytes read
Depends on your paranoia level. If you're sure you'll always receive a string, I.e. alphanumeric chars, then you can use String or std::string instead of a vector of uint8. Me, I'm paranoid, so I'd use the vector and then check the contents, or check the byte c on the fly for alphanumeric values before accepting it
den har
@denman0000_gitlab
Sep 02 2018 03:28
@devyte Awesome re While available loop :-) thank you will count the bytes
@devyte yes always will receive a string
@devyte So that last question : Do i need to set client as uint8 as well or is it fine as is there since receive side now comes out as you kindly showed as uint8 ? Or is there a quick way to bring the received in a Char array so I can use SSCANF like here :
Develo
@devyte
Sep 02 2018 06:38
I'm not sure how to answer that. If you use a String instead of a std::vector, then you can parse its contents directly, including sscanf
den har
@denman0000_gitlab
Sep 02 2018 12:05

@devyte

I'm not sure how to answer that. If you use a String instead of a std::vector, then you can parse its contents directly, including sscanf
Please indicate what needs to be changed in this code stub you sent me to make it a String/Char :

std::vector<uint8> buff;
while(serverClients[I].available())
{
   uint8 c = serverClients[i].read();
   buff.push_back(c);
   Serial.write(c);
}
...
//do something with buff
...
//buff goes out of scope so gets destroyed
...
den har
@denman0000_gitlab
Sep 02 2018 23:57
@devyte How are you ?