A blog about my life, development and projects

Atlantic Challenger – RPM sensor unit

A while back I started to create a sensor unit for my husband's Atlantic Challenger remote control model boat. The objective was to monitor the RPM of the motors, the temperature, battery consumption and current draw on the batteries.

The current project only has RPM and Temperature, but I will soon be adding the rest of the sensors. I kept the scope of the project as little as possible in order to first test and make sure that it all works as expected.

Hardware:

  • 2x Adafruit Feather 32u4 + LoRa 868mhz
  • 2x Line Follower Module - TCRT5000
  • 2x 18B20 Digital Temp Sensor
  • 1x LiPo 1200mAh 3.7V Battery

The RPM and temperature sensor unit is developed in such a way that the sensor values can be read over a long distance. The initial project was done using a WiFi chip that resulted in the device losing connectivity when the boat is out on the water.

This current sensor unit is using a 900mhz "Long Range (LoRa)" packet radio that can send the values from the sensors over a distance of up to 20Km. This enables the user to keep an eye on the boat’s performance from the shore line.

The RPM values are read using a Line Follower Module which consists of an IR transmitter and Receiver that can pick up the presence of a dark object passing before it. On the motor shaft a small arm has been attached that passes by the sensor every rotation. Using this the RPM can be calculated by counting the number of rotations a minute.

The values read from the different sensors are then transmitted using the LoRa radio. On the receiving end another LoRa radio receives the sensor information and then just writes it out to Serial. This enables any device with a USB port to read the values and display it. In this case a C# windows application is used, but this can easily be a mobile application, linux application or even a TV.

All the code have been made available on GitHub should anyone be interested to see how it all comunicates:
https://github.com/TechnoDezi/AtlanticChallengerSensorUnit 

Ionic Native HTTP

About a year or so back I created a mobile application for a client that was based on Ionic and was asked recently to add SSL pinning for security reason. During this I found and interesting behaviour that isn't very well documented and took me a while to discover.

In order to add SSL pinning I had to change the Http service calls from using Angular HTTP to Ionic Native Http. Everything was all good untill I had to make service calls.

But first, what is SSL Pinning: 

By default, when making an SSL connection, the client checks that the server’s certificate:

  • has a verifiable chain of trust back to a trusted (root) certificate
  • matches the requested hostname

What it doesn't do is check if the certificate in question is a specific certificate, namely the one you know your server is using.

Relying on matching certificates between the device's trust store and the remote server opens up a security hole. The device’s trust store can easily be compromised - the user can install unsafe certificates, thus allowing potential man-in-the-middle attacks.

Certificate pinning is the solution to this problem. It means hard-coding the certificate known to be used by the server in the mobile application. The app can then ignore the device’s trust store and rely on its own, and allow only SSL connections to hosts signed with certificates stored inside the application.

Adding SSL Pinning to an Ionic application:

The Ionic documentation is quite limited when it comes to examples. You can find it here https://ionicframework.com/docs/native/http/

Step 1: Install the required packages

$ ionic cordova plugin add cordova-plugin-advanced-http
$ npm install --save @ionic-native/http

Step 2: Add the plugin to the apps modules

import { HTTP } from '@ionic-native/http';

...

@NgModule({
...

providers: [
...
HTTP
...
]
...
})
export class AppModule { }

 

Step 3: Set SSL pining before making the HTTP service call

this._http.setSSLCertMode('pinned');

 

Issue 1: Now that SSL pinning is set, you can make the service call right? Wrong, the 1st issue was to actually specify the SSL certificate to use. The documentation didn't specify where the certificate should go, or what it should look like. I ended up creating a ".cer" file that consists only of the Public key (Please never distribute your private key). This certificate file I added to "/src/certificates" in my project. After this I had to update my Ionic asset copy to copy this file to "www/cerificates". Sure you could just add it directly to this folder, but I wanted it as part of the build in order to easily change it later on.

Now that the certificate is added the http calls started to work as expected. But some of the calls were still failing which leads to Issue 2.

Issue 2: After adding SSL pinning, the cerificate, and updating all my service calls from angular Http to Ionic Native Http some of the service calls were still failing. After some debugging, WireShark traces I discovered that Ionic Native Http by default sends all post requests as "application/x-www-form-urlencoded". This was fine for the basic calls as .Net Web Api can handle these things, even if it's expecting Json Rest calls, but the complex types were failing becouse they weren't parsed corectly.

The solution to this was simple. All I had to do was to set the Data Serializer for Ionic Native Http to Json. I wasted a lot of time on this which could have been solved if it was in the documentation, but here it is now for anyone else if they battle.

this._http.setDataSerializer('json');

 

Free SSL certificate on an Azure Website

Over the last last year it has become more and more required for websites to be secured using SSL cerificates. But what if you don't really want to pay for a ssl certificate and isn't worried about a green seal verification?

Well, all you need a a certificate from Let's Encrypt, the free SSL provider.

Last year when I tried adding it to one of my other websites it was quite a mission and there weren't much documentation on it for Azure Websites. Today I thought I would try again to add ssl to my blog, and guess what? Scott Hanselman has posted a very nice blog post on how to add this to an Azure Website. I was able to get it set up in just 5 minutes.

You can view the blog post here: https://www.hanselman.com/blog/SecuringAnAzureAppServiceWebsiteUnderSSLInMinutesWithLetsEncrypt.aspx 

I am from now on adding it to all my sites by default.

Transport/Convert SqLite to MS Sql

Happy new year everyone!

So over the last few weeks I needed to import a lot of GIS and geographical data from a .db file into an existing Sql database.

After asking "the oracle" aka Google for an option on what the best approach would be I found a few posts that led nowhere safe.
Some of the options deals with SqLite ODBC drivers then mapping it as a linked server. Normally this would not be a bad idea, but having then to write a bunch of queries to port the data over to my database just seems like too much work. Besides for that, you might not always have access to set up a linked server.

The best option that I found was a tool called "esf database migration toolkit" but it turns out that you have to buy it. With our South African exchange rate it just seems a little steep, otherwise it would have been an excellent tool.

So as any good developer would do, I wrote my own little tool. In just 4 hours I had a tool that can read the schema from my SqLite database, create the structure with the correct data types on the MS Sql Database and then transport the data for me. The tool is not perfect, but it works.

If you want to use the tool for your own project, or just have a peek at my code you can find it on my GitHub https://github.com/TechnoDezi/SqLiteToMSSqlConvert

Transport/Convert SqLite to MS Sql

Happy new year everyone!

So over the last few weeks I needed to import a lot of GIS and geographical data from a .db file into an existing Sql database.

After asking "the oracle" aka Google for an option on what the best approach would be I found a few posts that led nowhere safe.
Some of the options deals with SqLite ODBC drivers then mapping it as a linked server. Normally this would not be a bad idea, but having then to write a bunch of queries to port the data over to my database just seems like too much work. Besides for that, you might not always have access to set up a linked server.

The best option that I found was a tool called "esf database migration toolkit" but it turns out that you have to buy it. With our South African exchange rate it just seems a little steep, otherwise it would have been an excellent tool.

So as any good developer would do, I wrote my own little tool. In just 4 hours I had a tool that can read the schema from my SqLite database, create the structure with the correct data types on the MS Sql Database and then transport the data for me. The tool is not perfect, but it works.

If you want to use the tool for your own project, or just have a peek at my code you can find it on my GitHub https://github.com/TechnoDezi/SqLiteToMSSqlConvert