Tag Archives: Delphi

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 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;

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.

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.

RAD Delphi/CPP XE5 was released

Before I could even start some apps on beta7/beta8 — the official release of XE5 came out.

The most “in the face” feature is the very impressive integration of the RAD XE5 to the different environments (Win8/iOS/Android). It enables the developer to seamlessly connect the mobile device  or emulator that the app would be compiled on. And run the application.

I didn’t yet, dig enough into the twiks of each system. Of course each platform and device got its own sensors with-which you can program an app to.

All programming for the mobile EcoSystems, is being done using the FireMonkey FMX. Which is an OO environment. And if you check the source code of the FMX, you’d find a FMX.Platform.{PlatformType}.pas that is functioning as an encapsulation of the ecosystem basic function.  the {PlatformType} is one of the following by default: IOS, Win, Mac, Android.

Platform.IOS:

The integration to the iOS got a procedure where you automagicly sync the current XCode headers to be used by the DCCARM on the RAD OOP environemnt. This procedure is being done once, and could be repeated when a new version of the iOS is out.

All code-signing, and device deployment for the iOS is being done using the existing Mac XCode environemnt (when dealing with key-chain codes, and provisioning profiles — this is a procedure every Apple developer know, and is well documented in Developer.Apple site.)

Platform.Android:

As for the android platform, because of the fact that it is an open source OS. Embarcadero decided to ship the RAD environment with a deployment of the android SDK/NDK. So emulation and use of tools is being done using them.

When connecting a new android device the RAD automatically detect it and can compile code to the device itself.

 

APNS – Apple Push Notification Server

I’ve updated my code on the iOS client of the “Apple Push Notification Server”. With its companion the Server side. This version of code was written in Delphi, for windows desktop environment — and I’ve enhanced it a bit. Had to understand the thingies with the signing and all the procedure.
If you are in the progress of building one yourself here are my notes on the subject:

  • Make sure you are consistent with the type of app you are developing. Basically there are two kinds: Development & Production (Distribution). What ever you choose note the following assignments:
  1. Code sign your APNS with the proper type (DEV/PRO)
  2. Assign the server to be connected to the proper gateway:
    A. gateway.sandbox.push.apple.com:2195 – for DEV
    B. gateway.push.apple.com:2195 – for PRO
  3. Make sure your type is consistent to the client side (DEV/PRO) – The type of kind will produce a different value for the client APN Token when registration the client on the server side.

I’ve created a NotificationPanel for my windows desktop machine. Yet, it isn’t as fancy as the Apple/Google ones. But it inform me on different messages that I’ve connected it to. I’ve registered it as a COM AutomationObject, so it could be used in Microsoft VBA scripts, or similar applications.

One of the features of that code is the ability to send a message via my APNS registered server.

I am still trying to figure out, why not all of the messages being sent via the APNS reach the client side. I do not know where it actually fails [Client or Server side].

In addition there is the issue with the APNS feedback system (feedback.push.apple.com:2196) which I didn’t manage to verify its function. My version of code, for it, doesn’t seems to receive and feedbacks — whether messages has been sent properly or not, and if not — what is the exact reason.