Thursday, December 14, 2023

Christmas presents

For an index to all my stories click this text.

The holliday season is coming up. Lots of time to celebrate with your loved ones and friends, but also lots of time to spend with your hobby. And maybe you have relatives or friends also want to start with electronics or the Internet Of Things. What better way than a book that explains it all in an easy to understand manner.  

Next to being the author of this blog I also wrote (until now) 4 books in plain English and two in Dutch that explain these things in an easy way. That is why the series is called xxxx Simplified.


Javascript tips

My latest book. This was released in May/June this year and already many have been sold. This book does not teach programming in Javascript. It assumes that you have some basic knowledge in programmin in Javascript.


For those in the blind: Javascript is thye language that makes webpages tick. Programming in Javascript even allows you to build app's for your mobile phone. This will be featured on this weblog in the upcoming year.

So what is it ?
This is a book with more than 500 tips that help during programming in Javascript.
Here is a small selection of things discussed in this book.
- How to calculate the number of days between two dates.
- How ro remove all non-alphanumeric characters from a string.
= How to copy all even numbers from an array to a new array.
- How to sort an array capital independend.
- How to call a function with an unknown number of arguments.
- How to start a function at preset times or intervals.
- How to test if a certain key is present in an object.
= How to change buttons, text, clour etc. on a web-page.
- How to add or delete elements on a webpage.
- How to prevent a user to copy parts of a webpage.
- How to prevent a user from printing a webpage.

Click here to order this book at Amazon

Click here to order this book from Lulu (my publisher)

The book is avaliable through all local book stores, Barnes and Nobles and Amazon.



Raspberry Pico W Simplifeid.

This is my latest book that was released in October this year.
The book covers the already very popular Raspberry Pi Pico W. In which the W stands for Wifi. The Raspberry Pi Pico W is a serious competitor to the famous ESP32. Not only has this board a lot of memory, a fast dual-core processor, loads of IO ports and USB for easy programming. It also has Wifi which makes it ideal for the Internet of Things. Look at it as an Arduino with added Wifi.



This book covers the following subjects:
Installing MicroPython, the MicroPython language, the pins layout, how to use a breadboard, adding power, how to use a button, how to use leds, fading leds with PWM, connecting to wifi, check if someone is at home with ping, Dallas DS18B20 thermometer chip, building your own MicroPython library, access internet data with Urequests, getting jokes from the internet, publishing to and retrieving data from Thingspeak, using an LDR for measuring light intensity, using mains power with a relay, movement detection with a PIR, getting notifications on your phone with Pushbullet, vibration detection, sending data to Telegram Messenger, how to use JSON, sending data to and retrieving data from Dweet, building a webserver that displays data and has buttons to control leds and lamps etc., attach a reset button.

Every project is build on a breadboard. All programs in the book are written in MicroPython and fully documented in detail.

This book is available through my publisher and through Amazon:

Click here to buy this book from Lulu (my publisher)

Click here to buy this book from Amazon


Raspberry Pi Pico Simplified


The Raspberry Pi Pico was the first microcontroller released by the Raspberry Foundation. Within a year 1.000.000 (yes 1 million) pieces were sold. The Pico is a serious competitor for the Arduino range of microcontrollers. It has a fast processor, loads of IO pins and can easily be programmed with MicroPython. This book focuses on the MicroPython language and on how to use a multitude of sensors with this microcontroller.



The book covers the following subjects:
Getting started, installing libaries, Pico's pins layout, introduction to using a breadboard, power, basic programming knowlegde, buttons, leds, fading leds with PWM, Dallas DS18B20 Digital Thermometer, using an LDR for measuring light intensity, potmeter, servo motor, more power, using mains power with a relay, touch sensor, controlling a motor, making sound with a buzzer, neopixels, H-Bridge for advanced motor control, movement detection with a PIR, motion detection with the RCWL-0156 Radar, measuring distance, tilt sensor, vibration detection, display your data, rotary encoder, oled display and how to build a reset button.

Every project is build on a breadboard. All programs in the book are written in MicroPython and fully documented in detail.

Click here to buy this book from Lulu (my publisher)

Click here to buy this book from Amazon

ESP32 Simplified

When the ESP8266 was released it was a sensation. It was a microcontroller like an Arduino but then with Wifi. The ESP32 offers even more benefits. The ESP32 has many IO pins, a fast processor, a lot of memory, bluetooth and an USB port so you can easily program it. The popular Arduino language (which is C++) is vailable for it and that opens the gate to many libraries for sensors and access to web-services. The ESP32 is a popular widely used microcontroller and therefore this book is a valuable source of information for anyone who wants to start with electronics and the Internet of Things.



This book covers the follwong subjects:
Installing the Arduino IDE, ESP32 board install, using the IDE, using the library manager, using ZIP libraries, installing libraries manually, first use of libraries, ESP32 Pin layout, ESP32 on a breadboard, introduction to using a breadboard, power, USB Breadboard connector,batteries, external Power Supply, programming basics, how to attach a button, buttons or switches, led, fading leds with PWM, Dallas DS18B20 digital thermometer, using an LDR for measuring light intensity, potmeter, make a dimmer, servo Motor, building a web server, more power, using mains power with a relay, automatic night light, touch sensor, a touch sensitive lamp, plant watering system, IFTTT, neopixels, thermometer with led indication, roll the dice, H-Bridge for advanced motor control, movement detection with a PIR, motion detection with the RCWL-0156 Radar, vibration detection, tilt sensor, display data with the TM1637, oled display, Thingspeak a cloud basede IOT, sending thermometer values to Thingspeak.

