Connect USB from Virtual Machine using Vagrant and Virtual Box

Sometimes (e.g You are developing an IoT Project), you need to connect you board to Virtual Machine via USB Port. This post will show you steps to connect USB port from Virtual Machine using Vagrant and Virtual Box.

At the first, you have to make sure that the USB device was connected to your computer with command:

The output above shows the USB Device has VendorID is 0x1a86 and ProductId is 0x7523. So we add the lines below to Vagrantfile:

Finally, starting your Virtual Machine:

In your Linux Virtual Machine, type lsusb to check the result.

Fix UTF-8 Issue with Python Logger

When you work with Python Logger to STDOUT, sometimes you got error messages as the below:

The reason is STDOUT does not support UTF-8 encoder.

I try to google to solve the issue. And I got the solution. We have to create environment variable PYTHONIOENCODING=utf-8

So It works.

Compress/Split/Concat MP4 with AVCONV

This post just save some command that I used to edit my video. Hope it is helpful with you.

Compress MP4 with H264:

Split Video by time frame:

Concat/Join two video files:

Export video to PNG files

Create GIF from PNG files (ImageMagick):



I start studying Internet of Things

As you know, Internet Of Things is the hottest technical trend in the world recently. So we should study it. A old developers should learn it before becoming a backward guys. And a young developer should learn IOT to make the future better that today, or just simple to have  a good job.

I heard about IOT the last year.  From there,  I thought about it when i have free time. I prepared basic knowledge about IOT as below:

  • The Essentials of Electricity & Electronics
  • IOT Concept
  • IOT Architecture Overview
  • MQTT Protocol

I am a Software Developer, I always want to start writing source code after leaning a bit theory. But I do not know how to start.  So I joined Maker Hanoi ( A IOT Group in Hanoi Vietnam) and started study a IOT class for beginners there.

At the beginning, I bought a NodeMCU ESP8266 Dev Kit with price 9$ (200.000 VND)

NodeMCU ESP8266 Dev Kit

NodeMCU ESP8266 Dev Kit

I also need a micro USB cable to connect Development Kit to my computer.

Micro USB Cable

Micro USB Cable

After having DevKit, I took a look to ESP8266 Datasheet to understand ESP8266’s pins, functions. I also need to refer the image below to know Port Mapping between DevKit and ESP8266.

NodeMCU ESP8266 Dev Kit Pin Out

NodeMCU ESP8266 Dev Kit Pin Out

After the hardware was under my control, I went to the next step – studying software. I was suggested using Sming Framework to write firmware for ESP8266.  Sming Framework is easy to understand and use. However,  maybe you can have some issues with installation.

My first idea about IOT is pushing data from ESP8266 to an IOT Cloud Platform.  Actually, there are many solutions for IOT Platform. For example, I can build a IOT Platform on my own by using open source, or try IBM IOT Platform. However,  to simple and free, I chose Koor.IO – An IOT Platform for Developer.

With Koor.IO, I can have use Restful API, Websocket and MQTT. Koor.IO help me collect data and show on chart.

To implement my idea with Koor.IO, I just do the some steps below:

Step 1: Create Project

Create an account on Koor.IO and create my first project.

Create a IOT Project on Koor.IO

Create a IOT Project on Koor.IO

Waiting until Koor.IO finishing setup your project


After that, open your project, create Field to indicate what field you need KoorIO collect the data.


Now, you are done with Koor.IO

Step 2: Source code

In this step, you clone Koor.IO’s MQTTClient example.

You need to change configuration file include/config.h

MQTT_TOPIC should be project_domain/field. And field  is the field you created on, project_domain is the domain of your Koor.IO Project.

MQTT_HOST, you enter

And I entered your Wifi Information in WIFI_SSID, WIFI_PWD

Step 4: Build

After change the configuration file, We just need to build the source code and load into ESP6266 by the commands:


After build flash was successful, I go to the dashboard of the project on Koor.IO to see the data was pushed from the device. The chart is updated realtime as below.

Koor.IO - Chart - ESP8266

Koor.IO – Chart – ESP8266


With Linux,  in case you can not load data to ESP8266, you should check the connection between DevKit and your computer by command


If you did not see the logs from ESP8266. You can use screen command:

Thank you for your reading!!!


MQTT, HTTP Haproxy Configuration

If you are building a system that serves both HTTP and MQTT, I sure that you have to use HAProxy. So in this post, I will share you the way to setup HAProxy to serve Nginx and MQTT Broker.

Your haproxy.cfg file should contain the source code below:

Haproxy MQTT Configuration

Note: broker is MQTT Broker’s hostname

Haproxy Nginx

For monitoring Haproxy, You can add Haproxy Stats Configuration

Final Result haproxy.cfg



How to add SSH Keys to CoreOS

