-->
Page 1 of 2

Sending custom packets using ESP8266WiFi library

PostPosted: Wed Feb 24, 2016 9:38 am
by Ahunter
I've got a little project which involves sending TLS packets. For this, I need to be able to make up a custom packet.

At the moment I'm using ESP8266WiFi to open a TCP connection on port 443 (which works), and then using client.print(packet) to send the data. It all compiles, but when I capture the packets on the access point, all I get is a load of TCP packets that don't contain any of the data I tried to send.

Am I using the print() method wrong, or is this the wrong way to go about doing this?

I've posted the important parts of the code below. everything after the [...] is in the loop() function.

Code: Select all#include <ESP8266WiFi.h>
[...]
WiFiClient client;
    const int httpPort = 443;
    if (!client.connect(host, httpPort)) {
      Serial.println("connection failed");
      return;
    }
    else {
      char packet[] = "\x16\x03\x01\x00\x2c\x01\x00\x00\x28\x03\x03\x2b\x7e\x15\x16\x28\xae\xd2\xa6\xab\xf7\x15\x88\x09\xcf\x4f\x3c\x2b\x7e\x15\x16\x28\xae\xd2\xa6\xab\xf7\x15\x88\x09\xcf\x4f\x3c\x00\x02\x00\xa0\x00\x00";
      client.print(packet);
}

Re: Sending custom packets using ESP8266WiFi library

PostPosted: Wed Feb 24, 2016 2:29 pm
by martinayotte
The client.print() is used for string, so it will send the first bytes until it reach the first 0x00 and stop there.
You need to use client.write(const uint8_t *buf, size_t size).

Re: Sending custom packets using ESP8266WiFi library

PostPosted: Thu Feb 25, 2016 11:02 am
by Ahunter
Thanks, that did the trick!

Re: Sending custom packets using ESP8266WiFi library

PostPosted: Tue Mar 15, 2016 2:53 pm
by Ahunter
So I'm revisiting this project, and I've encountered another problem: I need to be able to build packets at runtime, but the method that was specified earlier - client.write(const uint8_t* buffer, size_t size) - only allows the use of "const" qualified variables.
Is there some way around this?
I tried sending the data using the client.write(uint8_t buf) method, but as expected, this sent out individual TCP packets that didn't seem to be able to be reassembled...