Every example is build on a breadboard so no soldering is required. Every example has an accompanying program which is documented in detail.

Click here to buy this book from Lulu (my publisher)

Click here to buy this book from Amazon



ESP32 Uitgelegd
Javascript tips


The Dutch versions of my books. For more information look at this story:

https://lucstechblog.blogspot.com/2023/11/sinterklaas-2023.html


Thanks for reading.
Have a great Xmas, a happy and healthy new year and loads of fun.

Luc Volders




Friday, December 8, 2023

ESPEasy part2: send data from esp to esp

For an index to all my stories click this text.

Introduction

ESPEasy is a software package for the ESP8266 and ESP32 that brings IOT functionality where no programming knowledge for is needed. The previous story in this series showed how to install ESPEasy and how to build a button in Domoticz that controls a led attached to an ESP8266 that runs ESPEasy. Indeed no programming was involved !!!

Please read or re-read that story first before continuing here because all the necessary background information is in that story. You can re-read it here http://lucstechblog.blogspot.com/2023/10/espeasy-part-1-iot-without-programming.html

This story tells how to send data from an ESP8266 with ESPEasy to another ESP8266 also with ESPEasy. Again: no programming required !!!! You could use this as a doorbell, movement alarm, door alarm, setting a lamp on etc. etc. etc.

As we will be sending data from one ESP8266 to another ESP8266 no home automation system or cloud service is needed. This is pure communication between two ESP's.

What you'll need.

To reproduce this project you will need two ESP8266's. I used two Wemos D1 Mini's but any version will do. The first ESP8266 will have a led attached. The second ESP8266 has a button attached.

So start with flashing ESPEasy on both ESP8266's as described in the previous story in this series : http://lucstechblog.blogspot.com/2023/10/espeasy-part-1-iot-without-programming.html

Breadboard setup

We need two breadboards. The first one has an ESP8266 with a led and is the receiver. It will get a command from the other ESP8266 to set the led on or off.



The setup is as simple as it gets. An ESP8266 (Wemos D1) with a led, connected to D7. As usual there is a current delimiting resistor of 220 ohm connected to the led. Actually this is the same setup as used in the previous story.

The second breadboard has an ESP8266 with a button. No pull-up resistor needed. We are going to use the internal pull-up resistor in the ESP8266 for that. This is the transmitter.



So this setup is equally simple. The button is at one side connected to GND and the other side to D3.

Setting up the receiver

Actually there is nothing to set up. As you might know from the previous story in this series ESPEasy reacts on simple HTTP commands to set an IO pin high or low.
The receiver has in this example the IP-number 192.168.1.82 Please alter this to your own settings.

Setting up the transmitter

First step is to tell ESPEasy to which pin the button is attached.

At the top of the screen click on Devices.



As the picture shows we can add 12 devices (Tasks) to the ESP8266. A device can be a button or a sensor.

The list of sensors that direct can be used in ESPEasy can be found here:
https://www.letscontrolit.com/wiki/index.php?title=Devices As you can see there are more as 100 sensors that direct can be used as the drivers are build into ESPEasy !!!

We want to add a switch. So first press on the Add button for Task1


Click on the - None - label and a drop down menu appears with all the available sensors. Scroll down till you see Switch input - Switch and click on that.

The screen changes in the settings screen for switches. Lets first look at the upper part of that page.



Now give the button a name. I named it sw1 but choose anything you like. As said before you can add multiple tasks so also multiple buttons. Therefore choose a logical name.

Make sure the button is enabled by checking enabled so it turns blue with the V sign in it.

In the sensor section check Internal Pullup. That way we do not have to use an external pull-up resistor on the ESP8266. Clicking it will turn it blue with the V sign.



The button is on the breadboard attached to D3 of the ESP8266 so make sure to choose GPIO-0 (D3) from the drop down menu.



Choose Switch as the switch type.



And choose Push Button Active Low as the button type.

Leave all other settings as they are.



At the bottom of the page make sure you check Send to Controller 1. ESPEasy can work with 3 Controllers. In this example we are going to use a single one. We will get to the meaning and purpose of the Controllers in a moment.
The IDX and interval value stay as they are: 0

And the last line allows you to name a variable in which the value of the button is stored. Just like coding with the Arduino IDE the value will be 1 if the button is NOT pressed, because of the pull-up function. The value will become 0 if the button is pressed. As with the button name choose the variables name wise as you can have multiple switches attached to the same ESP8266.

When done click Submit and the settings are stored in ESPEasy. Then click Close.

ESPEasy quircks

Well in the first part of this series I told you that in my opinion ESPEasy has some quircks. Well here is the first one.



