These are chat archives for esp8266/Arduino

27th
Aug 2018
den har
@denman0000_gitlab
Aug 27 2018 01:08
Could someone please explain this ???
We replaced WiFiServer server(80);
with
ESP8266WebServer server(80);
Soooo
class ESP8266WebServer' has no member named 'available'
WiFiClient client = server.available();
and some examples use this ESP8266WebServer server(80); and some use WiFiServer server(80); and ehrn including libraries from the arduino IDE both of these get added #include <ESP8266WebServer.h>

include <ESP8266WebServerSecure.h>

not only that ..some examples have this : WiFiServer server(80);
is there some consistency for both client and server as results vary as do the behaviors across ESP12F and NODEMCU 1.0 and ESP8266EX (sonoff) ?
den har
@denman0000_gitlab
Aug 27 2018 01:19
and of course with reference to this page example and walk-through
so in order to progress and future proof a solution .. what path should we follow in terms of the code and versions and libraries ?
which examples are correct and work correctly ?
den har
@denman0000_gitlab
Aug 27 2018 01:27
I would really appreciate some help with this
Develo
@devyte
Aug 27 2018 05:35
Oh boy
WiFiClient is a TCP socket. You send bytes over it.
ESP8266WebServer is for serving http, as in hypertext. It is implemented over WiFiClient, as in it uses WiFiClient under the hood to for http sending and receiving. Of course it doesn't have available(), you're not supposed to know about individual bytes at that level.
There are some (early) examples that show how you could implement a simplified webserver using WiFiClient, hence the (80), but implementing http yourself is NOT advised, because the protocol has a long list of caveats.
Develo
@devyte
Aug 27 2018 05:44
The examples are meant to show how something is used. Therefore there are examples for the lower level TCP socket aka WiFiClient, and for the higher level ESP8266WebServer
den har
@denman0000_gitlab
Aug 27 2018 09:59
@devyte How are you ? Thank you for the reply .. I am trying to use the 'leanest' TCP method to TX./RX tiny amount of data (+-30 bytes or less) , a single point to multipoint (one sender multiple receivers) , a master with multiple slaves .... In order to make this work I need the master to act as a client and all the slaves act as a server ... hence the reason for the questions I recently posted here .. they revolve around using the WiFiClient and either ESP8266WebServer or WiFiServer. Could you possibly suggest what to use to get this working ?
den har
@denman0000_gitlab
Aug 27 2018 10:14

I am running this from the WiFi client
sprintf(allDroid, "%s,%s,%s,%s", hDroid, pDroid, ooDroid, devDroid);
and need to do this one the Server side :
sscanf(allDroid, "%s,%s,%s,%s", &hDroid1, &pDroid1, &ooDroid1, &devDroid1);

NOTE all variables are char Arrays for example :
char allDroid[18]

* I seem to have an issure on the server side .. Should I be using client.read (which seems slightly different to arduino serial.read) or is there something simimlar to clientReadStringuntil ?

Bert Melis
@bertmelis
Aug 27 2018 15:44
Hi all
Someone I'm giving support to can't snprintf. It just outputs the format instead of the formatted number. Does anyone have a clue what's causing this?
so snprintf(str, sizeof(str), "%.1f", value); puts "%.1f" in str and not 26.1
Bert Melis
@bertmelis
Aug 27 2018 15:49
we're both using a Wemos D1 mini and the same sketch. Difference though is that I'm using VSCode/Pio and he's using Arduino IDE.
Bert Melis
@bertmelis
Aug 27 2018 16:33
ah, wait. it's by design according the existing issues. I'll use the String workaround then: printf("%s", String(value,1).c_str());
david gauchard
@d-a-v
Aug 27 2018 17:12
You can enable or not floats in printf using board generator (option --nofloat). Maybe VScode is not using the same options as arduino IDE (-u _printf_float -u _scanf_float in compiler cmdline, check platform.txt)
den har
@denman0000_gitlab
Aug 27 2018 17:15
@bertmelis Hello Bert ... is snprintf very different to sprintf ? Would love to know ... sorry to drop in on your question .. it's just I'm really battling with char * and array and sscanf .. is there something similar to sscanf ?/
Bert Melis
@bertmelis
Aug 27 2018 17:16
snprintf has an extra parameters to indicate the length so you won't write past the end of the char array
den har
@denman0000_gitlab
Aug 27 2018 17:17
@bertmelis aaaah awesome .. will give it a shot .. not sure if you saw my earlier post here .. been battling for a week just to get it right
@bertmelis and thanky you kindly for replying now
Bert Melis
@bertmelis
Aug 27 2018 17:34
earlier post? about sscanf? I've never used it but it is the other way around as sprintf.
den har
@denman0000_gitlab
Aug 27 2018 17:55

