Category Archives: RAD Delphi

Developer tools environement

DHT22 (Temperature and Humidity) Aggregators

Been running this circuit and server DHT22 aggregator since May 2022.
Basically this is a client (actually a server – ESP32 REST respond server), and a windows server (that calls the ESP32 server every interval, and aggregates the data into a sqlite3 small db).
Win Server as can be seen on the screen shot, displays compared data of temperature/humidity of the last four days – graph x-temperature y-time_of_day.

Technical details:

  • Win Server is a Delphi VCL Win32 application using TChart for the charts plot.
    In addition I’ve coded that the app taskbar icon, will light in RED when no connection can be made to the defined address.
  • ESP32 chip Server is an espressif-IDF SDK,. C code,. ESP32 is simply connected GPIO to the DHT22 sensor (as can be seen on the chip wired image).
    In addition I’ve connected a red led light, that is turned on, when no connection is done for defined interval to the ESP32 server.
    Calls to the ESP32 server are replied structured in very simple REST JSON record format.
DHT22 Windows server aggregator screenshot
DHT22 ESP32 server aggregator screenshot

Wrote a small app, that takes all my aggregated Temperature data and displays it on a scale of PI per day,. according to the temperature every period of time.
Total 148 days,. total 2.4m records (probed every 5sec – on a sqlite3 db).
It scales from the color red when the temperature was about 24.9c — to the green/black (which is kinda these days) when temperature is about 29c~30c.

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)

Delphi iOS Client Push Notification setup

Apple APNs iOS Client with Delphi 10.3+~

Prolog: A Lot is written how to implement APNs in various languages. I didn’t find, though proper one stop to learn how to implement APNs via IDERA’s Delphi. Basically, a main task with this procedure is with dealing with Apple Certifications (which is widely documented over many guides and sites).

