ShIoTiny5 – OTA, clock, Encoder and other news from v0.26 to v0.32

What is this article about?

This is a continuation of a series of articles about a hobby project ShIoTiny5 – embedded graphic programming system for microcontrollers of the family ESP8266.

For those who don't know what we're talking about

For those who hear about the project ShIoTiny5 for the first time – you can watch project website and find detailed information there firmware instructions v0.32 and herself firmware.

In addition, at the end of the article there is linkswhich will help you understand what we are talking about.

To write programs for ShIoTiny5 you don't need anything other than an Internet browser and a module based on ESP8266connected to a computer or laptop via WiFi.

However, programs can be written (or rather, drawn) without a module based on ESP8266 – there is an online version of the program circuit editor located here. But without ESP8266 These programs cannot be launched and tested in operation.

For those who already understand and are aware

Several months have already passed since I wrote my last article about a hobby project. ShIoTiny5.

Since the last article was written, the software version ShIoTiny5 got up from v0.26 before v0.32. A lot of bugs have been fixed. New devices have been added. New functions of the entire system and components have been introduced. This article is an overview of the new project features ShIoTiny5.

I get quite a lot of emails from people who have used ShIoTiny5 for your needs. They repeat questions about what I plan to do, when and “is it possible to add this too.”

On the one hand, I am very glad that people are interested and not only interested, but also used for simple crafts.

On the other hand, I cannot answer everyone and fulfill all wishes.

Firstly, this is the time that is limited for me by my main job and other things like children's parties, trips to hospitals, kindergartens, schools and other family concerns.

Secondly, this is the memory of ESP8266 modules, which is not infinite. I previously limited the FLASH volume to 1 MB and do not want to go beyond it.

Thirdly, I have ideas for the development of this project, but for ESP32.

Therefore, now there is a certain minimum of functions that I want to add, debug, bring to mind and call it a day by switching to ESP32-modules.

In this article I will describe the latest changes that have befallen the software. ShIoTiny5 from version v0.26 up to current version v0.32. In addition, where appropriate, I will share plans for the future.

Brief list of changes from v0.26 to v0.32

  • It is now possible to update firmware over the network – OTA;

  • Introduced support for on-chip real-time clock DS1307;

  • Now you can connect up to 16 temperature sensors DS18s20, DS18b20, DS1822 per tire;

  • Added support for CO2 concentration sensor – SCD30;

  • Rotation angle sensor – encoder (valcoder) supported;

  • Fixed connection error with MQTT server;

  • Fixed many editor errors;

  • It is now possible to automatically rebuild communication lines between nodes.

This is the main thing. There are also several dozen small fixes that kept me from living in peace, but there is no point in describing them, because outwardly they have almost no effect on anything and are not noticeable to the user.

The changes are discussed in more detail below.

OTA – ability to update firmware over the network

The most important change that made it easier to work with ShIoTiny5 – this is the appearance of the button Upgrade on the device configuration page. This button only appears if your ESP8266-based module has at least 2MB of FLASH memory!

For modules with 1MB of memory, software updates are possible, as before, only via UART.

This is a small problem, since it is now difficult to find a module with even less than 4MB of FLASH memory.

Be that as it may, starting from the version v0.29 It is possible to update the software via the WEB page. This is not quite an OTA in the classical sense, since there is no single image repository. But how convenient it is!

Updating over the network looks ridiculously simple for the user:

  • push the button Upgrade;

  • then a file selection dialog will appear in which you need to select a file with a software image, version no less than v0.29;

  • Once a file is selected, it is downloaded and checked for correctness. If the file is found to be correct, a window prompting you to update the firmware is displayed. If the file is broken, then a window with an error message;

  • in the window asking you to update the firmware, click the button Start Upgrade;

  • We wait until the firmware downloads and the device restarts.

Firmware update process via WEB interface

Firmware update process via WEB interface

The program diagram and device settings are saved. Therefore, after updating the firmware, the device usually continues to work as before.

The update process is described in detail in instructions.

Real time clock

In version v0.27 a real-time clock unit based on a microcircuit was introduced DS1307.

This is an urgent need, which has become more urgent due to the fact that data published via the MQTT protocol can now be linked to a timestamp.

If there is no real time clock and the NTP server is not available, then the timestamp will be incorrect.