@bertmelis I am running this from the WiFi client
sprintf(allDroid, "%s,%s,%s,%s", hDroid, pDroid, ooDroid, devDroid);
and need to do this one the Server side :
sscanf(allDroid, "%s,%s,%s,%s", &hDroid1, &pDroid1, &ooDroid1, &devDroid1);

NOTE all variables are char Arrays for example :
char allDroid[18]

* I seem to have an issure on the server side .. Should I be using client.read (which seems slightly different to arduino serial.read) or is there something simimlar to clientReadStringuntil ?

@bertmelis and using a very simple tcp webserver and client
@bertmelis just can seem to get the conversion right on server side :-(
Bert Melis
@bertmelis
Aug 27 2018 18:15
  1. make sure all separate char arrays and formatting characters fit in allDroid
  1. don't forget the null-terminator
den har
@denman0000_gitlab
Aug 27 2018 18:16
@bertmelis both done
check and double checked
the code works fine on its own in arduino
and also on the ESP8266
Bert Melis
@bertmelis
Aug 27 2018 18:17
so what's not working?
den har
@denman0000_gitlab
Aug 27 2018 18:17
@bertmelis .. would you prepared to give it a try for me ?
the receive side
aka server
Bert Melis
@bertmelis
Aug 27 2018 18:18
never worked with sscanf. and I've only worked with async server of websockets.
but server behzves like normal serial
maybe afd a known terminator character
den har
@denman0000_gitlab
Aug 27 2018 18:19
@bertmelis thats perfect actauuly .. i'm using async tcp websocket
Bert Melis
@bertmelis
Aug 27 2018 18:21
for example, add "+" to your allDroid char array. the read untill the character "+" appears and they you know the complete message is received
den har
@denman0000_gitlab
Aug 27 2018 18:22

@bertmelis
`
//declare "code-holding" 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

//declare "code-holding" vars for receive
char hDroid1[5] = {
'\0' }; //4 or less digits/keys eg 1234 + NULL
char pDroid1[3] = {
'\0' }; //2 digits/keys eg 12 + NULL
char ooDroid1[4] = {
'\0' }; //3 or less digits/keys eg 123 + NULL
char devDroid1[5] = {
'\0' }; //4 or less digits/keys eg 9999 + NULL

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

void loop() {
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
delay(1000);
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);

//clear the arrays
memset(allDroid, 0, sizeof(allDroid));// This line is for reset the StringReceived
memset(hDroid1, 0, sizeof(hDroid1));// This line is for reset the StringReceived
memset(pDroid1, 0, sizeof(pDroid1));// This line is for reset the StringReceived
memset(ooDroid1, 0, sizeof(ooDroid1));// This line is for reset the StringReceived
memset(devDroid1, 0, sizeof(devDroid1));// This line is for reset the StringReceived

}
`

Bert Melis
@bertmelis
Aug 27 2018 18:22
Autocorrect is not helping...
den har
@denman0000_gitlab
Aug 27 2018 18:22
i know the markdown and numbering is not forgiving here :-(
@bertmelis in the above code i have put both (client side- sender) and server side (receiver) in one set for testing
Bert Melis
@bertmelis
Aug 27 2018 18:23
so what's not working? Serial output?
den har
@denman0000_gitlab
Aug 27 2018 18:25
@bertmelis the send to server works great but i cant seem to get the sscanf side conversion right ( maybe wrong conversion ??)
@bertmelis one side is running webclient(TX) .. the other running webserver (RX)
did
den har
@denman0000_gitlab
Aug 27 2018 18:27
i totally understand scanf
as well as sprintf
@bertmelis if you possibly get a chance i would greatly appreciate if you tried this and fed back to me ...
@bertmelis and if you can't I understand .. but feel free to stay in touch as perhaps myself and my hobby friend in Aus can help you with stuff too .. or chat etc
Bert Melis
@bertmelis
Aug 27 2018 18:30
Let me try. But give me some time...
never used sscanf before
den har
@denman0000_gitlab
Aug 27 2018 18:30
@bertmelis Thank YOU Kindly ...

@bertmelis and this is where the problem is specifically :

 ```

WiFiClient client = wifiServer.available();

if (client) {

while (client.connected()) {

  while (client.available()>0) {
    char c = client.read();
    Serial.write(c);
  }

  delay(10);
}

client.stop();
 ```
Bert Melis
@bertmelis
Aug 27 2018 18:36
meanwhile, please read this: http://www.gammon.com.au/serial
den har
@denman0000_gitlab
Aug 27 2018 18:38
Thats an excellent resource indeed and always has been
the issue I have is that this code works fine on arduino and NRF etc
but I not if I just replace the char c line in code above
@bertmelis and been balling with it for days
@bertmelis oh and by the way if i can help you with your problem or test in return will happily do it
@bertmelis i'm trying to establish whether or nit its the webClient is or me ..increasing ini insanity :-(
@bertmelis so crying out for help as a sanity check
den har
@denman0000_gitlab
Aug 27 2018 19:06
@bertmelis and please accept my apology for the barrage of info at once