These are chat archives for esp8266/Arduino

16th
Jun 2016
Ivan Grokhotkov
@igrr
Jun 16 2016 00:45
Actually, just rounding the size is not what he needs.
The correct formula is result=(pos+16)&15
Because there is a checksum byte added at the end
Just rounding the sketch size up to 16 bytes will not give a correct result when pos is already 16 bytes aligned, I.e. you need to take checksum byte into account.
P.s. I can send you a sketch which is 16 bytes larger than get sketch size 😉
Martin Ayotte
@martinayotte
Jun 16 2016 02:13
BTW, I don't know about all underlying stuff, but if getsketchsize() isn't able to keep track of the real size, why not padding empty words with some signature such 0xAAAAAAAA that getsketchsize() will be able adjust itself to real value ?
Ivan Grokhotkov
@igrr
Jun 16 2016 02:18
It's not that it can't track the real size... it's just a bug and the fix is basically one extra line which i have posted above.
sticilface
@sticilface
Jun 16 2016 06:01
A checksum now it makes sense. Thanks. I'll adjust, test accordingly and amend the pull request.
Ivan Grokhotkov
@igrr
Jun 16 2016 06:08
I'm on it already :)
wait a bit please...
Ivan Grokhotkov
@igrr
Jun 16 2016 06:29
actually, if you don't want to be bothered with flashRead and getting all alignments right, you can simply use memcpy_P to copy stuff from flash to RAM
it will be a bit slower (around 35% slower), but not a deal breaker.
turned out, writing a test case for getSketchSize and getSketchMD5 is not exactly trivial...
Me No Dev
@me-no-dev
Jun 16 2016 07:01
:D
how long does it take to calculate the md5?
Ivan Grokhotkov
@igrr
Jun 16 2016 07:02
~100ms with flashRead, ~135ms with memcpy_P
that is for a 230k sized sketch
flash read methods are blocking, so you can not actually do calculations while you wait for data to be pulled from flash.
but meh, it's caching result anyway, so it's just 100ms once, not a big deal
Me No Dev
@me-no-dev
Jun 16 2016 07:05
maybe not a bad idea to use the code to check the md5 of the new uploaded sketch (instead of checking what came through the network)
currently we do not know if the sketch was written properly
Ivan Grokhotkov
@igrr
Jun 16 2016 07:08
yeah, possible entirely, just read stuff back in UpdaterClass::_writeBuffer...
Ivan Grokhotkov
@igrr
Jun 16 2016 08:18
i have no idea how to test this though
i.e. how to simulate a case when flash is not written correctly
Me No Dev
@me-no-dev
Jun 16 2016 08:19
pick a random address and write something else to it?
how are you testing the flashing now?
write to a file?
Ivan Grokhotkov
@igrr
Jun 16 2016 08:20
no i mean i wanted to write a test case for this feature — checking that md5 catches bad flash writes
we don't have one at the moment, so would be good to add it
Me No Dev
@me-no-dev
Jun 16 2016 08:21
since it's a test, it does not involve a real ESP right?
Ivan Grokhotkov
@igrr
Jun 16 2016 08:21
it does
Me No Dev
@me-no-dev
Jun 16 2016 08:22
hmm... then...
Ivan Grokhotkov
@igrr
Jun 16 2016 08:22
i think i'm going to take my FPGA board and create a flash chip emulator with a "bad block"
should be fun
Me No Dev
@me-no-dev
Jun 16 2016 08:22
:D
so if you OTA a sketch, the md5 is once checked for the incomming data
if you write some random stuff to a random place after that
the following md5 will fail
that only if md5 is checked once the new sketch is written to the flash and not while writing it
or am I getting the totally werong idea of how tests work
Ivan Grokhotkov
@igrr
Jun 16 2016 08:26
actually i added flash read back thingie into the Updater, so MD5 is calculated by Updater based on data read from flash.
esp8266/Arduino@0c58dc1
Me No Dev
@me-no-dev
Jun 16 2016 08:27
why not use both and know which one failed?
I mean network or write
Ivan Grokhotkov
@igrr
Jun 16 2016 08:27
does it matter?
like, does it matter which one failed?
Me No Dev
@me-no-dev
Jun 16 2016 08:27
it could... but more for debugging
if you get fails, you will need to add it so you can figure out where to look for issues
it can hint on failing flash blocks also
Ivan Grokhotkov
@igrr
Jun 16 2016 08:31
yeah, that can be done basically by comparing the contents of _buffer written and read in _writeBuffer, that will give you info on exact location in flash where this happens
Me No Dev
@me-no-dev
Jun 16 2016 08:31
maybe even retry write?
Ivan Grokhotkov
@igrr
Jun 16 2016 08:33
if the flash is borked i wouldn't like software to sweep the issue under the rug by doing some retries.
just fail hard and fast
Me No Dev
@me-no-dev
Jun 16 2016 08:33
is that the only reason why write would fail?
Ivan Grokhotkov
@igrr
Jun 16 2016 08:34
It may also fail due to EMI or bad power supply, but those issues should, IMO, be made as obvious as possible.
Me No Dev
@me-no-dev
Jun 16 2016 08:36
ok, hard fail it is :)
Mehrdad K
@mkeyno
Jun 16 2016 10:24
hi every one , so sorry for any interrupt, can anyone tell how to catch ip address of client connected to webserver in AP and Station mode ,? is following code correct
ESP8266WebServer server(80);

