These are chat archives for esp8266/Arduino

3rd
Jun 2016
Clemens Kirchgatterer
@everslick
Jun 03 2016 07:55
so i have now isolated this minimum websocket sketch. when i send JSON data of 2930 bytes, it works. when i send 2931 bytes the browser receives garbage. :-D
looks a little bit like if (date length ~ < 2 * MTU) { okish }
Me No Dev
@me-no-dev
Jun 03 2016 08:31
that is so because that is the maximum size usually for the first outgoing window
in order for it to send larger packets, you need to split them into MTU chunks and send when it's possible
there is a bit more to that if you want to get the transmission as a single message on the other end
Clemens Kirchgatterer
@everslick
Jun 03 2016 08:54
i have hoped, that arduinoWebSockets would do this for me :-(
Me No Dev
@me-no-dev
Jun 03 2016 08:56
well large data on the ESP has always been a problem, because you do not have infinite ram
everything is doable though ;)
unfortunatelly Links have not exposed the required method for you to contruct the data
I'll look in a minute what I have exposed in my lib and show you how you can do it with that
Clemens Kirchgatterer
@everslick
Jun 03 2016 09:02
i have opend an issue on github: Links2004/arduinoWebSockets#85
yes, i know about that upper limits, but as long as ram is available... didn't expect to things bailing out at 3KB
arduinoWebSockets apparently supports your async TCP lib, but last time i tried that it didn't help
Me No Dev
@me-no-dev
Jun 03 2016 09:06
i was not talking about the async tcp lib but the async web server
which has web sockets also
limitation is ok, you just need to think different about it and it can be done
Clemens Kirchgatterer
@everslick
Jun 03 2016 09:17
async web server?
Me No Dev
@me-no-dev
Jun 03 2016 09:18
yes
this one?
Me No Dev
@me-no-dev
Jun 03 2016 09:18
yes
Clemens Kirchgatterer
@everslick
Jun 03 2016 09:19
checking it out
Me No Dev
@me-no-dev
Jun 03 2016 09:20
there isn't currently an example of how to send large data messages but I can help
Clemens Kirchgatterer
@everslick
Jun 03 2016 09:27
thats nice. thank you!
i currently look at the API,
i see AsyncResponseStream *response = ... i guess response handles its internal buffer with something like String. correct?
Me No Dev
@me-no-dev
Jun 03 2016 09:28
this is not for the web socket though
the AsyncResponseStream just exposes a Print interface so you can print, println and printf to the output
Clemens Kirchgatterer
@everslick
Jun 03 2016 09:29
yes, but if i will swtch to async tcp i will have to migrate my current framework over to it completely.
Me No Dev
@me-no-dev
Jun 03 2016 09:29
yes
this is my current http implementation, will it be much work to port over to async webserver? what do you think?
Me No Dev
@me-no-dev
Jun 03 2016 09:31
it will be actually pretty easy
Clemens Kirchgatterer
@everslick
Jun 03 2016 09:32
then i could get rid of the extra websockets lib as well
Me No Dev
@me-no-dev
Jun 03 2016 09:33
pick a callback and I'll translate it to async for you so you can see how it will go
:-D
Me No Dev
@me-no-dev
Jun 03 2016 09:33
API is mostly the same, but you do need to carry the request you are answering to instead of calling the server methods
static void handle_info_cb(AsyncWebServerRequest *request) {
#ifndef RELEASE
  String webpage;

  if (!setup_complete()) return;
  if (!authenticated()) return;

  if (!webpage.reserve(4*1024)) {
    log_print(F("HTTP: failed to allocate memory\n"));
  }

  html_insert_page_header(webpage);
  html_insert_page_body(webpage);
  html_insert_page_menu(webpage);
  html_insert_info_content(webpage);
  html_insert_page_footer(webpage);

  request->send(200, "text/html", webpage);
  system_count_net_traffic(webpage.length());
#endif
}
:D that was too easy
Clemens Kirchgatterer
@everslick
Jun 03 2016 09:38
htat is because of my great software design!!! ;-)
Me No Dev
@me-no-dev
Jun 03 2016 09:39
static bool authenticated(AsyncWebServerRequest *request) {
  String header;

  if (request->hasHeader("Cookie")){
    String cookie = request->header("Cookie");
    String name = "GENESYS_SESSION_KEY=";

    if (cookie.indexOf(name + session_key) != -1) {
      return (true);
    }
  }

  AsyncWebServerResponse *response = request->beginResponse(301); 
  response->addHeader("Location","/login");
  response->addHeader("Cache-Control"," no-cache");
  request->send(response);
  system_count_net_traffic(header.length());

  return (false);
}
Clemens Kirchgatterer
@everslick
Jun 03 2016 09:40
ahh for auth
Me No Dev
@me-no-dev
Jun 03 2016 09:40
here is a more interesting example (need to change the call to authernticated in handle_info_cb
Clemens Kirchgatterer
@everslick
Jun 03 2016 09:41
IC
looks straight forward
OTA could be different i guess though?
Me No Dev
@me-no-dev
Jun 03 2016 09:42
the biggest doifference is that you are always working with the current request in the callback as opposed to with the server
the regular web server is blocking, so you are always responding only to one client
in async you can be responding to 5 clients at the same time
Clemens Kirchgatterer
@everslick
Jun 03 2016 09:43
indeed, only limited by free ram i guess
Me No Dev
@me-no-dev
Jun 03 2016 09:55
ram and lwip setting
Clemens Kirchgatterer
@everslick
Jun 03 2016 10:40
AsyncWebServerResponse does it have something like length() ?
so i know how much bytes it sent?
many
Me No Dev
@me-no-dev
Jun 03 2016 10:46
depends on the response
but why? don't you know how much you sent?
Clemens Kirchgatterer
@everslick
Jun 03 2016 11:31
not really. look at the last function call in the 2 mothods you ported for me
in the first it was easy
but the second is complicated
its no deal breaker, but ... i'd prefer to have an API for it in the network stack anyway. this system_count_net_traffic() is a workaround, because there is no byte count in the LWIP for an PHY
Me No Dev
@me-no-dev
Jun 03 2016 11:39
oh, you want to count all bytes?
then you need to go inside lwip for that
else you are missing most of the actual bytes that go through the phy
also the response is something that is managed in the background once you "send" it
it's queued for data when possible and freed on completion
Clemens Kirchgatterer
@everslick
Jun 03 2016 11:45
yes, i know, it is a crude way, but LWIP does only count packets and not bytes AFAIK
there is a stats API, but i couldn't figure out how i could get to the bytes sent
maybe i could use that linker trick to wrap send and receive in my own send and receive functions, once i figure out, whick one i have to wrap
Me No Dev
@me-no-dev
Jun 03 2016 11:47
that would be the best way
Clemens Kirchgatterer
@everslick
Jun 03 2016 11:48
i did this with malloc/free... to keep track of heap
Me No Dev
@me-no-dev
Jun 03 2016 11:48
for malloc/free you have the source in the core compiled so no need for wrapping ;)
core/umm_malloc/*
Clemens Kirchgatterer
@everslick
Jun 03 2016 11:49
this would suck, because i would have to change each time i pull the newest versions
and everybody else who wants to use genesys as a boilerplate firmware
the wrapper works without any changes to the core
Me No Dev
@me-no-dev
Jun 03 2016 11:50
only to the build process
so not usable through the IDE
Clemens Kirchgatterer
@everslick
Jun 03 2016 11:52
that's true, but i can't stand the arduino IDE in the first place
:-)
Ivan Grokhotkov
@igrr
Jun 03 2016 14:36
🤔