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:

Objects Indexing – Image Processing

I wrote a short draft of an idea for a mobile multiplayer game. Writing that raised an idea of algorithm which would be required in different applications when processing an image and deconstructing it  into separated objects:

Scenario description:

Imaging you got a picture which you would like to know where each object is indexed in this big image. (For example, a picture where a collection of people holds their mobile device,. and an application should ‘know’ who is behind each one of the mobiles — and index it accordingly in the big picture).

Each person holds his device, and in front of this group of people, stands the ‘server’ device, which is required to picture this group, and index (or moreover, communicate to each index accordingly)..

Of course solving that could be done easily if you got the big picture. Yet, for some reason I thought of another complex (or easy way). If each person is holding his device,. and all devices are connected to the server — the server can communicate to each index by identifying it — initially — index it, and then send each participant the required data.

  • I thought of an art work, where this group of people and mobile devices, could function as a live ‘Music Scope’…
  • or, think of a stadium where each person holds his device,. and then the server, runs a live mosaic picture, where each mobile screen takes part of this image.

Code archaeologist

As a obsessive code collector,. form an early age. Today as I didn’t sleep all night. I decided to  sort the old floppies I still had, and arrange my old basic programs.

I can not tell from what year it is, cause on those days programs were brand new, and even the GWBASIC we had those days didn’t save the datetime of the creation of the file (or was it the old DOS, can not remember exactly). It was from the late 80ies — something like 1987~1989…

Anyhow, had to create an Oracle VirtualBox of DOS6.22 — and create an .iso disk associated with it containing my old basic code. Due to the fact, as I said, that I am a collector of software, GWBASIC was at hand.

Had to ‘LOAD”…”‘ and ‘SAVE”….”,A’ all about 60 code programs. This command loads the GWBASIC code (which was then, stored in a binary form on the file structor). And ReSave it using the ‘,A’ flag, which mean save as ASCII.

I went back then from learning basic, then c, and then pascal and cpp. So I had some C and Old Pascal code stored as well.

This is what I call ‘Code archaeologist digging…’

BOINC back

The last time I ran the BOINC engine was in 2007. Now I’ve started running it again. BOINC is a Berkeley application manager for distributed computing. To describe the process very shortly you take a big task, cut it to small chunks, send each client at the end this chunk to be processed by him.

Usually many science related or research in a given topic, produce huge amount of digital data. Yet, in order to process that in a reasonable time, you can use this type of computing.

When BOINC initially running boinc, you can choose from a variety of projects to run from health related application, to cosmological projects.

Now-a-days when the mobile was introduced, there have been some applications for mobile (that does the same process) released for the public (i.e., BBC article on the subject)

Thing is that since the last time I ran it,. they have now added a procedure where a Virtual Machine is attached to a given project you run on the system (in our case they used the open sourced Oracle Virtual Box) — enabling the tasks to be ran on a given light version of Linux machine…

Here is a fast summary of the path it takes (after all initialization of the software has been done):

BOINC download a chunk of data –>
a VM is being ran by BOINC –>
procedures are being processed under that VM –>
Results are sent to the server back

Which is really cool seeing and understanding that,.

You can configure the system to be ran while in idle mode, on a screen saver (which shows a related data plot of the given project).. for example, if you run a ‘Quake Identification Project’ it shows you the globes with the different variable which are processed on your machine.

If you got a machine and would like to contribute to this processing power.. check the links I’ve gave in this article. That way you would know you are truly assisting to science  and our globe space ship…

Perspective of life – the fifth decade – by Nighthawk

It suddenly came to my brain, a reasonable explanation of this Human race acts, that we all participate in. I came up with these insights, whether they apply just to me, or you might find it useful as just another view point of life – that would impact in some way your way of thinking and view.

On past decades, I participated in this hectic race to the way up… I had a proper job, which I liked… and had a very tight social life (not as wild as other people got, but something reasonable).

Then on the forth decade of my being, I suddenly had a ‘life bump’ which halted all that I was doing before. And stopped the routine I had – almost making me reach a stop still place, it wasn’t a physical stop still – it was mental stop still.

 Subjective feeling of talk time:

Today, as I was listening to several different radio shows… It knowledge has impacted me. While each show was about an hour, one show seems to be shorter than the other one… it made me think, then I finally got that; people that do not have time to their selves, and are in a complete battle with life, would extended talks would somewhat sound shorter, than people who are at peace with life – and would like to share their moments with others.

It wasn’t the first time, I felt that.. Sometimes people who I talked with although talking to different people the same absolute time, would feel to some longer, and to other shorter.

Of course, all people like to share… yet, some people got their personal goals, which doesn’t match yours. And would like to benefit from these talks. And manipulate you into thinking this way or the other.

Another important thing is that when one have common shared knowledge, for example if you are an expert in this or that area,. And the other side, would like, know, or interested in the subject at hands subjective time passes slower… enabling one to celebrate the sharing and talk.

To sum this view, people who do not have time for themselves, or to other – why would someone have time to even hear what they want to say. People who are at peace with themselves, and with others would impact ones soul much more.

Jobs and the social disruption:

On prior decades, I was in a race, I didn’t have time! I was always ran after things to accomplish… And although from now and then, I stopped to hear I didn’t listen much.

Any job which require both sides to stop and think, and accomplish a creation – or a solution to a given problem – doesn’t just disrupt — it creates. It slows the whole system a little… because it requires attention from the people who accomplish it.

One shouldn’t take that as ‘Hay you are slowing me down..’ but as ‘ok, that requires a creation…’ – which is a task to make which benefit the larger society – to enjoy later – in whatever area it concerns.

Learn:

It doesn’t matter what you learn, as long as it benefit the bigger picture. It doesn’t matter either how you learn… You can watch a movie or listen to music, and learn while enjoying yourself.. come up with different conclusions – and make you think in the process.

Enlarging your common knowledge is always a good thing. It is better to hear and understand things, that just run in circles. Same basic ground would benefit the bigger picture…

Do not come up to hasty conclusions:

Somethings, things look wrong, crazy or without any meaning… only after a given time – things would fit into the bigger picture. And would look synergetic with their environment.

Enjoy life:

Whatever subjective way you like to enjoy and celebrate life, is good. As long as it doesn’t hurt anyone. One can find even very simple routine procedure enjoyable at times. When you invest in your joy, and expertise, to tend to share the solutions or knowledge in a much more tender way… and not being uptight with time, and life.

Just another WordPress site