# 2023-10-07 I got distract by hacking last night and forgot to write this, so this covers my work for the past two days. ## Guru meditations I spent a while on Friday trying to debug a nagging Guru Meditation (aka a segfault) in my autoconnection code. One of the debugging tricks that really helped with this is to the PlatformIO monitor filter for decoding ESP stack traces. Anyways, the problem ended up being trying to use the result of a bool function when that function wasn't returning anything. I guess the warning for the was lost in the scrollback. ## Autoconnecting My first pass at autoconnecting was to scan for SSIDs, looking up each one in the phonebook. However, I wasn't seeing my home network in the scan list. I ended up using a Preference (from the ESP Preferences library) to store the SSID of the last connection, looking that up in the phonebook, and connecting to that. This worked. ## A question of structure I want to be able to switch the modem into different modes. The main use for the modem is to be able to telnet into a BBS, so I need a way to say that I/O should be passed between the host machine and the BBS. At the same time, there needs to be a way to talk to the modem, to tell it to connect or disconnect, dial hosts, manage connections, etc. At first, I thought I would use some kind of an object inheritance system, so I wrote up a basic skeleton of that. However, the guiding constraint is that I'm trying to dynamically allocate as little memory as possible. In order to use an abstract base class, though, you need a pointer, and that got convoluted quickly. Then I tried putting a static member in a header, but the fields would be reset to NULL each time. What I ended up doing was putting a static variable in a new source file and added some interaction scaffolding around it. This works. And of course it does when you think about it. I was thinking of the extern keyword, and I've spent too much time in Go. Rather than debug this on the microcontroller, I wrote a quick test program where I could use gdb and generate coredumps. It was relatively easy to figure out at that point. Long story short, this works now: MODEM BOOT SPIFFS INIT DAT FILE 512B LOAD PHONEBOOK OK dictionary entries: { HomeNet->c00lp4ssw0rd OtherNet->correct horse battery staple } AUTO ATC LAST SSID: HomeNet CONNECT HomeNet SSID: HomeNet IP: 192.168.88.232 MODEM READY > ATW 802.11 CONNECTED SSID: HomeNet IP: 192.168.88.232 RSSI: -53 > ATWS SCAN ## File system choices When I was reading up on storing files on the ESP32, SPIFFS was the default choice. However, on the ESP8266, it seems like LittleFS is the default. Do I need to write a compatibility layer? The RC2014 WiFi module is an ESP8266, but my dev boards are all ESP32. It works now, but there's the threat of deprecation in the future. In addition, I could use an SD card. Something to think about. For now, I'm just using SPIFFS. I think a generic interface for this would be something like // open flags: // APPEND // CREATE // READONLY // READWRITE // WRITE class PersistentStorage { public: virtual int Open(const char *path, uint8_t mode) = 0; virtual int Close() = 0; virtual size_t Size() = 0; virtual size_t Read(uint8_t *buf, size_t maxlen) = 0; virtual size_t Write(uint8_t *buf, size_t length) = 0; virtual int Flush() = 0; } ## On code organization Most of this has been a first pass attempt. I'm going to sit down at some point and work out all the proper organization. I think the display was helpful for getting off the ground but ultimately it's a distraction. Also, I need to settle on the hardware. I think I'm going to make a carrier board with things like an FTDI header, some LEDs, and the ability to program it. ## On editors I've switchd over to joe recently. We'll see how long it lasts.