void handleRoot() {
  Serial.print("this request if from=");Serial.println(server.client().remoteIP());

  server.send(200, "text/html", "<h1>You are connected to slave node</h1>");
}
Hagai Shatz
@hagai-shatz
Jun 16 2016 10:53
@everslick and @me-no-dev, why do we have to send 'Content-Disposition: inline; filename='...' with every file that we serve? This is an overhead TMOH and also expose the actual file location in the file system. Sorry I was not following the full discussion on it, but as far as I can read this is not HTTP standard and has some security risks: stackoverflow
Me No Dev
@me-no-dev
Jun 16 2016 10:56
@hagai-shatz so it was better before?
@mkeyno if(server.client().localIP() != WiFi. localIP()){ server.send(200, "text/html", "<h1>You are connected to my AP</h1>"); }
Hagai Shatz
@hagai-shatz
Jun 16 2016 11:00
I'm not sure... I think it is good to add Content-Disposition: attachment; filename='...' to force download, but I think it is better to only provide the file name without the path.
@everslick what is the case to add 'inline'? Maybe it is only relevant to some file types?
This message was deleted
Me No Dev
@me-no-dev
Jun 16 2016 11:03
yeah, but... in case where AP is off and STA is in the same subnet as AP it will false positive
best to check against STA IP
Mehrdad K
@mkeyno
Jun 16 2016 11:05
thanks dear @me-no-dev and sorry @hagai-shatz for crossing , but who has the client.IP registration? is there another choose between localIP() & remoteIP() , I want to catch the authorize IP to process it's command
Me No Dev
@me-no-dev
Jun 16 2016 11:06
client ip registration?
Mehrdad K
@mkeyno
Jun 16 2016 11:06
IP of connected Client
Me No Dev
@me-no-dev
Jun 16 2016 11:07
server.client().remoteIP() is it's remote IP
localIP is the IP that the client connected to
Ivan Grokhotkov
@igrr
Jun 16 2016 11:08
i think @mkeyno wants to get the IP of the client
so its server.client().remoteIP()
Mehrdad K
@mkeyno
Jun 16 2016 11:09
thanks Ivan , yes , but I want to sure that, my way to check authorized IP with server.client().remoteIP() is correct
Ivan Grokhotkov
@igrr
Jun 16 2016 11:09
what's "authorized IP"?
Me No Dev
@me-no-dev
Jun 16 2016 11:10
and what is your way of checking it?
Mehrdad K
@mkeyno
Jun 16 2016 11:10
authorized client , I want check authentication with client's IP
Ivan Grokhotkov
@igrr
Jun 16 2016 11:11
lol, how much security that adds I wonder?
Mehrdad K
@mkeyno
Jun 16 2016 11:11
compare it with pre save IP's
Ivan Grokhotkov
@igrr
Jun 16 2016 11:11
basically, as an attacker, i can set myself any static IP
and then cycle through all subnet IPs until i find one which is authorized
Me No Dev
@me-no-dev
Jun 16 2016 11:12
if you are in the subnet
Mehrdad K
@mkeyno
Jun 16 2016 11:12
wow!!!?? such dumb I am, so what should I do Ivan
Me No Dev
@me-no-dev
Jun 16 2016 11:13
there is authorization in the server
Ivan Grokhotkov
@igrr
Jun 16 2016 11:14
yeah, at least use the basic-security thing in the web server, although it won't stand against wireshark.
Mehrdad K
@mkeyno
Jun 16 2016 11:14
this is only for users intend to open the webpage from SPIFF
but what if two machine intend to talk each other in pre set secure line
Me No Dev
@me-no-dev
Jun 16 2016 11:16
http talk?
Ivan Grokhotkov
@igrr
Jun 16 2016 11:17
since we don't have HTTPS in webserver (yet...), your best bet would be to use something like DIGEST-MD5
Me No Dev
@me-no-dev
Jun 16 2016 11:17
@igrr I think we can bring real digest md5 to the server for auth
Mehrdad K
@mkeyno
Jun 16 2016 11:17
My Sensor ESP module send data to my ESP actuator module , so I must be sure someone else don't send unauthorized action to the actuator module
I can set ip address of sensor module in my actuator module , but as you say it is totally leak
Ivan Grokhotkov
@igrr
Jun 16 2016 11:19
quick fix: use MQTT. add an MQTT broker to the system, make sensors and actuators connect to the MQTT broker with TLS and client certificate authentication, and that's going to be pretty secure
Mehrdad K
@mkeyno
Jun 16 2016 11:20
wow Ivan your offer is quit lot of time for me
Ivan Grokhotkov
@igrr
Jun 16 2016 11:20
another way: authenticate the command from sensor to actuator with HMAC-MD5
Mehrdad K
@mkeyno
Jun 16 2016 11:21
what is the HMAC0-MD5?
do you have any example of that
Ivan Grokhotkov
@igrr
Jun 16 2016 11:22
it's a hash message authentication code based on MD5
Mehrdad K
@mkeyno
Jun 16 2016 11:24
ok , thanks you guys , sorry for this interrupt , please continue to your professional discussion
Hagai Shatz
@hagai-shatz
Jun 16 2016 11:33
We are all professionals @mkeyno , you are one of us now! ;-)
Mehrdad K
@mkeyno
Jun 16 2016 11:36
no , I'm novice walking in the Gods presence
Hagai Shatz
@hagai-shatz
Jun 16 2016 11:41

