Wednesday, April 6, 2022

Make fun things with your home IoT devices, securely over the internet.

I am planning to start a series of posts discussing how to put your IoT devices in the internet and do fun stuff with them. I will provide them as GitHub Wiki pages and I will also provide code and scripts when this is possible. This page will act as a placeholder.

Interact using Alexa with your IoT devices

In this first post I am using the excellent, free, Cloudflare Tunnel and I make my Raspberry Pi accessible over the internet using a custom domain and HTTPS. Only with a few clicks and no cost (apart from the cost of the domain name).

Then I provide an Amazon Alexa Skill that can be used for interacting with your Raspberry Pi using your Alexa device! In this simple example, I am implementing a simple REST API which is invoked using voice commands.

Have fun!

Monday, August 10, 2020

Create a JWT singed with RSA private key in .net core

The following example is a snippet of a C# code that generates an RSA private key out of a .pem file and uses it to sign a JWT. The privateKey variable, stores the contents of the .pem file minus the "-----BEGIN RSA PRIVATE KEY----" and "-----END RSA PRIVATE KEY-----" lines.

string privateKey = @"
byte[] RSAprivateKey = Convert.FromBase64String(privateKey);
RSA rsa = RSA.Create();
rsa.ImportRSAPrivateKey(RSAprivateKey, out _);
var jwt = tokenHandler.CreateEncodedJwt(
   issuer: "...",
   audience: ...,
   signingCredentials: new SigningCredentials(
     key: new RsaSecurityKey(rsa),
     algorithm: SecurityAlgorithms.RsaSha256)

Thursday, April 9, 2020

Deploying smart contracts to ganache using python and web3

Ganache is a useful tool that emulates Ethereum blockchain in your local machine and it is very practical for testing smart contracts. Most tutorials explain how to deploy a smart contract in ganache using truffle, which is a development framework by the same company. But this is not necessary. Here, I explain how to write and compile a contract using Remix, and deploy it using python and

Write your smart contract in remix and compile it. Then press the "ABI" button on the bottom left (see picture) and paste the output in a file. This will be our ABI_file. Do the same with the "Bytecode" bottom. This will be the bin_file. Then you can use the python script from this github repository. Make sure you have installed the dependencies and that you have modified the ABI_file and bin_file variables of the script accordingly.

Sunday, May 19, 2019

CoAP POST using libcoap

View a list of all libcoap examples here.

This example includes a CoAP server and a CoAP client. 
The client performs a CoAP POST request for the "coap://" resource. The server listens on port 5683 (default port) and prints the POSTed data

You can find the source code of this example, as well as, instructions for compiling it in Linux in this github repository, in the "post" folder.

Friday, November 25, 2016

A CoAP server for the riot operating system using libcoap

View a list of all libcoap examples here.

The riot operating system ( is an operating system for the Internet of Things that currently supports many platforms. One of the main advantages of riot is that it supports programs and libraries written in C including libcoap.

In this github repository you will find an example of a CoAP server for the riot operating system This server implements a default resource that outputs "Hello World!".In order to test the example, download the latest version of the rios os (, create a folder inside the examples directory and copy the code from in that new directory. Then from a terminal type
$ make

If you encounter any problem, consult this riot wiki page In order to use the example you have to create a virtual interface in your linux machine. In order to do this invoke the following utility:
$ <riot directory>/dist/tools/tapsetup/tapsetup -c1

This utility will create a virtural interface and a bridge (for more information visit this wiki page After this step, from the folder where you have put the example code invoke:
$ make term

This command will execute the binary created in the previous step and soon an ipv6 address will appear in the terminal. You can now access the coap server using the libcoap coap client and the displayed ipv6 address, by invoking the following command:
$ coap-client coap://[<ipv6 address>%tapbr0]

Tuesday, September 6, 2016

Asynchronous CoAP request-response using libcoap

View a list of all libcoap examples here.

This is an example of asynchronous request-response. The server listens on port 5683 (default port). When it receives a request for the "hello" resource, it sends and ACK and after 2 seconds it responds with a "Hello World!".

The client performs a CoAP GET request for the "coap://" resource and prints the response.

You can find the source code of this example, as well as, instructions for compiling it in Linux in this github repository, in the "seperate" folder.

Sunday, July 17, 2016

libcoap examples

libcoap is an open source C implementation of the CoAP protocol. It can be used for developing CoAP services in Linux, MacOS, as well as, in various IoT operating systems such as Contiki, LwIP, and TinyOS.

However, libcoap lacks  documentation. Apart from some installation instructions there is not any tutorial on how to use the library. Moreover, the examples included in the source code are very complex and they cause confusion. I have constructed a small set of examples that use libcoap to perform simple tasks.

All examples are available on github

List of examples