CoreOS is not same the other Linux Distribution (Ubuntu, CentOS). If you want to SSH to CoreOS by user SSH Public key, you should add the key into CoreOS by command


Using Ngrok to publish HTTP and SSH for your Rasperberry Pi

I have a Rasperberry Pi 2, and i put it in my home in the silent.  Sometimes I need to ssh to my Pi or view a website that I deployed to my Pi. I looked for a solution in the Internet. I found Ngrok. I really fitted my case. So in this post, I will share you the way to setup Ngrok on Rasperberry Pi in step by step.


Download Ngrok

You find the correct link to download at You see “Linux ARM” and get the link.

After that, you do some commands to download and decompress:

Creating Configuration File for Ngrok

We need to publish two tunnels (ssh, http). So we have to create a Ngrok configuration file to declare those services.

I create a file named ngrok.yml with content as below

web_addr: means that I can access Ngrok Webpage on my Pi via http://RASPERBERRY_PI_IP_ADDRESS:4040

I also declare two protocols and address for two tunnels – SSH and HTTP

Installing Supervisor

We need run Ngrok as a daemon (in background). So I use Supervisor – a third-party process manager. You can install Supervisor with command.

After finishing the installation, we create a Supervisor configuration file at /etc/supervisor/config.d/ngrok.conf with content as below

Running the tunnels

In this step, we just need to run the program via Supervisor by command:

Verifying your works

Now, we open the browser and access http://PI_IP_ADDRESS:4040 to get the information of tunnels and try a test.

Vagrant – Failed to mount folders in Linux guest

I usually use Vagrant in Development Environment.  I need Vagrant to create Ubuntu Server on Windows 10 Desktop. Everthing work fine until one day, I met an error “Failed to mount folders in Linux guest”.

So I fixed it by command below:

Education is the most powerful weapon which you can use to change the world

Education is the most powerful weapon which you can use to change the world

If you meet an error as below

You have to change Vagrant Home Directory to a path without spaces.


Starting a Miroservices Project with NodeJS and Docker

If you are planning to build a project with Microservices pattern and DevOps culture, you can use the source code here.

In this source code, I built two services, one for Frontend AngularJS and Bootstrap, one for Backend ExpressJS and Mongoose. All services in this project is dockerized and pushed to Docker Hub. You can read Dockerfile in each service for further details. To create a new service, you just create a new directory, writing source code for that service and update docker-compose.yml file.


The Orchestration of Project is written in docker-compose.yml file. So it is so easily to understand and run the project.

Using Vagrant and Virtualbox

We also start from Virtual Machine layer with Vagrant.

After that, you can access the application via link:

You can read Vagrantfile to understand what we need to prepare for VMs.

System Architecture

With the source code, we will have a system architecture as below

Microservices DevOps Starter Project

Microservices DevOps Starter Project


Monitor & Logs

This starter project also fully supports monitor by using Telegraf, InfluxDB, Grafana and Kapacitor. Supports centralizing Logs with fluentd, Kibana and Elasticsearch.


Part Title Git Tag
1 Starting with ExpressJS 1.0
2 Logger with Winston 1.1
4 Config Management with Node-Config 1.2
5 Building Create User API 2.1
6 Adding Swagger Documents 2.2
7 Building Login API 2.3
8 Building Get User List/Detail API 2.4
9 Authorization all APIs 2.5
10 Unit Test 2.6
11 Building Config API 3.0
12 Using Cache 3.1
13 Using Queue 3.2
14 Starting AngularJS with Yeoman 4.0
15 Config Management for AngularJS 4.1
16 Building Login Page 4.2
17 Building List User Page 4.2
18 Pagination with AngularJS and Bootstrap 4.3
19 Multiple Languages 4.4
20 AngularJS Unit Test 4.5
21 Dockerize Aplication 5.0
22 Orchestration with Docker Compose 5.1

Install Docker and Docker Swarm on CentOS7

This tutorial will show you how to install Docker and Docker Swarm on CentOS7. This tutorial is for Docker Version 1.11 and I use Vagrant and VirtualBox to create CentOS 7 in Virtual Machine.

Stop worrying about what you have to loose and start focusing on what you have to gain

Stop worrying about what you have to loose and start focusing on what you have to gain

Create a Vagrantfile for CentOS7

Turn on your Virtual Machine with command:

After finishing creating CentOS server, you access the server via SSH by command:


Go to root account:

In the next step, we will install Docker Engine following the official tutorial of Docker.

Add Docker Repository  into CentOS

Running the installation

Start Docker Service

Enable Docker run on OS Start

Docker Swarm

Installing Docker Swarm via Docker Pull

Open Docker Service Configuration file

In the line contains ExecStart, we add text as below

And now, reload Docker Service

Now we can run Swarm Node

And running Swarm Manage

Finally, verify your work


Thanks for your reading!!!