From RFC6266 section 4.2:

On the other hand, if it matches "inline" (case-insensitively), this implies default processing. Therefore, the disposition type "inline" is only useful when it is augmented with additional parameters, such as the filename (see below).

Hagai Shatz
@hagai-shatz
Jun 16 2016 12:01
To my understanding, this code is more to the point (not tested):
  if(download) {
    // set filename and force download
    int filenameStart = path.lastIndexOf('/') + 1;
    char buf[26+path.length()-filenameStart];
    char* filename = (char*)path.c_str() + filenameStart;
    snprintf(buf, sizeof (buf), "attachment; filename='%s'", filename);
    addHeader("Content-Disposition", buf);
  }
Me No Dev
@me-no-dev
Jun 16 2016 12:03
@everslick had some issues vewing files, but that could have been due to ContentType
Helio Machado
@crushedice2000
Jun 16 2016 12:04
Hi!
Is there any way of setting up SSDP in AP-only mode? What should I use for HTTP.client?
Helio Machado
@crushedice2000
Jun 16 2016 13:01
@me-no-dev: I've enabled the web sockets debugging:
[WS-Server][0] new client from 192.168.4.2
[WS-Server][0][handleHeader] RX: GET / HTTP/1.1
[WS-Server][0][handleHeader] RX: Host: 192.168.4.1:81
[WS-Server][0][handleHeader] RX: User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.11; rv:46.0) Gecko/20100101 Firefox/46.0
[WS-Server][0][handleHeader] RX: Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
[WS-Server][0][handleHeader] RX: Accept-Language: es-ES,es;q=0.8,en-US;q=0.5,en;q=0.3
[WS-Server][0][handleHeader] RX: Accept-Encoding: gzip, deflate
[WS-Server][0][handleHeader] RX: Sec-WebSocket-Version: 13
[WS-Server][0][handleHeader] RX: Origin: null
[WS-Server][0][handleHeader] RX: Sec-WebSocket-Protocol: arduino
[WS-Server][0][handleHeader] RX: Sec-WebSocket-Extensions: permessage-deflate
[WS-Server][0][handleHeader] RX: Sec-WebSocket-Key: RrKmoSNY9m6iRvu68YSksw==
[WS-Server][0][handleHeader] RX: Connection: keep-alive, Upgrade
[WS-Server][0][handleHeader] RX: Pragma: no-cache
[WS-Server][0][handleHeader] RX: Cache-Control: no-cache
[WS-Server][0][handleHeader] RX: Upgrade: websocket
[WS-Server][0][handleHeader] Header read fin.
[WS-Server][0][handleHeader]  - cURL: /
[WS-Server][0][handleHeader]  - cIsUpgrade: 1
[WS-Server][0][handleHeader]  - cIsWebsocket: 1
[WS-Server][0][handleHeader]  - cKey: RrKmoSNY9m6iRvu68YSksw==
[WS-Server][0][handleHeader]  - cProtocol: arduino
[WS-Server][0][handleHeader]  - cExtensions: permessage-deflate
[WS-Server][0][handleHeader]  - cVersion: 13
[WS-Server][0][handleHeader]  - base64Authorization:
[WS-Server][0][handleHeader] Websocket connection incoming.
[WS-Server][0][handleHeader]  - sKey: rjv7vPOR2aRzxiFdTzTrSoDFVJk=
[WS][0][headerDone] Header Handling Done (1075851445us).
[WS][0][sendFrame] ------- send massage frame -------
[WS][0][sendFrame] fin: 1 opCode: 9 mask: 0 length: 0 headerToPayload: 0
[WS][0][sendFrame] sending Frame Done (4688us).
[0] Connected from 192.168.4.2 url: /
[WS][0][sendFrame] ------- send massage frame -------
[WS][0][sendFrame] fin: 1 opCode: 1 mask: 0 length: 9 headerToPayload: 0
[WS][0][sendFrame] fin: 1 opCode: 1 mask: 0 length: 9 headerToPayload: 0
[WS][0][sendFrame] text: Connected
[WS][0][sendFrame] pack to one TCP package...
[WS][0][sendFrame] sending Frame Done (13869us).
[WS][0][handleWebsocketWaitFor] size: 2 cWsRXsize: 0
[readCb] n: 2 t: 47745
[WS][0][handleWebsocketWaitFor][readCb] size: 2 ok: 1
[WS][0][handleWebsocket] ------- read massage frame -------
[WS][0][handleWebsocket] fin: 1 rsv1: 0 rsv2: 0 rsv3 0  opCode: 10
[WS][0][handleWebsocket] mask: 1 payloadLen: 0
[WS][0][handleWebsocketWaitFor] size: 6 cWsRXsize: 2
[readCb] n: 4 t: 47768
[WS][0][handleWebsocketWaitFor][readCb] size: 6 ok: 1
[WS][0][handleWebsocket] ------- read massage frame -------
[WS][0][handleWebsocket] fin: 1 rsv1: 0 rsv2: 0 rsv3 0  opCode: 10
[WS][0][handleWebsocket] mask: 1 payloadLen: 0
[WS][0][handleWebsocket] get pong  (<null>)
The client says: Firefox no puede establecer una conexión con el servidor en ws://192.168.1.1:81/.
andig
@andig
Jun 16 2016 15:42
stupid question: where do I need to git clone esp8266 on osx?
couldn't find it in the docs and am new to osx...
Helio Machado
@crushedice2000
Jun 16 2016 15:44
@andig: Arduino/hardware/esp8266com/esp8266
I don't know where you have the Arduino folder
The first text field on the Arduino preferences has the path to that folder
Helio Machado
@crushedice2000
Jun 16 2016 15:50
You can get into the Arduino preferences by pressing Command and comma (,)
Miguel Angel Salinas Gancedo
@masalinas
Jun 16 2016 15:51
@andig in mac osx arduino folder is on /Users/<you>/Documents
Helio Machado
@crushedice2000
Jun 16 2016 15:52
Sin título 2.tiff
Sin título.tiff
andig
@andig
Jun 16 2016 15:52
it doesn't have a hardware folder right now which confuses me
Helio Machado
@crushedice2000
Jun 16 2016 15:53
Create it
andig
@andig
Jun 16 2016 15:53
it has one on windows that contains the regular arduino stuff?
Helio Machado
@crushedice2000
Jun 16 2016 15:53
cd /Users/$USER/Documents/Arduino
mkdir hardware
cd hardware
mkdir esp8266com
cd esp8266com
git clone https://github.com/esp8266/Arduino.git esp8266
andig
@andig
Jun 16 2016 15:54
right, doing so now
and there it is... thanks!
espasync libs in there as well or into the regular libraries folder?
Helio Machado
@crushedice2000
Jun 16 2016 15:55
@masalinas: I thought that it was placed on Documents because I placed it there.
@andig I think that it should be on the libraries folder.
andig
@andig
Jun 16 2016 15:58
huh, seems to compile quicker on macbook thatn on core i5 windows machine? funny
Helio Machado
@crushedice2000
Jun 16 2016 16:00
@andig: Maybe. PlatformIO compiles even faster than Arduino IDE.
@me-no-dev: Did you remember that ugly web socket issue?
I've "solved it"
extern "C" {
  #include "user_interface.h"
  void __run_user_rf_pre_init(void) {
    uint8_t ap_mac[] = AP_BSSID;
    uint8_t sta_mac[] = STA_BSSID;
    system_phy_set_max_tpw(TXPWR);
    wifi_set_phy_mode(TXMODE);
    wifi_set_macaddr(SOFTAP_IF, &ap_mac[0]);
    wifi_set_macaddr(STATION_IF, &sta_mac[0]);
  }
}
The above lines are the conflicting ones.
However, I don't know why nor how.
Could you kindly explain me that?
andig
@andig
Jun 16 2016 16:21
where should I put the upload tool on osx?
docs/arduino/tools/espplugin.jar ?
doesnt seem to fint it whereever its put
Helio Machado
@crushedice2000
Jun 16 2016 16:58
@andig: What upload tool?
Helio Machado
@crushedice2000
Jun 16 2016 17:45
@me-no-dev: The conflicting lines are:
wifi_set_macaddr(SOFTAP_IF, &ap_mac[0]);
wifi_set_macaddr(STATION_IF, &sta_mac[0]);
Clemens Kirchgatterer
@everslick
Jun 16 2016 18:09
@hagai-shatz i think cutting the directory info from path is absolutly fine and a sensible thing to do. the RFC even suggest that the browser should do it, when the server hadn't.
@hagai-shatz about 'inline': it's needed to be able to set the filename parameter, so the browser can give the right default filename should the user decide he wants to 'Save As...'.
Me No Dev
@me-no-dev
Jun 16 2016 18:51
@andig the tool should go into ~/Arduino/tools/... (like the hardware folder you created)
@crushedice2000 I'm a bit confused?
what was the issue and why would those lines matter?
Helio Machado
@crushedice2000
Jun 16 2016 18:53
@me-no-dev: Do you remember the issue I had with WebSockets that could not connect?
The main culprit is of these lines. Don't ask me why, but commenting out they, all works.
Me No Dev
@me-no-dev
Jun 16 2016 18:55
interesting... maybe @igrr can check the source for issues
@crushedice2000 please explain the problem better here, so he can have something to go from
Helio Machado
@crushedice2000
Jun 16 2016 19:02

