Battery charging circuit of DS3231 module

 Author:   Posted on:    No comments

I'm working on a project which requires an RTC clock. So I decided to get a module, since my project is based on a development board with ATmega328. The cheapest and most available module is a small PCB with "ZS-042" printed on it. Besides DS3231 realtime clock IC, it also includes an I2C EEPROM (24C32). Both share the same bus lines. The module is shipped without a battery. Product description (on AliExpress) mentions only LIR2032 battery and 5V supply for the module. They even say that it does not ship with the battery and that's not a big deal since it costs only "0.01 dollars". Really?!

The reason I chose DS3231 is because I need 3.3 V compatibility. I'll be using other peripherals which support 3.3 V only and ATmega328 will run at 8 MHz. RTC datasheet confirms DS3231 is 3.3 V (and 5 V) compatible. But the module specifications say you should use 5 V. I began wondering if there is something else that made sellers say this. In this post I will answer two questions: can ZS-042 operate at 3.3 V and what type of battery should you use (CR2032 or LIR2032).

ZS-042 DS3231 Module

ZS-042 DS3231 Module

Versatile LM317 power supply project

 Author:   Posted on:    No comments

An adjustable power supply is mandatory lab equipment for those who regularly deal with electronics circuits. One of the most popular integrated circuit for linear power supplies is LM317. There are countless power supply projects using LM317. This one has some additional features. The usual output voltage of LM317 cannot be lower than 1.25 V. However this circuit uses an additional negative power supply derived from the same transformer winding. With this, you can pull output voltage down to 0 V. The PCB also contains an additional power supply, with fixed regulator. Its purpose is to supply power to a custom made panel voltage and current meter. But you can use it to power a cooling fan if you want.

Versatile LM317 power supply project

LM317 Power supply built PCB

Configure Mosquitto™ broker with TLS certificate

 Author:   Posted on:    No comments

Following my previous post, you should have now a running Mosquitto based MQTT broker on your OpenWrt router that listens on port 1883 for unsecured clients and on port 8884 for TLS PSK clients. But that's not all. I want to have the broker listen to 8883 port for TLS certificate secured clients. I will use this port for remote clients over the internet.

Of course, the port can be used for local clients that support TLS. This is the highest level of transport encryption available. It's the same encryption used by HTTPS. When you (your browser) send a HTTPS request to a server (website), the server responds with its certificate and public key. The browser has a database of trusted certificate authorities and if the authority that issued the received certificate is in that database, browser will trust the server and will respond with data encrypted with the public key. Server decrypts data with its private key. Client and server will negotiate a one time key that will be used throughout the session.

Configure Mosquitto™ broker with TLS certificate

Install and configure Mosquitto™ on OpenWrt

 Author:   Posted on:    2 comments

The previous post was about MQTT security layers, the advantages of running a local MQTT server and how may a network of things be structured. The OpenWrt router should be ready to install and set up the server (broker) software. The software repositories contain two variants of the Eclipse Mosquitto software. One of them is built without SSL support. If you install that one, you won't be able to accept secure clients. The SSL enabled variant requires a bit more internal storage space and that's the main reason they provide both builds.

I'm using a router with Broadcom SoC and 16 MB of internal storage. There's still 86 percent free space after installing Mosquitto, the SSL enabled build. In this post I'll show you how to configure Mosquitto broker to listen to multiple ports and to accept clients with different security settings. This is because not all microcontrollers with network connectivity have enough processing power for TLS/SSL. And, as I said in the previous post, the devices in your local network are behind (at least one) firewall, and as long as no one else has physical access to the network, transport encryption between MQTT clients and server is not really needed. However, TLS/SSL is required for remote clients, over internet.

Install and configure Mosquitto™ on OpenWrt

Run a local MQTT broker on OpenWrt router

 Author:   Posted on:    No comments

Nowadays, microcontrollers with internet connectivity are cheap and popular. Actually, not quite internet connectivity, but network interface (mostly wireless). Also, to those MCUs that do not feature this, you can connect various network or WiFi modules (known as shields). It's now easy to connect almost anything to the big network starting from a simple LED or relay.

There are plenty of projects on this topic. Most of them make use of development boards based on Espressif platform, because they are cheap and have built-in wireless LAN connectivity. An you can run basic web servers on these that offer a web interface where you can display or change parameters from any device with web browser. But that's not what everybody needs. Sometimes, the development board is just a member in a network that includes other things too.

A common protocol was needed to allow communication between devices in the network of things. Actually, one has been around a while, way before these development boards became so cheap and available. It's the Message Queuing Telemetry Transport protocol (or MQTT), which is now an ISO standard. Used wherever small amounts of data needs to be transferred, it works on top of TCP/IP.

Run a local MQTT broker on OpenWrt router

Arduino: interrupts in class and callback functions

 Author:   Posted on:    No comments

Arduino is a popular open source electronics development platform. The programming language is nothing else but C/C++. The predefined Arduino libraries provide easy to use functions for most usual tasks, like writing and reading to MCU pins, data transfer using common protocols etc.

If you're working on a complex project or you are developing your own library, chances are you are creating new classes. That's because a class can contain member data (just like data structures) and member functions (which modify, process or generate data). Access to class members is usually governed by an access specifier. Private members are accessible only from within other members of the same class, while public members can be accessed from anywhere where the class object is visible. This is the C/C++ programming language. If you're not familiar with it I suggest starting with this tutorial about classes.

Arduino: interrupts in class and callback functions