PHPnews.io

Working with the ESP in Cspect [spectrum] [blog]

Written by Remy Sharp / Original link on Sep. 9, 2021

After developing the .http tool for the Spectrum Next in assembly, for my own workflow I did most of the testing against an emulator (before moving to hardware), however there's some quirks with Cspect and the wifi/esp/internet setup, and since I've been through the fire and come out the other side it makes sense to write it up.

By default

With no changes, Cspect does support making TCP/IP requests and emulates a small subset of ESP AT commands, such as AT+CIPSTART, AT+CIPSEND=... etc.

The big gotcha is that all data is encoded as 7-bit.

This is important because if you're working with ASCII text like a protocol like gopher, then everything will work fine. However, if you're sending raw 8-bit bytes over a socket, Cspect will corrupt the data. For example, if the server sends 0xFF it will be corrupted to 0x7F.

However, there's also no logging so debugging can be especially hard. This is where Robin Verhagen-Guest's github repo comes to the rescue.

Enabling 8-bit bytes

The UART replacement Cspect plugin replaces Cspect's own implementation and, from my own experience, makes the ESP communication near identical to the Spectrum Next's own comms. However, you will need your own ESP module attached to your development machine (in my case, my Mac).

The directions are very simple to follow once you've download the plugin zip file:

Download the CSpectPlugins.zip file, then extract the UARTReplacement.dll and UARTReplacement.dll.config files. Exit CSpect, then copy these into your CSpect directory

Now you need to plug your ESP module into the machine you're working with. I used this specific adapter and it worked with zero setup: OPEN-SMART USB To ESP8266 ESP-01. Of course, you'll also need an ESP-01. You can find these on Amazon (a pack of 4 for £12) or 87p on AliExpress (if you're happy to wait).

You will need to discover the port that the device is connected to. On Windows this is typically COM1 but it's worth checking your devices to be sure. MacOS is a little trickier, but typically can be found using ls /dev/tty.* (though /dev/cu.* might also work). Take note and use this in the UARTReplacement.dll.config.

This is my own MacOS config file:

<?xml version="1.0" encoding="utf-8"?>
<Settings xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <PortName>/dev/tty.wchusbserial1420</PortName>
</Settings>

Using Cspect now will pass the requests directly to the ESP which gives you a much closer experience to the Spectrum hardware.

Logging

Again, Robin's repo solves this problem. In the same zip file is the UART Logger. Again, drop this into your Cspect directory and now all ESP comms are logged (by default) in the Cspect directory in a file called ESPLogFile.txt.

The result is all the back and forth communication between the ESP and the software:

cspect-esp-logging.png

Final background reading

I'd also recommend reading around the ESP itself to understand some of it's quirks, since the actual hardware can host different versions of the AT commands - with that in mind, I personally recommend sticking to the lowest common commands - usually just CIPSEND.

I did write up my braindump on ESP modules which could be useful follow up reading.

Originally published on Remy Sharp's b:log

remysharp

« You Don't Need to Burn off Your Fingertips (and Other Biometric Authentication Myths) - Small commits: ask me why »