I am building a wireless control system for a magnetic loop antenna. The system uses an ESP32 microcontroller (that has Bluetooth and WiFi) that
- automatically drives the magloop capacitor by means of a DC motor, while
- minimising SWR in real time.
While "1" is easy, I failed at "2". I want to use FT817's own SWR meter, and assumed I could programmatically read-out the LCD readings via CAT control: this is what Omnirig does (if I am not mistaken).
I then got a (CAT) Bluetooth dongle on eBay and, using the "BluetoothSerial" Arduino library I managed to have the ESP32 and the FT817 communicating! For instance, the ESP32 can easily read (and set) mode + frequency, activate/release the PTT, and even switch ON/OFF the radio! I even managed to read out the S-Meter values (by the ad hoc CAT command).
Reading SWR programmatically, however, requires using an (undocumented) CAT command (mentioned by KA7OEI). Unfortunately, as I try that, the ESP3 gets a series of wrong numerical values, at odd with the number of "segments" on the LCD indicating SWR.
Something is wrong with my idea or with the (Arduino, C) code, whose extract is reported below:
#define CAT_sTX_DATA_CMD 0xBD
unsigned short int getSWR() {
byte outByte[5] = {0x00,0x00,0x00,0x00,0x00};
outByte[4] = CAT_sTX_DATA_CMD;
long elapsed = 0;
byte reply1, reply2;
unsigned int swr;
unsigned int pwr;
String SWR;
long timeout = millis();
sendCmd(outByte, 5);
while (SerialBT.available() < 2 && elapsed < 2000) {
elapsed = millis() - timeout;
;}
reply1 = SerialBT.read();
reply2 = SerialBT.read();
pwr = (unsigned short) ((reply1 >> 4) & 0x0f);
swr = (unsigned short) (reply1 & 0x0f);
return swr;
}
void sendCmd(byte cmd[], byte len) {
for (byte i=0; i<len; i++)
SerialBT.write(cmd[i]);
}
Any chance that some among you has already solved the same problem?
Any hints or suggestions? Do you see a problem in my getSWR() function?