Friday, January 19, 2024

ESPEasy part 4: ESPEasy send data to Whatsapp

For an index to all my stories click this text.

In this tutorial I am using an ESP8266 with ESPEasy installed. A button is connected to the ESP8266. When you press the button ESPEasy will send a message to Whatsapp. This is an example to show how we can send alerts direct from ESPEasy to our phone.

Introduction

ESPEasy is a kind of operating system for the ESP8266 and the ESP32 that has a good looking webpage and build-in drivers for hundreds of sensors and actuators. Even better: most of them are usable without you having to write 1 line of program code.
ESPEasy can send data to your home Automation system (like Domoticz or Home Assistant) but also to cloud services like Thingspeak and Freeboard. ESPEasy can even send data from one ESP8266 to another.
I wrote a series of articles on ESPEasy. Here is the list.

1) Getting started with ESPEasy
http://lucstechblog.blogspot.com/2023/10/espeasy-part-1-iot-without-programming.html

2) ESPEasy inter communication. Sending data from one ESP to another
http://lucstechblog.blogspot.com/2023/12/espeasy-part2-send-data-from-esp-to-esp.html

3) ESPEasy sending to and receiving data from Freeboard.
http://lucstechblog.blogspot.com/2024/01/espeasy-part-3-freeboard-iot-dashboard.html

What if you want a project to send it's data direct to your phone. ESPEasy can send data to your home automation system and that can send a notification to your phone. However ESPEasy can not send itself a notification to your phone. So what if you need a quick solution for a doorbell, rain detector, an alarm if your printer filament is broken, if someone opens the cookie jar etc. etc.

Here is a solution to that problem.

There is a service called CallMeBot. I have covered that here before as a means to send a message from an ESP8266 or ESP32 to WhatsApp. These work flawless but require you to program the ESP in C++. ESPEasy can do this without programming.

For this project you'll need an ESP8266 (I use the Wemos D1 version) and a button. And you will need to have that ESP8266 installed with ESPEasy. For installing ESPEasy read the first story in this series:
http://lucstechblog.blogspot.com/2023/10/espeasy-part-1-iot-without-programming.html

Next you need to have CallMeBot activated. You can read how to do that here:
http://lucstechblog.blogspot.com/2021/05/esp8266-and-esp32-sending-messages-to.html

The breadboard setup

As easy as it gets.



Just an Wemos D1 mini with a button attached to pin D5.

Setting up a switch.

Before we can use the button we need to setup a switch in ESPEasy.



Start at the Devices section. Press Add at task number 1.



Then click on - None - in the drop down menu and scroll down till you see Switch Input - Switch and click on that. Next fill in the settings for that switch.



In the top part of the settings page give the switch the name sw1 and make sure Enabled is checked.
We use the internal pull-up resistor in the ESP8266 so make sure to check that.
The switch is on the breadboard attached to D5 which is GPIO-14.
Choose switch as the type and Push Button Active Low.
This is because the switch is normally high (by the internal pull-up) and when pressed becomes low.
Leave the rest of the settings in this part as they are, and scroll down.



At the bottom of the page make sure Send to Controller 1 is checked. This attaches the switch to the first controller which is the part that actually sends the data to Dweet. And lastly rename the Value in sw1val. Then make sure to press Submit and the settings are stored in ESPEasy.

The referral to the switch in ESPEasy is Name#Value which is now sw1#sw1val. That is what we are going to use in the Controller part.

Setting up the Controller.

To send data from ESPEasy to another ESP or a Home Automation system or any other device you need to configure a so called Controller.



In this example the ESP8266 is only sending data to WhatsApp so we configure Controller 1. Click on the blue Add button at Controller 1.



The standard Controller Protocol is - Standalone. Click on that because we want to choose another option.



Choose Genric HTTP cause we are going to send an HTTP command to CallMeBot.