The microcircuit is connected DS1307 via bus I2C. Other devices can be connected via the same bus.

Typically a real time clock is used in conjunction with an NTP server. When the NTP server is available, it is used for time synchronization. Otherwise it is read from the microcircuit DS1307.

In order to synchronize the time in the system from the NTP server and count it regardless of the presence of a connection with the NTP server and the presence of the main power supply to the ESP module, it is recommended to use the diagram shown below.

Sharing NTP Server and Real Time Clock

Sharing NTP Server and Real Time Clock

As usual, details in instructions.

Plans: I want to support a more modern watch chip.

Temperature sensors DS18s20, DS18b20, DS1822 – many and different

Since version v0.31 it became possible to connect up to 16 sensors to one bus.

To do this, in the node DS182x a parameter field N was introduced, in which you can set the number of sensors on the bus – from 1 to 16.

DS182x node

Knot DS182x

The number of sensors on the bus must be strictly equal to the specified one. Otherwise, at the node outputs DS182x will be set to NaN (not a number).

The order of binding sensors to node outputs DS182x determined automatically by a unique 64-bit sensor identifier. When replacing one sensor with another, the binding order changes in an unpredictable way.

Two sensors connected to the bus

Two sensors connected to the bus

On the page “ShIoTiny Info” In chapter “Used GPIOs» information about connected sensors will be displayed: node output number DS182xto which this sensor is attached, the value of the temperature read from this sensor and its unique 64-bit identifier.

Of course, everything is described in much more detail in instructions.

Plans: I want to introduce nodes that support the same sensors, but with strict binding to a unique 64-bit identifier.

CO2 concentration sensor – SCD30

The SCD30 sensor – very expensive – allows you to measure CO2 concentration, temperature and air humidity. Support for this sensor starting with v0.30made it necessary to measure the CO2 concentration.

The SCD30 sensor is connected via bus I2C.

As usual, details in instructions.

Rotation angle sensor – encoder (valcoder) – Encoder unit

Beginning with v0.32 Added support for a highly customizable encoder or valcoder node.

The encoder itself allows you to determine the angle of rotation and direction of rotation by recording the phase and number of pulses generated by the contacts (or optocoupler).

Typical rotary encoder with push button

Typical rotary encoder with push button

A typical encoder designed to act as a switch with an infinite number of positions looks like the figure.

It has two signal lines, which can be labeled differently, but I labeled them as Sa And Sb. These lines are equal. One of them serves as a synchronization signal, and the second as a signal indicating the direction of rotation. In addition to the signal lines, the encoder is supplied with power and ground.

In addition, many encoders can not only be rotated, but also pressed. But we won’t dwell on how to work with the button here. This is a normal dry contact.

Encoder node in no-input mode

Encoder node in no-input mode

The encoder node has quite a few functions – counting pulses, limiting the minimum and maximum values ​​in several ways, control by setting the initial value, etc.

The picture shows the node Encoderconfigured to operate with an encoder connected to the line GPIO4 And GPIO5. In this configuration, the output node will count values ​​from 0 to 99 (or from 99 to 0 if the direction of rotation is reversed). The initial value at the output of the node is determined by the field Init and equals 0 in our case. When rotating in one direction, the value at the output of the node will increase by 1 with each pulse at the input, and when rotating in the other direction, it will decrease by 1.

If we set the parameter value Stepfor example, in 0.1then with each step the value at the output of the node will increase or decrease by 0.1.

In general, the fields Step, Min, Max, Init can have integer, fractional, positive or negative values. This is convenient for converting the number of pulses into the required value. For example, to change the direction of counting, it is enough to change the sign of the parameter Step.

Constraints can also be set in different ways, determined by the value of the field Mode. Methods for limiting node output values Encoder are given below.

  • Mode: Rotate cyclical change. That is, if the value becomes greater than Max, then it is set to Min, and if the value becomes less than Min, then it is set to Max. (We walked around and started over).

  • Mode: Fix fixing the minimum and maximum. If the value becomes greater than Max, then it is set to Max, and if the value becomes less than Min, then it is set to Min. (We rest against the limiters on the left and right).

  • Mode: FixMin fixing the minimum. If the value becomes less than Min, then it is set to Min. But if the value becomes greater than Max, then it is set to Min. (We rest against the limiter only on the left).

  • Mode: FixMax fixing the maximum. If the value becomes less than Min, then it is set to Max. But if the value becomes less than Min, then it is set to Max. (We rest against the limiter only on the right).

