All posts by admin

Delphi Websockets

Been compiling a version of the following WebSockets delphi repository: https://github.com/staspiter/delphi-websocket the third 3-WSS. My setup was under Linux compilation using RAD Delphi 10.4.2 FMXLinux GetIt-Addon – on Ubuntu 20.4-LTS Linux. Using IndyProject Components set.

The certain delphi-websocket repository was coded as part of Delphi CodeRage2019.

Clients were standard .js browser side the sent/received messages in an IRC room alike setup..  Just wanted to run a POC on this code.

Thing that caused the code to get ‘Stuck’ was a situation where the end clients were mobile – and

  • got connected via local Wifi
  • manually disconnected from Wifi
  • connected to data connectivity
  • refresh chat page
  • disconnected from data connectivity
  • refresh chat page
  • connected to local Wifi again
  • and refresh the page

When snooping the network using WireShark the following log lines were already raised in the situation described above – xx.xx.xx.xx – is the external Domain (cause most of the connections I made were from the inside LAN to the external Domain IP – Except when connecting the mobile to cell data connection) IP, 192.168.2.194 is the WebSocket Delphi Server local IP.

  • 22900 1126.696488 xx.xx.xx.xx 192.168.2.194 TCP 66 56732 → 8889 [RST, ACK] Seq=1667 Ack=4941 Win=107904 Len=0 TSval=23369304 TSecr=4087275315
  • 22901 1126.697212 192.168.2.194 xx.xx.xx.xx TCP 60 8889 → 50466 [FIN, ACK] Seq=3136 Ack=1 Win=501 Len=0
  • 22902 1126.697226 192.168.2.194 xx.xx.xx.xx TCP 60 8889 → 50462 [FIN, ACK] Seq=3136 Ack=1 Win=501 Len=0
  • 22903 1126.697232 192.168.2.194 xx.xx.xx.xx TCP 60 8889 → 50452 [FIN, ACK] Seq=3136 Ack=103 Win=501 Len=0

What you see in this log, that when the StuckUp-Actions taken. A RST call was made (RST are standard TCP flag calls [RESET] – which are triggered every time an end point disconnects). And this cause a shutdown to all connected clients (you can see the connected clients in the different PeerIP each WebSocket Client get).

When debugging that (using Delphi IDE and PAServer bridge on Linux) Server raised the following error: “Delphi Project raised exception class Broken pipe (13)” – (the other errors such as the SSL error in the image – were probably raised due to communication and server stuck issue). I initiate a chat with Remy Lebeau – who is maintaining the Indy code for a while now.

Took me some time, actually debugging and finding this error. But Remy understood exactly at no time how to fix that. I had to run the following code lines:

uses Posix.Signal;

signal(SIGPIPE, Pointer(SIG_IGN));

In official Delphi environment the namespace units ‘POSIX’ contains different units which handle different Linux RTL API calls.

Disabling the Pipe is done slightly differently on Apple and on Linux platforms machines.

As for the present time (as I write this) WebSockets aren’t integrated into actual Indy components set. There are several open-sourced versions floating around (and of course at leaft four commercial components set versions – which in this case were too much to invest in, just yet). I found the above github repo good enough cause I could use it cross-platform on my Linux.

MQTT Delphi fmx

I was looking for MQTT (Mosquitto protocol implementation) using Indy components (that supports FMX [Delphi Firemonkey framework]).

I found this repo https://github.com/wizinfantry/delphi-mqtt-client — which seems to work after adding the following fix:

On file .\delphi-mqtt-client\LIB\MQTT.pas on function ‘function TMQTT.WriteData(AData: TBytes): boolean;’ using proper TMemoryStream something like that:

function TMQTT.WriteData(AData: TBytes): boolean;
var
  sentData: integer;
  attemptsToWrite: integer;
  Stream: TMemoryStream;
  nCount: Integer;
  pData: TArray<byte>;
begin

// :
// ;

    try
      Stream := TMemoryStream.create;
      nCount := Length(AData) - sentData;
      pData := Copy(AData, sentData - 1, Length(AData) + 1);
      Stream.Write(pData, nCount);
      Stream.Seek(0,0);
      FSocket.IOHandler.Write(Stream, Length(AData) - sentData);
      Stream.Free;
      Result := True;
      FisConnected := true;
    except
      raise;
      Result := False;
      FisConnected := false;
    end;

// :
// ;
end;

Although it is only Alpha version, it does seem to do the basic functionality.

Seems to me this repo is a forked version of https://github.com/jamiei/Delphi-TMQTT2 which is the VCL version using Synapse TCP components.

I ran basic tests on Win, Android and Linux (using Delphi Sydney 10.4.2 with Linux GetIt addon)… all seems to work properly — (Linux had a little free memory issue when subscribing a topic — which required try except — as a fast fix)

First time with electronics! Yey!

I started playing a little with electronics, for the first time in my life. I keep on being amazed with the wide options it all open for me, breaking the PC to small parts unleash worlds of possibilities. I got into several personal projects — when I immediately saw when these options were revealed.
A good friend of mine introduced me to Autodesk Eagle  — software to draw circuits. In addition you can download and insall Adafruit & Sparkfun electronics huge parts catalog in your Eagle for you to use.
I bought a ESP32 WROOM DevKitC  from Expressif — but couldn’t find the proper Eagle schematics for the ESP32 unit on the web (even after looking for it for a half a day).  There were a lot of links that presented the information in .pdf files. Cause it is very early stage of me playing with Eagle, I couldn’t find a proper way importing the .pdf to Eagle.
So I used the following resources:

And assembled a My Eagle schematics of ESP unit – Download ESP32 DevKitC Eagle Library  Schematics.
Due to the fact it is the first day I am playing with Eagle, there may be issues in the Schematics I assembled, which will be corrected if required.

More information about the different kind of ESP units can be found here.

My DoorBell Project:

My doorBell project is easy to explain,. basically some one rings the bell and a whole process it inititiated:

  • BellRing event is launched (On the ESP unit)
  • Windows Server logs activity (Using Delphi Datasnap WebBroker Technology)
  • Windows Server notify Android end units and a RPiZW unit to play the audio ring (Android units written with Delphi FMX, and RPiZ is a python based script)

An Eagle schematics I made of the ESP32. The big chip in the middle is the ESP32 v4 I am using:

I added in, the Eagle footprint image of the chip as noted:

This is a sample of the unit in action (on a test breadboard — note it is wired differently — it is the first test I made), with all sides modifications — it still requires some modifications and changes:

 

This is are two images of the circuit soldered on a standard prototype board: