Nucu Car Devlog: 0x03 – Android

Hello everyone!

I’ve been working lately on my little project involving Raspberry Pi and .NET, during my free time. Now, I’ve introduced a new technology, Android!

The project needed a front-end and It took me a long time to decide how to implement it and what technology to use.

I was conflicting between a cross platform desktop application or a web application. I initially thought Electron would have been a great choice since it covers both, but it doesn’t work out of the box with gRPC and I needed some proxies which complicated the things on the backend, not to mention JavaScript is horrible in every imaginable way.

Luckily for me, I started dabbing in Android and somehow I manage to get a simple activity up which reads the data from the NucuCar.Sensors component.

It connects to it via gRPC directly. I didn’t expect that setting up gRPC on the Android would be so easy to be honest, you can literally just follow the gRPC tutorial for Java and everything works.

Getting that to work got me motivated and I’ve fixed some bugs in the NucuCar.Telemetry component. This made it possible for NucuCar.Sensors to run for four straight days, non-stop without crashing, it’s still running at this moment.

The component reports sensor reading to Firestore every one minute, since there are 24h in a day it reports around 1.4K readings a day.

At this point I’m pretty proud of this project, I wrote a simple Python script to plot the Temperature, Humidity and VOC resistance from my apartment, for the last 3 days:

As you can see the spikes on 2020-11-28 12:00 indicate that I’ve opened the windows and let some fresh air come into the apartment. The temperature and the humidity dropped while VOC resistance rises. The higher the VOC value the better the air quality.

This project is open-source and it can be found on my Github profile.

Thanks for reading!

Nucu Car: Devlog 0x02

Hello,

I’m still working on my NucuCar project from time to time, I’m currently at my parents home and I left the raspberry pi at my apartment so I’m only testing the builds it on my computer. Luckily I can test the telemetry by using the CPU temperature sensor implemented by dotnet IoT.

For the next step, I wanted an effective way to store telemetry data in the cloud, preferably for free, since this is a hobby project after all.

After testing multiple solutions I’ve settled with Firebase, I tried to write a telemetry publisher for it using it’s SDK which internally uses gRPC and everything went well until I put it on the board. It turns out that dotnet gRPC doesn’t work on raspberry pi. I got the basic server working using a hack but that’s about it, so I moved to the REST API and I’ve implemented a simple translator which translates raw C# dictionaries into compatible Firebase RESTful post request Json payload.

The project got a little bigger and at the current state it was quite messy, a restructuring is needed and this is what I’ve done:

NucuCar.Domain

Initially I’ve designed the NucuCar.Domain project to contain .proto files and data classes without too much implementation, however, many Telemetry Publishers such as Azure, Disk were in this package and it was kind of wrong because they contain too much implementation and they were dependent on heavy external packages and they would bring too much of a burden.

The TelemetryPublisher abstract class and the ITelemeter interface both which don’t contain implementation remained in NucuCar.Domain and the concrete publishers along with the worker were extracted in NucuCar.Telemetry.

I’ve also extracted the Firebase translator into a package of it’s own, and published it on NuGet, making this my first published package. 😀

NucuCar.Common

In NucuCar.Common, I’ve moved some of the classes which were utility classes and were still present in NucuCar.Domain, the ConnectionParser class and a class which provides basic argument guarding.

Another thing that I needed and I’ve implemented in NucuCar.Common is a HttpClient wrapper class, I found very verbose to serialize Json every time and deserialize it when sending data to Firebase.

Thus I made a simple wrapper to simplify the process, while also introducing a retry mechanism and cancellation and timeout support.

Conclusion

Overall I’m quite happy with the end result and I’m looking forward to see what interesting things I can implement in the future.

I’m not sure if I want this to be a remote controlled toy car project anymore, it sounds good but I think it would be more practical If I could connect multiple sensors, create a simple interface and monitor my apartment using this, perhaps add some support to automatically water my plants, that would be nice.

The project is open source and can be found on my Github.

Thanks for reading!

Nucu Car: Devlog 0x01

Hello everyone,

A while ago I started working on a pet project called NucuCar. It’s a platform written in .NET for the Raspberry Pi in which I’m trying to implement various utility functions to create a complete piece of software that can be used to build a remote controlled car for the Pi.

The project is open source and it can be found on GitHub: https://github.com/dnutiu/NucuCar

Since I didn’t buy a toy car and I don’t have much space in my apartment I was working only on the sensors module, which currently has support for the BME680 environment sensor and the CPU temperature sensor build in the Pi.

The idea behind this is to make a daemon that polls the sensor, publishes telemetry data and can be easily configured. This is the configuration file:

The Telemetry block configures which telemetry publisher to use Azure or Disk (for the moment, can be extended) and the interval in which to publish the telemetry data. The other two blocks configure whether the sensors and telemetry collection is enabled or not. That’s about it.

To develop this I’ve been using Github, a free Jira instance and JetBrains’ Rider.


Running on the Pi

I’ve build the project and uploaded it on the Pi, running it will all the options enabled yields the following htop result:

We have lots of processes which are in interruptible sleep, about 7.8% CPU time which went to 0.7% after a while and around 5.5MB or ram usage. That’s not bad, considering that we’re running C#. Oh, and I forgot to mention, the BME680 sensor is exposed via a gRPC server. 🙂

Telemetry Data

While running the program, the telemetry data from the sensor was collected and saved to the disk. Here’s how an entry looks like:

{
   "source":"NucuCar.Sensors",
   "timestamp":"2019-12-01T23:26:13.5537227+02:00",
   "data":[
      {
         "sensor_state":2,
         "temperature":32.65558333857916,
         "humidity":100.0,
         "pressure":62228.49565168124,
         "voc":0.0,
         "_id":"Bme680-Sensor"
      },
      {
         "sensor_state":2,
         "cpu_temperature":48.849998474121094,
         "_id":"CpuTemperature"
      }
   ]
}

Then I wrote a Python script to plot the available data, skipping the first 10 results.

Thanks for reading!

References:

My experience with .NET IoT (so far)

cover

I haven’t done any embedded development in a while and I was thinking to build myself a remote controlled toy car with video streaming.

The project is going to take me a while. To build it I’m going to use C#. I’m already too familiar with Python and a little challenge doesn’t hurt.

To interface with the hardware, I’m going to use the .Net Core IoT Libraries from Microsoft.


My idea was to create a set of .Net Core services that communicate internally via gRPC and an ASP.Net Core web application to control the car. (Now that I’m writing this I’m thinking that could possibly drop the web app and use gRPC directly from the client).

The client would be a desktop application that will display the video stream and data from the sensors. It should work with an Xbox controller or else it won’t be fun. 😦

To write it I will probably use Mono or Unity.


After burning the latest version of Raspbian on the board using Etcher and spending a few hours in Rider developing a base for the app. I’ve Installed .Net Core 3 SDK and ran the application. The results were amazing! I’ve checked the thermostat in the office and it was set on 25

readings

And the application only consumes ~10MB RAM! That’s awesome!


I’m really impressed and so far things are looking bright for dotnet/iot. I can’t wait to test the gRpc support and other hardware modules.

The full code can be found here: https://github.com/dnutiu/NucuCar

If you want to run the app on your Raspberry you’ll need to install the .Net Core Sdk (Instructions) and run the following commands:

git clone https://github.com/dnutiu/NucuCar.git
cd NucuCar
dotnet build
cd NucuCar.Sensors
dotnet run


Thanks for reading!

I hope you will give dotnet/iot a try for your next project!