We have to use the CallMeBot API to send messages from ESPEasy to CallMeBot. Please re-read my story on CallMeBot that explain this. You can re-read it here: http://lucstechblog.blogspot.com/2021/05/esp8266-and-esp32-sending-messages-to.html

That story told us that to send a message to CallMeBot we have to use the following format:
http://api.callmebot.com/whatsapp.php?phone=+XXXXXXXXXXXX&text=This+is+a+test&apikey=YYYYYY

Of Course you will have to replace the XXXXXXXXX by your mobile phone number and the YYYYY by the CallMeBot api-key.

And we do not want to send the message: This is a test. What we want is to send the state of our button: 0 or 1. For example: Button value  = 1.
The switch defined in the Devices section has the name sw1 and its value is in the variable sw1val.
Therefore we have tp replace - This is a test -  by Button+value+=+[sw1#sw1val]
To put a variable into an equation or a text you need to put the full name of the variable between square brackets.

This makes our HTTP command complete:
http://api.callmebot.com/whatsapp.php?phone=+XXXXXXXXXXXX&text=Button+value+=+[sw1#sw1val]&apikey=YYYYYY



And here is how the complete settings for the Controller look.

The Protocol is Generic HTTP.
The Controller is Located by Using the Hostname
The Hostname is api.callmebot.com and as we are sending over http the Controller Port is 80.

The rest of the settings are good as the are except:

Client Timeout: 1000

The Client Timeout is the time ESPEasy should wait before it decides that there is no connection with CallmeBot. Within our own network a setting of 500 (half a second) is more then sufficient. But here we have to wait for a response over the internet. And when it is busy that will take a while. So start with setting this value to 1000 and do some experiments with a longer and shorter time.

And lastly we need to fill in the settings for Controller Publish; whatsapp.php?phone=+XXXXXXXXXXXX&text=Button+value+=+[sw1#sw1val]&apikey=YYYYYY

Again: do not forget to replace the x's with your phone number and the y's with your own CallMeBot api key.



And here are the messages in Whatsapp.

We've Dunnit !!!!!

This is the way to send messages directly from ESPEasy to Whatsapp.

Please be aware that CallMeBot has a limit of 25 messages per 240 minutes. That is about 1 message every 10 minutes. So pack more information in each message or limit the amount of messages you are going to send.



If there is for example a second button with the name sw2 and its variable is sw2val then you could send:

text=Button+value+=+[sw1#sw1val]+\n+button2+value+=+[sw2#sw2val]

The \n puts the information from the second button on a new line.The + sign puts a space between the words.

Have fun with ESPEasy
and till next time.

Luc Volders












Friday, January 12, 2024

Migrating Cirkit from Windows to Linux (Ubuntu)

For an index to all my stories click this text

My computer is an old workhorse. I bought it in 2018 that made it now no less then 6 year old. The age does not bother me as it does what I want, except for one thing: it is slow, really slow.
Booting to starting a webpage takes more than 4 minutes !! And shutting down takes around 50 seconds.

Most of this lack of speed is due to Windows. Windows is doing lots of things in the background. It is doing disk optimalization, virus checking and updating of the os and programs while I am working. And that slows everything down. Next to that every update of Windows brings new stuff which also may slow things down.

Three options:
- Learn to live with the speed limit
- Buy a new (faster) computer
- Switch to Linux which is a lot faster.

So I am slowly switching over to Linux.
I put Ubuntu on an USB stick. Each time I boot my system I press F12 to get to the Bios and choose if I want to boot from my harddisk with Windows or from the USB stick with Ubuntu. And since I started with this option a few weeks ago I find myself 98% of the time booting Linux. So I am considering to install it permanently on my harddisk. That may even make it faster.

Most of the software I use on my Windows setup also runs on Linux. There are versions of the Gimp, LibreOffice, Thonny, Arduino IDE, Media player, Firefox, Discord, Cura slicer and Raspberry Imager. So not a lot of difference between the two operating systems. Oh, and there is Cirkit for documenting breadboard setup for my stories. I use that a lot for my books and this weblog.

Cirkit is easy to use and it is easy to define your own components. I wrote a story on this which you can read here: https://lucstechblog.blogspot.com/2022/08/create-new-component-in-cirkit.html

I only had a small problem. I have several self defined components and naturally I want to use them with Cirkit in Linux. So how do You transfer the components from Windows to Linux.

Locate the components in Windows

First thing is to find where Cirkit stores the self defined components in Windows.



There is a directory called userDefinedComponents and you can find it by following this path:
Windows/users/lvold/AppData/Roaming/CirkitDesigner/



In this directory there are two other directories called images and jsons.
The first directory (images) contains all the pictures of your user defined components. The second directory (jsons) contains the descriptions and the pin layout. You need both.

What I did was to copy both directories to a USB stick. Then I rebooted my computer in Linux.

Copying the components to Ubuntu

Now I had all my own designed components I had to copy them to the right directory in Cirkit under Linux.



This is how the menu structure of Cirkit initially looks. As you can see there are (naturally) no self defined components.

They need to be put into the following directory:

Home/snap/cirkit-designer/20/.config/cirkit-designer

First thing to do to find that directory is to enable viewing hidden files.



So click the hamburger menu (3 horizontal lines) at the left-top side of the window and activate Show Hidden Files.

Then click consecutively:

- snap
- cirkit-designer
- 20
- .config
- cirkit-designer



And then UserDefinedComponents.

Next copy the files from your USB stick (the images and jsons directories) to this location. And we are done.

Do not use this method if you already have defined some new components in Cirkit in Ubuntu as the files from the USB stick will overwrite your exisiting files.



And there they are. All my self-defined components ready to use with Cirkit in Ubuntu. Ready for new adventures !!!

Till next time.
Have fun

Luc Volders







Friday, January 5, 2024

ESPEasy part 3: Freeboard an IOT dashboard with ESPEasy

For an index to all my stories click this text.

Remember Freeboard ?? I wrote a story on Freeboard in October 2019. You can find it here: http://lucstechblog.blogspot.com/2019/10/freeboard.html

For those in the blind: Freeboard is an IOT dashboard that uses a service called Dweet to communicate with IOT devices. Freeboard is relatively easy to use and free of charge. Oh, yes, the original version of Freeboard is no longer free of charge. But luckily for us Freeboard can be forked from Github and you can then run your own Freeboard for........indeed free. Please read the above story for a tutorial on how to use Freeboard.

And lately I have published a few tutorials on ESPEasy. ESPEasy is a software package for the ESP8266 and ESP32. It is a stand alone solution for working with sensors and sending their data to a Home Automation system like Domoticz. ESPEasy has a good looking web-interface and has support for tons of sensors build in. You can also use ESPEasy to send information between multiple ESP's without the use of a dedicated server or cloud service. Just direct communication between two (or more) ESP's. And best of all: most ESPEasyfunctions can be used without 1 line of programming !!  ESPEasy is certainly worth checking out. You can read my previous stories on ESPEasy here:
http://lucstechblog.blogspot.com/2023/10/espeasy-part-1-iot-without-programming.html
http://lucstechblog.blogspot.com/2023/12/espeasy-part2-send-data-from-esp-to-esp.html

Not all of the readers of this weblog have a dedicated Home Automation System like Domoticz. So I am going to show you how to use Freeboard as a dedicated IOT Dashboard for ESPEasy.

IF you do not have your own Freeboard up and running you can use freely my personal version which can be found here: http://lucsfreeboard2.000webhostapp.com/

Please make sure that you use http instead of https otherwise Freeboard does not work.
 
I did a complete series on Freeboard and you can find links to those stories on this page: http://lucstechblog.blogspot.com/2023/09/freeboard-revisited-5-install-add-ons.html

Dweet

As you might know from my previous story on Freeboard, Freeboard relies heavily on a service called Dweet to get its data from. So the way to send data to Freeboard is to send data to Dweet and Freeboard collects it from there.

In 2019 I wrote a complete tutorial on Dweet and you can re-read that here: https://lucstechblog.blogspot.com/2019/05/dweet-volatile-iot-cloud-service.html

Dweet itself can be found here: https://dweet.io/

Basically there are two important things to know about Dweet. The first is how to send data to Dweet and the second is how to retrieve data from Dweet. For working with Freeboard we only need to know how to send data to Dweet as Freeboard collects it automatically.

To send data to Dweet you need to send an HTTP command that looks like this:
http://dweet.io/dweet/for/my-thing-name?hello=world

In this my-thing-name is the name you want to give your sensor and hello is the variable name used with that sensor and in this example world is the data.
Before we are putting this into ESPEasy let's first look at the breadboard setup.

Breadboard

As we are going to send data from ESPEasy to Freeboard we need a switch that we can press, that Freeboard will be able to registrate. Next to that we are going to send a command from Freeboard to ESPEasy to set a led on.



The breadboard setup is the same as from my first story on ESPEasy. A button is attached to D7 and a led with a current delimiting resistor to D5.

ESPEasy to Freeboard

The first step is to install ESPEasy on your ESP8266. You can read how to do that in the first story on ESPEasy which you can re-read here http://lucstechblog.blogspot.com/2023/10/espeasy-part-1-iot-without-programming.html
Please also re-read the second story on ESPEasy in which Controllers and Devices are explained which we are ging to use here.

To send data from ESPEasy to another ESP or a Home Automation system or any other device you need to configure a so called Controller. In this example the ESP8266 is only sending data to Freeboard so we configure Controller 1.



As said before we are not sending data directly to Freeboard. We are sending data to Dweet and Freeboard will collect and display that data.

As Protocol to send data to Dweet we are using Generic HTTP.
The URL of Dweet (Locate Controller) is not the IP-Adress but Dweet's http name being dweet.io.
As the commands are send over http the port number is 80.

One very important setting is Client Timeout. This is the amount of time ESPEasy waits to get a reply from Dweet. This value is normally set to 100. That is ok when you are sending data to another ESP in your own network. Now we are sending  data to a cloud service and a busy one !!! So give ESPEasy some time to wait for the answer from Dweet. Set the value for Client Timeout to 1000 or even 2000. Just test what will work for your situation.

And then another important setting is the Controller Publish setting. Here we have to fill in what we are going to send to Dweet.io.

Thye command to send data to Dweet is:
http://dweet.io/dweet/for/my-thing-name?hello=world

The first part (the Controller Hostname) is already filled in.

I am using espeasy as my-thing-name and testval as the name of the variable.

As I expect quite a few readers to follow this tutorial I kindly ask you to use a different name as espeasy. If everyone is using the same my-thing-name your results will become unpredictable. So replace espeasy with something like your initials and and the date. Be creative.

In the next section we are going to set a device (in the Devices setting) and that is going to be the switch. The switch will be named sw1 and the variable attached to it will get the name sw1val.

So what we are going to have the controller send is:

dweet/for/espeasy?testval=[sw1#sw1val]

Fill this in at the Controller Publish field.
Last step is to check the Enabled field and then press Submit.

On to the Devices section.



First press Add at task number 1. Then click on - None - in the drop down menu and scroll down till you see Switch Input - Switch and click on that. Next fill in the settings for that switch.



In the top part of the settings page give the switch the name sw1 and make sure Enabled is checked.
We use the internal pull-up resistor in the ESP8266 so make sure to check that.
The switch is on the breadboard attached to D5 which is GPIO-14.
Choose switch as the type and Push Button Active Low.
This is because the switch is normally high (by the internal pull-up) and when pressed becomes low.
Leave the rest of the settings in this part as they are, and scroll down.



At the bottom of the page make sure Send to Controller 1 is checked. This attaches the switch to the first controller which is the part that actually sends the data to Dweet. And lastly rename the Value in sw1val. Then make sure to press Submit and the settings are stored in ESPEasy.

As you can see the referral to the switch is Name#Value which is here sw1#sw1val and that is what we used in the controller part as discussed previous.

Back to Dweet.

Press the button on the breadboard. ESPEasy will now send its data to Dweet. And we can check that.

Open a fresh browser window or tab and fill in: http://dweet.io/get/latest/dweet/for/espeasy



And this is the result you should see. This makes sure that ESPEasy is indeed communicating with Dweet.

Getting the data in Freeboard

Open freeboard in a new browser tab or window. As stated before, if you do not have installed freeboard on your own webserver you can use mine: http://lucsfreeboard2.000webhostapp.com/

First thing to do is to tell Freeboard where the data is coming from.



At the right side on the screen choose ADD (below DATASOURCES).



Click on Dweet.io



As the to be displayed name I choose ESPEasy Test and the thingname of course is espeasy.
Make sure to fill in the name you gave my-thing-name in Dweet.



At the right top side of the screen you will see that the Datasource for ESPEasy Test is immediately updated.



At the left side on the screen now choose ADD PANE. And click on the + sign.



Click on Select a type and choose Indicator Light



Click on + Datasource and then click on the Datasource. At this moment there is only one and that is ESPEasy Test.



Then click on testval as this is the variable we need.



You can give the On and OFF text a name of your liking. I just simpl,y choose ON and OFF.
As the last step click on SAVE and your done.



Now press the button on your ESP and the led on your freeboard will go ON or OFF.

That's it. This is how you send data from ESPEasy to your Freeboard dashboard.


Freeboard to ESPEasy

We can receive data from ESPEasy and display that on Freeboard. But what about the other way round.
The breadboard has a led and we want to control that from our Freeboard dashboard. Well that can easily be done.

Start with clicking on the left side of the screen on ADD PANE

In the new PANE click on the + sign and then click on Select a type... This time we are going to add a switch.

 

First we start with giving the widget a name. I choose ESP8266's led as that is what it is.

ESPEasy has internal commands to set a GPIO pin on or off.
The General command is http://URL-ESPEASY/control?cmd=GPIO,number,1 or 0

We know the IP adress of our ESP8266 and that is 192.168.1.82
We also know that the led is attached to GPIO 13

Therefore the command for setting the led on is:
http://192.168.1.82/control?cmd=GPIO,13,1

Setting the led off is doen with:
http://192.168.1.82/control?cmd=GPIO,13,0

You can give the ON and OFF TEXT a name as I did. I simply choose ON and OFF. Alter this to your own liking. And SAVE.

Confused ??? Then read the first and second story on ESPEasy where all these commands are explained. You can find them here:
http://lucstechblog.blogspot.com/2023/10/espeasy-part-1-iot-without-programming.html
http://lucstechblog.blogspot.com/2023/12/espeasy-part2-send-data-from-esp-to-esp.html



There is our widget completed.



Click on the button next to the text ESP8266's led and the led on the Freeboard widget will change from OFF to on. At the same time (well almost) the led on your ESP8266 wil go on or off.

Save it

Don't forget to choose SAVE FREEBOARD to save the Freeboard settings to your computer. SAVE is at the top left side of your Freeboard.
Freeboard itself does not saves the data so if you dont do it then next time you open the Freeboard website you will have to fill in the Datasources and build all widgets anew.

That's it

This is how we can send data from ESPEasy to Freeboard and commands from Freeboard to ESPEasy.

Replace the led by a relays, pump, motor or whatever and start building your IOT system with ESPEasy and Freeboard. ESPEasy supports hundreds of sensors and actuators right out of the box, no installing needed. And as you have seen: no programming needed.

Your freedom with ESPEasy is a bit restrained compared to building your own program in the Arduino IDE. That is compensated by the speed and ease with which you can realise a project. Together with Freeboard ESPEasy is a great way to quickly build an IOT project.

Till next time
Have fun

Luc Volders