This is now how your Devices screen should look. Task 1 is activated. The attached device is a Switch with the name sw1. The task communicates with CTR (Controller) 1 (more on that later). The button is attached to GPIO-0 (D3). And the variables name is sw1val and the value is 1 (in green).

The value is 1 as the button is not pressed and uses the internal pull-up resistor of the ESP8266. Now press the button on the ESP8266 and ........ nothing happens. Press it again a few times and still nothing happens.

When I started working with ESPEasy I thought something was wrong and I started searching for the error. I switched back to the Edit screen and fiddled with the settings and then sometimes the sw1val changed into a 0 and later back again into a 1. But it did not works as I expected it to work like I was used from a button in the Arduino IDE.

But ESPEasy works different !!!
First thing to know is that the button works as a latching button. If you press the button the value of sw1val changes to 0 and stays 0 till you press the button again.
Second thing to know is that the pages are not live updated.

So press the button on the breadboard and refresh the page. Now you will see that the 1 has changed into a 0 or the other way round.

Would be a good thing if that was explained more in the documents.


The Controller.

The switch is setup. Now we need a way to send it's state (0 or 1) to the other ESPEasy (the receiver). For that we need a Controller. So click on the Controllers tab at the top of the page.



As you can see we have room for setting up 3 Controllers. The name Controllers was a bit confusing to me. The manual defines it as follows: A controller is a component to enable a plugin to send data elsewhere. Well that mystified it only more for me. What the hell is a plugin and what is data elsewhere.

But of course I figured it out. A plugin is a sensor or a button etc. And data elsewhere is another ESP, your home automation system, a cloud based service like Thingspeak etc etc etc. Well that clears it up.

Click on the Add button in front of the 1 to setup the first (and for this story only) Controller.



As you can see the protocol for the Controllers is set as Standalone. Not what we want. We want to send commands over HTTP.



Click on Standalone in the drop-down menu. Dont hesitate to have a look at all the options. As you can see there are several communication protocols build in. For now we stick to Generic HTTP.



Use the same settings as you can see in the above picture. Only make sure that you replace the Controller IP with the IP number of your own receiver IP. The Controller port is 80 as we will send commands over HTTP. Leave the rest of the settings unchanged for now. Just make sure that Enabled (at the bottom) is checked. If Enabled is not checked the Controller will not work. This is an easy way to switch between multiple Controllers.

What needs a closer look is Controller Publish. That is the second last line in the Controller Setup.

Controller Publish

This line does exactly what it says. In here we need to compose the command which we are going to send over HTTP.

The previous story showed that for sending a command over HTTP to control an IO pin the command structure is:

http://<ESPEasy IP Adress>/control?cmd=GPIO,number,value

We know the receiver's IP adress in this example is 192.168.1.82. We also know that the led is attached to D7. ESPEasy however uses the real IO pin numbers and that is GPIO 13. So the command for setting the led on is:

http://192.168.1.82/control?cmd=GPIO,13,1

And setting the led off is done by:

http://192.168.1.82/control?cmd=GPIO,13,0


You might check the previous story for a detailed explanation on this. Re-read it here: http://lucstechblog.blogspot.com/2023/10/espeasy-part-1-iot-without-programming.html

The IP adress is filled in at the top of the page. So we only need to fill in the rest of this line. Leave away the first /. So we need to send: control?cmd=GPIO,13,1 to switch the led on, or a 0 at the end to switch the led off.

What we really want to do is to use the variable sw1val for that. So there needs to be a way to incorporate that into the command.

Well it took me a while to figure that out. This is also a quirck that is not explained in the documentation. But after a lot of experimenting I found it.

A variable in ESPEasy can be referred to by the name of the unit followed by # and then followed by the name of the variable. All packed between square brackets.

Our switch has the name sw1 and the variable has the name sw1val. That makes the reference to the variable: [sw1#sw1val]

So the total command shall be: control?cmd=GPIO,13,[sw1#sw1val]

And now we have the setup for the Controller complete. Exchange the names sw1 and sw1val for the ones you used in your Device setup and we are done. Press Submit at the bottom of the page and then press Close.

Indeed we are done.

This project is completed. To get things working just press the button on the transmitter ESP and the led on the receiver ESP will go on. Press the button again and the led will go off. All done without 1 line of coding and no cloud service needed !!!

That is all. It looks complicated but it really is not. Just get used to working with ESPEasy and you will enjoy it's simplicity in the end.

I was going to add how to send data from ESPEasy to Domoticz in this story. But there is already a lot of information in here so I save that for a future story.

Conclusion for now.

ESPEasy is fun to work with. It is indeed possible to get things done like sending data from one ESP to another without 1 line of code, as this story shows.

This story and the previous have not even scratched the surface of what is possible with ESPEasy. So I urge you to dive into it and start experimenting.

But it is not completly easy as the name suggests. The documentation is a bit crummy. You will need some experience with ESP8266 to attach buttons and sensors. And you need some insight about IP-Adresses, HTTP code etc. So the easy part of the name is only justified for those that are not total layman.

Still I urge you to experiment with ESPEasy and if you get the hang of it, it is possible to set up some IOT projects in a very short time.

Till next time
have fun

Luc Volders