It is possible to manage the node Encoder using external node inputs. The mode of external inputs is determined by the parameter Inas shown below.

  • In: No There are no control inputs. The initial value is set field Init.

  • In:Init Control input Init. The initial value is set entrance Init.

  • In: Rst Control input Rst. When log.1 is at this input, the output value is set to the initial value, determined field Init. At log.0, the encoder pulses are counted at this input.

  • In:Init+Rst Control input Init And Rst simultaneously. With log.1 at the input Rst — the output value is set to the initial value, with entrance Init. At log.0 at the Rst input, the encoder pulses are counted.

To make it clear how to use an encoder, the figure below shows a simple example – a thermostat. Using the encoder, the desired temperature value is set – from +10C to +35C with an accuracy of 0.1C.

The simplest thermostat with indication

The simplest thermostat with indication

The thermostat hardware consists of:

  • ESP8266 module (for example, NodeMCU) into which the system is flashed ShIoTiny5;

  • an encoder that sets the desired room temperature value (pins GPIO4 and GPIO5 of the ESP8266 module);

  • an encoder button connected to the GPIO0 pin of the ESP8266 module;

  • DS18b20 sensor that measures room temperature (GPIO13 pin of the ESP8266 module);

  • relay controlled by the GPIO2 pin of the ESP8266 module;

  • A 6-digit indicator based on the TM1637 chip, displaying the desired (set) and actual room temperature values ​​(pins GPIO12 and GPIO14 of the ESP8266 module).

Of the six digits of the indicator, three digits (0-2) are the temperature setpoint (that is, what is set by the encoder) and three digits (3-5) are the current room temperature measured by the sensor DS18b20.

The thermostat operating algorithm is the simplest. If the value set by the encoder is less than the room temperature, then the heater is turned off. If the value set by the encoder is greater than the room temperature, the heater turns on.

Knot Delay0/1 It is only needed to ensure that the heater does not turn on and off more often than once every 1 minute.

When you press the encoder button, the setpoint value is reset to the initial value specified by the field Init node Encoder or 20C in our example.

Of course, with the help of such a device you can only heat the room, but not cool it. But that doesn't matter now.

That's all in brief about connecting the encoder to ShIoTIny5. For details, contact instructions.

Fixed connection error with MQTT server

This was an extremely annoying and very rare error.

It consisted in the fact that if in a certain way the connection between ESP8266 and an MQTT broker, the connection was never restored. It was a bug in the MQTT library I was using. Finally, this bug was identified and fixed.

Therefore, I recommend it to everyone who uses ShIoTiny5, update the program to version v0.32. Of course, it is impossible to correct all mistakes. But this error is definitely not here. The only good thing is that due to the rarity of this error, few people have come across it 🙂

Changes to the Link Properties menu

The editor has also been improved. It is now possible to automatically rebuild communication lines between nodes. During the process of constructing a diagram, when nodes and connections are moved many times by hand, sometimes nodes, loops and other visually unpleasant connections appear.

Rebuild links menu

Rebuild links menu

To eliminate this effect, a submenu “Reroute” – automatic rebuilding of links. This submenu, shown in the figure, is located in the “Link Properties Menu”.
When selecting “Line» one connection that is selected is rebuilt. When selecting “Group» the group of links is rebuilt, which includes the selected link (that is, all links connected to one output). When selecting “All» All connections in the diagram are rebuilt. This, of course, does not eliminate all problems, but it makes life much easier.

All links properties menu items are fully described in instructions.

Well that's all the news

Of course, you can write for a long time, describing in detail what errors were found and corrected. Detail plans for future changes.

But I won't do that. Because plans can change, and mistakes that almost no one knew about are unlikely to be of interest to anyone.

useful links

Of course, as always, I provide some useful links.

Mail. You can ask questions here. It’s not a fact that I can answer everyone quickly. But I'll try. Honestly!

shiotiny@yandex.ru

Previous articles about ShIoTiny5:

Previous articles about ShIoTiny (first version of the project, outdated):

Similar Posts

Leave a Reply

Your email address will not be published. Required fields are marked *