Node-RED Tutorial: How to send AT commands with Raspberry PLC

Send and receive SMS using Raspberry based PLC for Raspberry Pi automation
July 5, 2021 by
Node-RED Tutorial: How to send AT commands with Raspberry PLC
Boot & Work Corp. S.L., Fernandez Queralt Martinez

Introduction

GSM (Global System for Global Communications) is the communication system most widely used in mobile phones, and its first functionality is voice transmission. However, it also allows data transmission like SMS or Internet, at a very low speed.

GPRS (General Packet Radio Service) is an extension of GSM based on packet transmission that offers a more efficient service for data communications, especially in the case of Internet access.

In this post, you will learn how to send AT commands, specially how to send SMS from your Industrial GPRS Family of  the open source PLC Raspberry Pi to your mobile phone, thanks to industrial automation.

Related links

How to

Connect Raspberry PLC to Wi-Fi

Read 

Raspberry PLC

Family products

See 

How to

Program Raspberry PLC interrupt inputs with Python

Read 

How to

Find your perfect industrial PLC

Read 

Touchberry Pi

Family products

See 

Basics about

industrial Raspberry Pi PLC Analog outputs

Read 

Requirements

 Raspberry PLC with GPRS

 Ethernet cable

Explanation

Node-RED

In this post, we are going to develop a Node-RED flow to send SMS messages from the GSM module of the Raspberry Pi PLC controller to our mobile phone. The AT commands that we are going to use are the same as we used in this post.

First of all, check the following from your Raspberry Pi based PLC: 

  SSH is enabled

  Node-RED is installed in your Raspberry Pi industrial PLC

  If you go to minicom using:

sudo minicom -D /dev/ttyS0 -b 115200

and type AT, you receive OK.


And once everything is ready, let's go with the Node-RED application!

Sending SMS

Go to your favourite browser, type the IP address from your industrial Raspberry PLC and start your App.
As we mentioned before, we are going to send the following to our /dev/ttyS0 port to get the response. 

Sending SMS - Node-RED Tutorial: How to send AT commands with Raspberry PLC

So the first thing that we are going to do is to add five inject nodes to set the msg.payload to the String messages like this:

Add 5 inject nodes - Node-RED Tutorial: How to send AT commands with Raspberry PLC

As we can see in the picture above, after every message we must add an Enter character (\n), and also a Ctrl + Z right between the "Hello" message and \n.
So we are going to wire these five inject nodes to a function node, where we will add those characters in hexadecimal.
To add the \n after the AT commands, add the \n parsed in hexadecimal to a function node as shown:

msg.payload += Buffer.from("0D", "hex");
return msg;

Note that there is the symbol  "+=" to append the \n after the AT commands.

Edit function node - Node-RED Tutorial: How to send AT commands with Raspberry PLC

Now, we have to add a Ctrl + Z character between the Hello message that we want to send, and the \n. The Ctrl + Z is represented by 1a in hexadecimal. So add the following to a function node and wire it between the inject node and the function node with \n.

msg.payload += Buffer.from("1a", "hex");
return msg;

Properties - Edit function node - Node-RED Tutorial: How to send AT commands with Raspberry PLC

Then, look for the serial out node and configure it as you want. We left the default values and configured the following:

Baudrate: 115200
Data Bits: 8
Parity: None
Stop Bits: 1

Add a serial in node wired to a debug node, where you will get the responses from the same port.

Edit serial port node - Node-RED Tutorial: How to send AT commands with Raspberry PLC

Finally, click on the buttons of the inject nodes, and see the results!

Inject nodes - Node-RED Tutorial: How to send AT commands with Raspberry PLC
Hello message - Node-RED Tutorial: How to send AT commands with Raspberry PLC

 Now, would you like to know how to work with a GPRS module?

Know how >>

​Search in our Blog

Node-RED Tutorial: How to send AT commands with Raspberry PLC
Boot & Work Corp. S.L., Fernandez Queralt Martinez July 5, 2021

Looking for your ideal Programmable Logic Controller?

Take a look at this product comparison with other industrial controllers Arduino-based. 

We are comparing inputs, outputs, communications and other features with the ones of the relevant brands.


Industrial PLC comparison >>>