Eventually you’d have to forge these files:

  • CertificateSigningRequest.certSigningRequest – to request a certification from Apple Services
  • Go to in Apple Developer Certification Web Console – to the AppID Identifier, and the Push Notification Capability – use the .csr to request a – And download .cer file.

    • Development SSL Certificate or
    • Production SSL Certificate
  • Use the aps_production_cert.cer – The Certification which needs to be installed in your Mac OS
    • clicking the ‘.cer’ file will add it to ‘My Certifications’ under the ‘Keys Chain’ – (Important this should appear on the ‘My Certifications’ if it isn’t there file won’t be able to get exported as a .p12)
  • Certificates.p12 – exporting the Push Certification as ‘.p12’
  • Certificates.pem – convert the ‘.p12’ file to ‘.pem’ file using openssl command:
    • openssl pkcs12 -in Certificates.p12 -out Certificates.pem -nodes
  • entrust_root_certification_authority.pem – The Apple CA (it can be downloaded from
  • To test that I used the .php object (basically you can code a server using Delphi as well… but I tested that with this .php server object) from

We are using in Delphi the TMessageManager.DefaultManager class to register for various messages from the iOS APN service. Such as when registration and receiving from the system the Device TokenID. Or when this procedure fails.. http://docwiki.embarcadero.com/Libraries/Sydney/en/System.Messaging.TMessageManager.SubscribeToMessage

And using the TiosHelper.SharedApplication to obtain the UIApplication and register the client iOS device for notifications using registerUserNotificationSettings(..); and registerForRemoteNotifications(); These procedures respond with a MessageData containing the unique device token.

uses
  // :
  FMX.Platform.iOS, System.Messaging, FMX.Platform,
  iosapi.Helpers, iOSapi.Foundation, FMX.Helpers.iOS, iOSapi.UIKit;

procedure TForm2.LogMsg(Value: String);
begin
  edtLog.Lines.Add(Value);
end;

procedure TForm2.RegisterNotificationClick(Sender: TObject);
var
  types: UIUserNotificationSettings;
begin
  // The token obtained from the TPushDeviceTokenMessage event should be used to identify the iOS client and send notifications to it
  TMessageManager.DefaultManager.SubscribeToMessage(
    TPushDeviceTokenMessage,  procedure(const Sender: TObject; const M: TMessage)
      begin LogMsg('TPushDeviceTokenMessage: ' + (M as TMessage<tpushdevicetokendata>).Value.Token); end);

  TMessageManager.DefaultManager.SubscribeToMessage(
    TPushFailToRegisterMessage, procedure(const Sender: TObject; const M: TMessage)
      begin LogMsg('TPushFailToRegisterMessage: ' + (M as TMessage<tpushfailtoregisterdata>).Value.ErrorMessage); end);

  TMessageManager.DefaultManager.SubscribeToMessage(
    TPushRemoteNotificationMessage, procedure(const Sender: TObject; const M: TMessage)
      begin LogMsg('TPushRemoteNotificationMessage: ' + (M as TMessage<tpushnotificationdata>).Value.Notification); end);

  TMessageManager.DefaultManager.SubscribeToMessage(
    TPushStartupNotificationMessage, procedure(const Sender: TObject; const M: TMessage)
      begin LogMsg('TPushStartupNotificationMessage: ' + (M as TMessage<tpushnotificationdata>).Value.Notification); end);

  types := TUIUserNotificationSettings.Wrap(TUIUserNotificationSettings.OCClass.settingsForTypes(
    UIUserNotificationTypeBadge or UIUserNotificationTypeSound or UIUserNotificationTypeAlert, nil));

  TiosHelper.SharedApplication.registerUserNotificationSettings(types);

  TiosHelper.SharedApplication.registerForRemoteNotifications();

  LogMsg('TiOSHelper.SharedApplication.registerForRemoteNotifications;');
end;

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:

Diving into 3d programming – Supplement (Web)

As I started with some 3d programming on delphi — Another requirement was raised. I needed to port some of the code, to a web based engine.

I recalled that once I played a little with VRML. Yet, after a quick search I found the following 3d WebGL engine called three.js. Due to the fact that I was stunt of the result of it, I decided to post this short supplement to my previous post.

The three.js handles the limitation of processing power on browsers, taking into consideration and a high use of the HTML5 architecture. This opensource package includes many demos, which can be viewed under the link above.

Although the package is (from a very short view), as structured as the delphi glscene. It uses the javascript in a very impressive way.

I’ll post some more notes, after building and using it a little more.

Diving into 3d Programming

Recently I’ve been looking into the area of 3d programming. Here are some few notes from this area of computing.

This area of 3d programming, would serve anyone in the:

  • 3d games programming area — (the directx, and opengl got plenty of code and samples of, for example, preforming character manipulations – character walk, or talk).
  • or in the 3d designing area – such as architects (yet, this area is more likely would use less options available to this 3d environment than a 3d games.
  • Anybody in the 3d animated movies area (unlike the 3d studio tools, for example – these abilities enable one to create a scene for example of a character doing random things – without any special effort).
    Thinking of 3d animated movies, where plenty of tools are being offered. Most of the scenes are usually being defined by the director (for example the ‘lord of the rings’ armies fight – as so on).
    I can think of a whole world, one can create, much like the 13th floor movie. Where the characters  have a life of their own.. And the platform enables them all these daily “random” activities.

When speaking on 3d programming, on windows. There roughly two basic architectures. When using dev environment such as delphi — you can write to both engines seamlessly — while both archtectures enable you to manipulate 3d environment down to detailed variables and features that you would like to achive:

DirectX and Delphi:
To program for that environment I all these, in different times:

  • Delphi FMX — Embarcadero intreduced this crossplatform graphics environment, that got plenty of goodies and abilities.
  • ksDev dxScene — (which later, became the FMX archetecture

OpenGL and Delphi:

  • glScene — an opensource OpenGL environment for use with delphi.

I’ve focused on these two, but I’m sure that looking for other alternatives one can find plenty more. One that I can recall seeing is the: vrmlScene.

—-

Here are some notes, of my first digg into the 3d environment:

I’ve dived into this ocean of shaders (which are virtually effects being done on the 3d model data) and edge detecting techniques, and all these abilities of the graphics manipulations.

After I switched from the dxScene (DirectX) to glScene (opensource opengl libraries), seems that all the searches I’ve made were much more focused. It seems that opengl is much more common than the directx ones. Although all the abilities of the two platforms are somewhat similar.

Anyhow preforming the manipulation programmer wise, got awesome abilities. Though the designated final goal must be well defined.

Here is a sample url of a question about the edges issue,. Which advise a way to preforme the edges.. Another example is this, of displaying wireframe, yet I do not know whether that answer the question as well.

Implementing the shader can be done done, as you see in the examples above, using an opengl c like syntax. OpenGL (as all software) comes in versions flavors,. And using the language in certain syntaxes is valid only for the proper opengl version.

The shader API define parameters to be sent to the rendered application. And it is very dynamic being defined in that way. For example a shader can send only color variable, or can send multiple parameters according the way it was defined by the rendering application.

Another extension of all this process can be done via direct gpu programming using for example the CG (not to be mistaken with CygWin, which is the CPP compiler for windows).

The CG is a CPP compiler for shaders.

A little about API & wrappers

API – Application interface
Best way to describe an API, is an interface of a wrapper of some source code. This enables interaction with your code via any third party that would like to use the functionality of what you have programmed.

This enables any third party to treat your code, as a blackbox. Putting some input variables in and getting out from your blackbox a result of a sort.

Of course this result can be visual, or any other data output, that you will later process. On occasions it can be just enabling an activation of a method or a procedure in the wrapper.

Programming language based API
Programming view point, a lot was and would be written. Different language syntax were introduced. And they can be a post for another discussion.

I’ll just note, that the best was to see the wrappers in use cases, is within the Object Orient Programming — whether it be OOP (Object Oriented Pascal), or CPP (C Plus Plus) and Java. Where structures and objects using different procedures/methods/properties was defined. Wrapping source code objects in a defined structures.

The way of structured Object programming that was well defined, was shifted onto different source codes that function as a blackboxed application. When programming the actual code, in different places from within the application different calls are made to existing object and interfacing with them.

Same goes when a service/application requires interaction with the code, yet not within the same source code, but as an external interaction to the objects, data and services of the application.

These requirements resulted with many different products and syntax definitions that could be encountered on many different areas of computing. Here are my notes on these definitions of API.

Winamp API – My First spark of a great code and application design by NULLSOFT
My first encounter of a great API was with the WinAMP media player from NULLSOFT. They designed their application in such a way that any given part of the application could be interacted by any third party — while they enabled the following interface interaction:

  • Input files — Enabling the player to recognize many additional file types, not always the ones that were defined by default.
  • Output Devices – Enabling third party to define new output devices, so that the application will support addition ones other than the default Stero types
  • Filters – Enable different audio filters to be defined,

And so on. They defined the application in such way that the interaction included elements such as a skin style for the GUI of the application, something that until then hasn’t been done in such way.

Microsoft API definitions – By chronological releases
Microsoft initiated a set of wrappers when they found the need to do so, and saw the demand from third party developers. Way back on the early days, when there was the MSDOS, and the first Windows — the definition of wrappers was only in its first stages. In the coming years they defined various types of API wrappers for applications. Here is a short list of some that were defined:

This is a vast area, that was defined by Microsoft — and produced many great subproducts., The introduction of the DDE and COM/DCOM, enabled companies to wrap their product as a defined product, and market it to be used by software developers.

The DCOM, enabled the wrappers to be put on a remote machine and launch their task from that machine. Using a Client/Server programming abilities. Yet, all interface to a DCOM object is, mostly, as if it is a standard COM automation object.

As for the developers they had — when interacting from their code — to the blackboxes — to know the basic structure and method of assigning and mapping their application, with the blackboxes they got. Unifying this ability — produced a vast market that could use different ideas.

Google API
As I see the software market, google initiated a set of API for their products (which were mostly web based) as they learned from the existing companies and tech history.

Google viewed the market from a software developer view point. This enabled them to define the API and different interfaces in a way that will be easy for other software engineers to interact with.

On their developers site, you can find many different API to their product. Due to the fact that they became a huge and dominated company in the market, the list of API is parallel to their products services (search engine, mapping, cloud, office products [documents, spreadsheets, presentations], translate engine, social plus services — the list just getting larger as the time goes on).

Google web orientation, required a definition of the interaction with the different services to be done via the web itself. If the beginning of the API definition was done locally, on a single machine — as interaction better one local application to another local application, that ran on a single computer. –> the definition of the google services was shifted to a web based alike connection between each application. As different application ran on different machines, connected by the internet –> done, usually, as client/server based applications.

The web interaction, required a definition of some sort of structure of when passing parameters to process/or receive — This produced a variety of structures on different layers — as structured data elements (such as XML – Extensible Markup Language, or descended that enhanced it — such as KML – Keyhole Markup Language for mapping services for example) — or different definition  of structured language on the transport layer — (such as communication using JSON JavaScript Object Notation – data structures)…

 

Mobile and cross platform API

When mobiles came to existence, many possibilities and enhancements were introduced.

Today, when any application is written — people who know the market and programming will try to cover the following on their first, or later, releases of the application:

  • A desktop machine application (Whether it be a linux, windows or mac machines)
  • A mobile application (Whether it be an Android, Windows, iOS, or other platforms)
  • A web based application (A web based access to the data or services one provides)

There are many examples of such applications from different companies, that offer their services cross platform on all the above points I’ve mentioned. Again the best place to view such cross platform services, is on google products. Yet examples can be found on many other pinpointed services, such as the services of a Cloud Drive (you can check DropBox, OneDrive, GDrive, and others). Or other services such as EverNote.

A good company will expose their services to an existing ISO defined API, or a unique proprietary API. Again this varies on the company and upon their knowledge that they must produce such a feature so that coders will  act as a leverage to boost their product and services.

The new RAD Delphi XE6 was released

Note, this blog states the obvious.

Again I find myself in the process of waiting/reinstalling the new versions of the miscellaneous components — the I’ve bought. Each company got its own pace of releasing their updated set of components to their subscribers.

Some of them, got a hand of the beta testing of the RAD Delphi, and start to modify their components code, even before the official release of the development environment.

On other cases such as the Delphi Jedi Component Set — The  process seems to be a work in progress all the time. Due to the fact that it is defined as an opensource project. So many bugs, and improvements are being fixed, and added/modified almost everyday.

Yet, nowadays, that there is the Web, and all the social networks such as twitter/linkedin/facebook and so on — It seems that the wealth and variety of the set of libraries I come to find each and everyday, are much  more than what I thought there would be.

So It is good to get updated with many new tools, and utilities. You can call me a compulsive sourcecode collector. And due to the fact that I like the most the OOP with Pascal — I find everyday, new ways of coding in the same language that I happen to grow up with.

I didn’t had the chance yet, to cover all the different modifications that were added to the RAD Delphi XE6 —  itself… Though, I ran a couple of sample demo codes. I’ll be at this in the coming days.

Podcasts RSS: Aggregating Video/Audio/Podcasts

I thought for a couple of days what to write about, due to the fact that nothing much kept me busy… Though, I came to a conclusion that I’ll write about what did keep me going on all these days.

For the past dozen years, I’ve been hearing many different daily Podcasts…

So what is a Podcast?

A Podcast, is basically a media file (can be audio or video) which is being attached to a RSS (Really Simple Syndication). The RSS with the combination of the media file, makes it a very power full technology. That because different Feeds are being updated daily or weekly.

The programs that manage the different feeds (Podcasts Apps; such as Apple Podcasts app [on iOS] or Samsung KiesCast app [on android]), you listen to — know 🙂 but their definition whether it is a new item, or an old one… Thus notify you for the new ones.

History of RSS…

The RSS first was invented for Text news… News Feeds, were common, yet, attaching a video/audio file to it was a latter invention.

More about Audio Podcasts:

There are some more features which were added to the Feed,. and can be supply attached to the RSS Feed it self, or to the media file which attached to it.

Meta Tags:

Take for example the Meta Tags.

When adding an item for a feed, it includes a text which describe the current item (of course these additions should be supplied in such a way that the miscellaneous Podcasts apps aggregators would know where to look for that data).  Due to the fact the the RSS was derived from XML (Extensible Markup Language) files — which is a structured text file, with different variables with in it — It can contain many different Meta Tags.

In addition misc meta tags can be attached to the media file itself. For example a .mp3/.m4a audio files contain a structure that define the file meta tags. And their meta tags can include many different known, or user defined tags. Such as; Track Name, Year Published, Author, Lyrics, Picture Thumbnail — Icon of the track, and so on.

Different Sources of RSS Podcasts:

Today any news organization which respect itself got a team that compile a hourly/daily/weekly podcast. After all, all you need to create a podcast — it the knowledge how to construct the basic feed, and some hardware such as microphone and a recording application… And of course some content to talk about whether it’ll be global news/ Tech news/ Expert news/ Art news/ or any area which interest you.

My personal daily news:

I’ve been listening, as I mentioned, for the past dozen years to news via different podcasts apps, and being fed news from different sources. This of course is a routine change from the past — instead of  gazing on a TV screen — I am now free, to hear news — what ever — when even — and where ever — I like.

What Ever; Pick from the billion of podcasts sources online.

Where ever; I can hear news while doing the daily arrangements around the house — when doing the dishes, or any other tasks.

When Ever; Feeds by different sources are usually kept at least for a week and on many cases for years back on different sources. So even if I missed something, or if I would like to listen to new content to me — I can search it years back on the source WebSite.

Or for short the podcasts WWW 🙂