ATTAG handshake between blaster and host part 2

My intentions to keep the communication as small as possible reached some insane level I guess. After I got mad about some limits of C++ that really made me angry (Goddamn I am not a programmer.) I came to the conclusion that 1 byte is enough for the talk between blaster and host. As follows:

A byte contains 8 bits. I will use the first 4 bits to identify the blaster as 4 bits can describe 2^4 states. The 5th bit will describe the status and the remaining bits will be used as identification as ATTAG.

Why so short? Speed and reduction of possible transmission errors.

I am not yet sure if this will make any sense at the end but to run the HC-12 even at very low baudrates, it makes sense to keep the traffic as low as possible.

// the first player 0 starts at decimal 7, the binary code 0000 0111
// the first 4 bits are the player id, the 5th bit describes status available=0 and ready=1
// the last 3 bits 111 stay as identification of attag
// the next player 1 with status "available" is baseplayer+16=23 
// the status ready for that player then is baseplayer+24=31

// get the playerid from a potvalue later
playerid=4; // just for simulation now

int baseplayer=7; // player zero
int pavailable=baseplayer+playerid*16; 
int pready=baseplayer+playerid*16+8;

ATTAG handshake between blaster and host

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.

ATTAG Server Box

Alright, forget about the power bank thing I mentioned a couple of days ago, it is pointless. The smartdisplay got an integrated battery management system for a 3.7V lithium cell. So more room means more capacity. I was looking for some pouch cells and found these, which already have the correct connector:

Wiring of the HC-12 antenna.

The bottom of the box got a tab on each side for the usage of a velcro strap, belt or rubber band to place the server on a pole or a tree.

Make sure to add the button before inserting the smartdisplay.

The holes are made for M3 6mm skrews. You need five 6mm in total and two 16mm.

I fixed the battery with double sided tape, same for the HC-12 module and used some two-component glue for the speaker. I guess this could be done a little bit more elegant but anyway. I hope the bending of the antenna doesn’t cause me too much trouble, otherwise I gotta fix that later on. Just try to not bend it that way to avoid communication trouble.

My printer was set a bit too low on Z, so it messed up the logo and the text, but this is some alpha stuff anyway. As you can see it is already running on battery. Double tapping the button switches the server to off.

So here is what you need:

And of course the STL files for printing:

attag server box STL files

OSDYLS power supply for the server

For the server unit I was looking for some small power bank to avoid constructing a battery management and 5V supply. I came across some keychain power banks and picked this one:

It can be opened easily without damaging anything, the inflated pouch pack doesn’t look too trustworthy though. Apart from that the 500mAh should deliver enough power for a 2-3h running time of the server. More than enough time to battle. (From my experience you are really tired after an hour unless your are trained 😉 )

Just need to remove the plug wires and connect to a charging USB socket and solder the 5V to a connector for the display.

OSDYLS – Game master / Host / Server

Since the beginning of the project it was clear that there would be some sort of server, which controls the aspects of the game, like game mode, play time, respawns, ammo and so on. While I was working on the kiln control project I was looking for some tiny touchscreens around and came across these cheap small smart displays on aliexpress. [ link: ESP32-2432S024C ]

Smart Display
Smart Display

Instantly I thought these would be perfect for usage as an OSDYLS host. Though there is a slight drawback, the creators of these displays left very few GPIO pins for external sensors and mods.

However I got myself one of these displays and checked if the HC-12 radio module could be connected to it, and indeed it can. There is also a speaker connector, micro SD slot, WiFi and I think even BT functionality on the board. The vendor provides a pack of examples for it, but I suggest using the [ link: esp32-smartdisplay ] package from github made by [ link: rzeldent ].

You need to get used to visual studio and platformio for it, for a noob like me that was a bit of a challenge but it is quite worth the step. If you are more used to programming with arduino IDE you proably get the libs working there as well of course.

OSDYLS Battle Server

Currently the thing isn’t doing much, I was just creating a simple gui for the beginning using squareline studio, which comes in quite handy for that.

The next step is to create a handshake between players and host, so the server knows who is part of the game. It would automatically fire up the match once all players joined.