How many times have we not looked for a simple way to communicate with our devices through the Internet without complications and / or complex intermediary applications, DNS, IP addresses or VPN’s.
Many times I have been asked how to turn on a led, relay or view a temperature from the Internet in an easy way, here a possible answer.
For a long time I had in mind this application to control or interact an ESP8266 from the Internet using the existing IRC servers, it only requires 3 things an available IRC server, nickname and channel.
Internet Relay Chat (IRC)
Is IRC (INTERNET RELAY CHAT) is a transmission protocol (TCP/IP), which handles chats and asynchronous communication, chats can be in large groups of users or even one by one.
IRC exists since 1988, although currently it is not as popular as it was a few years ago but there are still many active groups, generally free software discussion communities, IRC servers are active, current and public.
IRC can implement Transport Layer Security (TLS) or Secure Sockets Layer (SSL) to encrypt data between users, it also allows file sending. Most messages sent between an IRC client and the IRC server are sent in plain text.
Technically, IRC is a protocol that allows sending messages to one or many users, using commands for certain actions, such as “PRIVMSG” to send a message to a channel / group or user.
More Information: IRC Commands list, Wikipedia source.
More Information: IRC, Wikipedia source.
More Information: IRC Protocol, linux.org. forum Wikipedia source
IRC Architecture
ESP8266 IRC Client
You could say that creating an IRC client is very simple, technically make connections with a server for a certain port, send and receive messages, for some time I have done tests with esp8266 as an IRC client, I have made some improvements to the initial tests presented in previous tutorials.
To guarantee the existence or connection of the clients the IRC Server continuously sends “PING” to the client in this case ESP8266 would respond “PONG” indicating that it is still active in the channel, this verification is done automatically by our application.
The application has been created to work Answer by request, the ESP8266 will only respond under requests / commands or messages from external clients, it is preferred to avoid constant sending of data without being requested, bombing or perhaps blocking of IRC servers.
Communication Architecture
Video: Introducción ESP8266 Cliente IRC V1.0 PARTE 1
Control and Monitoring
Below I will list some of the features of the irc application implemented in an ESP8266, the main functions of Monitoring and Control, some commands have been created, which allow to request values, states or data from the esp8266:
Downloads: Arduino ide & Github code at the end of the article.
Control of any Gpio output
- Control: GPIO’s activation and desactivation:
Important note: only gpios declared as outputs in void setup will be activated: pinMode (12, OUTPUT);
Command: “HIGH GPIOXX” example: “HIGH GPIO12” Response ESP: “TURN ON GPIO12”
Command: “LOW GPIOXX” example: “LOW GPIO12” Response ESP: “TURN OFF GPIO12”
Values or Data Request
- Monitoring: Read ADC0 value of esp8266.
Command: “READ ADC0” Response ESP: “ADC0 esp8266 = xx” - Monitoring: check the RSSI signal value of the esp8266.
Command: “ESP SIGNAL?” Response ESP: “Signal RSSI ESP8266 = -63 dB”
Application Sensors
- Monitoring: Read Temperature Sensor DHT11
Command: “ESP Temp?” Response ESP: “DHT11 Temperature Now = 29.00 ° C” - Monitoring: Read Relative Humidity Sensor DHT11
Command: “ESP HR?” Response ESP: “DHT11 Temperature Now = 47.00%” - Monitoring: Read Sensor Temperature DS18B20
Command: “ESP Temp2?” Response ESP: “DS18B20 Onewire Temperature Now = 28.42 ° C”
Other Comados available.
- This special command, will be received by all the esp8266 in the channel, regardless of the fact that ENABLE_USERPERMITTED = 1, is only the example of a command free of restrictions.
Command: “ESP ?????”
Response ESP: “Hi, I’m here, I’m Nickname esp8266 🙂 space on the chip is 45215 and how are you? Nickname of the one that I’m executing”.
- Menu of available parameters or help
Command: “ESP8266IRCXXXXXX Help” or “Nicknameesp Help” Answer ESP: List of commands.
Nickname esp8266 Default: ESP8266IRCXXXXXX, the last 6 characters will always be the MAC.
- Interaction: Responses to certain chat messages
Example 1: If any user sends a “:(“ = sad from the chat, the esp will respond.
Example 2: Although the esp performs the actions only by request, periodically the esp can send messages such as the web page information.
Note: commands can be sent in uppercase or lowercase letters.
Test already from IRC Web client
WEB Client has been enabled for your IRC tests, Test right now !!! in 4 steps it controls an ESP8266 from here IRC CLIENT WEB.
- Enter to http://pdacontrolen.com/irc/ and Press the Green Button “Connecting …”
2. Entering Channel “#PDAChannel” with automatic user/nickname example: PDAUSER|31947.
3. Send example command “HIGH GPIO12”.
4. See response of ESP8266IRCXXXXXX = “Turn ON: ON GPIO12” and Done.
Security
Well since the messages or in this case commands are group or massive, anyone could send a command and control the ESP8266, example activate an exit, a method has been implemented to limit the control for the users, in an array the users will be entered allowed to control the ESP8266.
Downloads: Arduino ide & Github code at the end of the article.
ENABLE_USERPERMITTED = 1: ESP8266 receives commands only from users included in the nick_users array, very secure.
ENABLE_USERPERMITTED = 0: ESP8266 receives commands from any user who has entered the same channel, nothing sure.
Send of private messages
It allows sending messages and / or commands directly or privately to ESP8266 if the group / channel publicly displays the command, but for now the ESP8266 will publicly respond to another point to improve.
Interactivity
Another of the functions to be implemented is the interactivity, there are certain pre-configured messages in the ESP8266, the idea is to be able to ask very basic questions to the esp6266, example how is the climate ?, currently in tests, not available in this version.
Materials and where to buy them very cheap !!
- ESP8266 12e NodeMCU
- Sensor DHT11
- Sensor DS18B20 Onewire
Other Recommended Equipment
- Power Meter PZEM 004 with display
- Power Meter PZEM 004T & Three phase meters
- Transformer core splitter
- Monophasic Electric Consumption Meters – Per Pulse
- MPPT Controller Regulator for solar panel
- Solar Panels 10W 18v
- Matrix Led x4 Max7219
- Arduino Nano Clone
Conclusions
There are specialized IoT Platforms, It could be said that IRC is the simplest and Bidirectional communication method that you will find to communicate your ESP8266 from anywhere.
Personally I think the application is very simple and given that feature is functional for simple tests.
Downloads: Arduino ide & Github code at the end of the article.
I have not done tests on a large scale, It is a basic application, Warning although the connection is technically continuous server-client, could give the situation that the messages are delayed, I recommend not to realize very complex control applications, “the control of the nuclear reactor “.
Some advantages
- Bidirectional connection through the Internet without registering to Applications, Token’s or Platforms, I consider it an IoT application.
- Does not require Hosting, Public Fixed IP Addresses, VPN’s, special ports.
- It is a simple TCP / IP connection, connection to a server and port 6777.
- IRC servers such as freenode are public have always been there.
- It allows to create temporary channels by a user, which are technically private, example “#TestESPChannel” could be used for private tests, said channel will only be active as long as there are users in it.
- By creating temporary groups we could create point-to-point P2P or M2M applications.
- IMPORTANT: Do not use existing channels or already used in any community, very public.
- There are IRC clients for almost all platforms, whether Android, Web, Python, C +, Arduino or Node-RED.
- The protocol guarantees the sending and receiving of messages between clients.
Some disadvantages
- In the case of ESP8266, since it connects a group with many users, example: 20 and receives all the messages, I have not performed tests verifying that the esp receives 20 or 30 messages or more, there are several possibilities not confirmed, lost or delayed in the messages, it could be a matter of optimizing the code.
- The security that we use a basic connection, we do not implement (TLS) or (SSL) available in IRC, but we will not use it, I do not see it as something critical, I do not really know in detail this part, although as in a lot of IoT platforms only they perform http communications, in case of discretion these are basic tests, do not place the start of the space shuttle.
For now, the routine that only allows certain users to control esp8266.
Recommendations
Create users or Nicknames with alphanumeric combinations maximum 10 characters, in the specific case of ESP8266 uses part of the MAC in your Nickname.
Again, I caution against using already existing IRC Groups or Channels to avoid complications, since it would be uncomfortable to send messages to channels of existing organizations or projects.
Restrictions
Although it is a public service, I have not found detailed restrictions for the use of the service, of course I recommend a prudent use for sending data, remember that they are servers, fortunately the implementation ESP8266 is response by request.
Technicall your application could be compared with the so-called IRCBots
More information: IRCBots source by Wikipedia.
Recomended: Comparison Lists IRCBots source by Wikipedia
Future improvements
Some improvements are planned, which are in process:
- Private responses to messages / private commands
- Local programming of ESP8266 via OTA, to avoid USB / Serial.
- Configuration from WifiManager.
- Implement a Web Server, for visualization of statistical data irc intcreations and messages.
- Interaction: Display of messages in matrix led or Oled I2c.
- Interaction: Connection with Twitter.
- Interaction: Connection with Google Spreadsheets.
- Interaction: Send notifications via Emails.
Downloads / GitHub Code
References
- More Information: IRC Commands list, Wikipedia source.
- More Information: IRC, Wikipedia source.
- More Information: IRC Protocol, linux.org. forum Wikipedia source
Recommended