Working on a simple handshake protocol between the blaster and the host using the 433MHz connection.
Question: Why not Blutooth or Wifi, ESP32 got both already?
Answer: Yes it might also work with BT or Wifi and maybe I am wasting too much energy on the 433MHz component but there are certain advantages in my opinion. First is the range, you can easily increase the range by using a long antenna on the host and there is no failing or loss of connection. Simple serial messaging. The disadvantage is the speed, so I have to keep the sent strings as short as possible. However I am no specialist, if anyone wants to provide a reliable BT or WiFi alternative in a later mod, go for it. It would reduce costs of course.
So this is my plan:
- Blaster: asks host
- Host: replies with game settings if detected and adds blaster to player list
- Blaster: replies with confirmation of received game data
- Host: replies with status “ready”
// doing the handshake between blasters and server
// doing the handshake between blasters and server
void dohandshake(lv_event_t *e) {
Serial.println("We are at handshake.");
// is HC12 available?
if (hc12.available()) {
// Serial.write(hc12.read());
// get the message
message = hc12.readString();
// @G0XX = attag blaster asking to join, XX=id of the blaster
// @G1XX = attag blaster received game data and is ready to start, XX=id of the blaster
// Reading messages from the blasters
if (message.substring(0,2)=="@G0") {
// adding blaster to the player list, but don't set on confirmed yet
// sending game data
} else if (message.substring(0,2)=="@G1") {
// setting blaster to confirmed
// sending ready status
}
}
}
The ID of the blaster could be transmitted in hex of course, this would shorten the string to 4 chars, 16 players (0-F) should be quite enough. There needs to be some sort of identification, so the server isn’t collecting any garbage from somewhere else, I guess the @G should do it, it isn’t rocket science here and anything in range at 433MHz would be some garage doors, weather stations and toy vehicles.