@me-no-dev: Explaining:

  1. I've done a sketch based on this one. The only difference is that I'Ve added this code in the top:
extern "C" {
  #include "user_interface.h"
  void __run_user_rf_pre_init(void) {
    uint8_t ap_mac[] = AP_BSSID;
    uint8_t sta_mac[] = STA_BSSID;
    system_phy_set_max_tpw(TXPWR);
    wifi_set_phy_mode(TXMODE);
    wifi_set_macaddr(SOFTAP_IF, &ap_mac[0]);
    wifi_set_macaddr(STATION_IF, &sta_mac[0]);
  }
}
  1. If I comment the below lines, all works well:
wifi_set_macaddr(SOFTAP_IF, &ap_mac[0]);
wifi_set_macaddr(STATION_IF, &sta_mac[0]);
  1. If I don't, then happens this:

    • On the firefox JS console:

      var j = new WebSocket('ws://192.168.1.1:81', ['arduino']);
      undefined
      Firefox no puede establecer una conexión con el servidor en ws://192.168.1.1:81/
      Translated: Firefox cannot connect to the server on ws://192.168.1.1:81/
    • On the server: It fires the webSocketEvent with type=WStype_CONNECTED and then the connection closes (the server won't fire webSocketEvent with type=WStype_DISCONNECTED )

Me No Dev
@me-no-dev
Jun 16 2016 19:07
you mac adresses ok?
uint8_t ap_mac[] = {0x01, 0x23, 0x45, 0x67, 0x89, 0xAB};
Helio Machado
@crushedice2000
Jun 16 2016 19:13
@me-no-dev:
#define AP_BSSID {0x52, 0x31, 0x39, 0x32, 0x41, 0x00}
#define STA_BSSID {0x52, 0x31, 0x39, 0x32, 0x41, 0xFF}
Me No Dev
@me-no-dev
Jun 16 2016 19:15
and everything else is fine? You see the proper mac in your DHCP?
Helio Machado
@crushedice2000
Jun 16 2016 19:15
@me-no-dev: I'm not using the client now. On the SoftAP, I don't know what to do.
Me No Dev
@me-no-dev
Jun 16 2016 19:17
ok what is WiFi telling you on the ESP?
if you read both macs after setting them
Helio Machado
@crushedice2000
Jun 16 2016 19:18
@me-no-dev: How?
Me No Dev
@me-no-dev
Jun 16 2016 19:20
String staMAC = WiFi.macAddress();
String apMAC = WiFi.softAPmacAddress();
Helio Machado
@crushedice2000
Jun 16 2016 19:23
@me-no-dev: The result is the new mac. The change works.
Me No Dev
@me-no-dev
Jun 16 2016 19:38
let's hope @igrr can shed some light
Helio Machado
@crushedice2000
Jun 16 2016 19:42
@me-no-dev: OK. Thanks!
sticilface
@sticilface
Jun 16 2016 22:06
@igrr any ideas about this. https://community.platformio.org/t/the-old-beast-using-the-staging-version/380/7 the wifievent refactoring does not play nice with platformio