Send SMS from Raspberry Pi with USB 3G

In Digital Marketing Strategy, email and SMS are the important tools to improve your  customer services. And Raspberry Pi is a good platform to help us to implement sending email or SMS.

In this weekend, I try to send SMS from Raspberry Pi with USB 3G, and i was successful.  I used a Raspberry Pi 2 model B, and a USB 3G (I am in Vietnam, so I bought a Viettel USB 3G).

Send SMS with Raspberry Pi and USB 3G Viettel

Send SMS with Raspberry Pi and USB 3G Viettel

At the first step, plug USB 3G in Raspberry Pi, and restart Pi.
From the terminal, type lsusb command:

And using dmesg command, find ttyUSB:

If you see the output above, it means that USB 3G connection is correct.

Now, we need to install a software to help us connect to serial port ttyUSB. That software is picocom:

After that, try to connect ttyUSB1 with command:

If you see the output has “terminal ready” and you try to type “AT” and receive the response “OK”. It means that your connection is prefect. Now, you type “AT+CMFG=1” to change to “text mode”

And try to send a SMS message with command:

Finally, press Ctrl + a + x to exit picocom terminal.

If you send SMS successfully with picocom. And now, we write a Python script to send SMS message.  You can see the source code below. It is so simple.

To build a high performance SMS sender, we should apply Redis Pub/Sub to push all messages need to send to Queue.

Good luck!

Replication and Load Balance in PosgreSQL 9.4 with PgPool2

When you design a scale, high availability, high performance system, I sure that you have to apply Replication, Sharding and Load Balance technologies for your database layer. In this post, I will show you the way how to setup a load balance with PgPool2 for your PostgreSQL Master-Slave Replication.

My scenario as image below:

pgpool (1)

Step 1: Install PostgreSQL Replication for your servers

At first, Please refer to 2 posts:


After that, install Pgpool Lib:

Step 2, Install PgPool2 for server

Edit /etc/pgpool2/pgpool.conf as below:

Make sure you set enable_pool_hba = on

And change /etc/pgpool2/pool_hba.conf to enable md5 for authentication:

Add account to /etc/pgpool2/pool_passwd.conf (just a example)

Now, run pgpool with log:

And stop Pgpool if you need:

Finally, test your installation. Good Luck!

Replication Master-Slave with PostgreSQL 9.4 in Ubuntu 14.04

My scenario is I have two servers at addresses and, and installed Ubuntu 14.04 and PostgreSQL 9.4.

To know how to install PostgreSQL, please read Install PostgreSQL 9.4 in Ubuntu 14.04

Step 1: Make sure that the two servers are able to SSH freely between them

Switch to Postgres account:

Generate ssh key:

Copy SSH key to opposite server:

Note: you have to do this step for the both servers 

Step 2: Setup Master Node

Create an account for replication

Modify postgres access config file:

Add content below:

And modify postgres config file:

The config value should be:

And now, restart Master server:

Step 3: Setup Slave Node

Stop PostgreSQL:

Modify postgres access config file:

Add content below:

And modify postgres config file:

The config value should be:

Step 4: Start the replication

In Master Server, run command below to start the replication

In Slave Server, create recovery.conf file:

And add the content below to that file:

And restart Slave Server to complete the setup:

It is time for testing, you can try to create and insert data to Master Server. It will be synchronized to Slave Server