Enable Javascript

User Rating: 5 / 5

Star ActiveStar ActiveStar ActiveStar ActiveStar Active

Article Index

mySimpleThings (myST)

With a unlimited number of ESP32 ESP-NOW devices
mySt addressing as: building (00-19), floor (00-99), room (00-99)
Communication with YOU over a ESP32/8266 WebSocket Server and Web browser(s)/WebView
With NTP time client, OTA upload, DST/Summertime and Sunrise/Sunset
With mySimpleThings, onStart, onCommand and onAction(time/event) user functions
And included my SimpleLib library with 25 Simple "how to use it" examples

Quote from Espressif: ESP-NOW is a kind of connectionless Wi-Fi communication protocol which is defined by Espressif. In ESP-NOW, application data is encapsulated in vendor-specific action frame and then transmitted from one Wi-Fi device to another without connection. CTR with CBC-MAC Protocol(CCMP) is used to protect the action frame for security. ESP-NOW is widely used in smart light, remote controlling, sensor, etc. https://docs.espressif.com/projects/esp-idf/en/latest/api-reference/wifi/esp_now.html

My ESPNOW tricks

ESP-NOW, it’s a perfect alternative to a Mesh network and with a few tricks, the possibilities are endless.
With my myESPNOW.h, myST_lib and Arduino IDE myST_<node> templates:

  • Only twenty devices?:
    The maximum number of devices with mySimpleThings is unlimited (theoretically).
    Quote from Espressif: The maximum number of paired devices is twenty.
  • SSID Scanning to get the device MAC addresses?:
    No scanning for devises, it’s predefined in myST with a set of twenty unique MAC addresses.
  • Trick 1:
    ESP-NOW can communicate with a unlimited number of devices with a shared MAC address. We call it Shared Node. Address example MAC+Shared: 0000.
    Addresses in myST: MAC 00 to 19, Shared 00 to 99 and Paired (trick 2) 00 to 99. (20*100*100 addresses)
    In myST we use only numeric chars, but with Shared and Paired all types of chars can be used. (20*n*n addresses)
  • Trick 2:
    A “shared Node“ can have one or more devices with the same shared Node address. We call this as a Paired Node. Address example MAC+Shared+Paired: 000000. (examples: 030200, 030202, ... 030249)
  • Trick 3:
    A paired address is a private address, but if the addressing is 0302-- (two dashes on Paired) then it’s for all nodes with the Shared addressing 0302nn. So,  by example, we can switch multiple lamps, with the same field name on different locations, with only one command.
    Or we can get list, in the Web Browser, of all on-line Nodes with that shared address if we use a standard command.
  • Trick 4:
    A Node can be used as a relays station to extend the ESP-NOW Wi-Fi range.
    Not included but simple to realize.
  • Trick 5:
    ESP-NOW use the devices in AP_STA mode, so it‘s “NOT possible“ to communicate with the Home Wi-Fi Network to use a WebSocket Web browser, OTA upload or get the NTP Server time.
    But, with a little more hardware and code:
    • Communication with a Web browser:
      A ESP32/8266 WebSocket Server communicate over Serial2, and/or SoftwareSerial 74880 baud, with Node 000000. It test: “is it for me“ or “send it to Node<nnnnnn>“ and vice versa.
    • On start-up:
      1. We increment the value of “EEPROM 0“. After one minute “EEPROM 0“ is set to “0”. But, on a restart within this first minute: “EEPROM 0“ is incremented and, only if the “value == 2”, there is a time window of 5 minutes to OTA firmware upload .
      2. The NTP time Client get the time from a NTP time Server.
      3. We go in the ESP-NOW master+slave mode.
    • A new day:
      We start a new day on 04:00 night (???) A room lamp, or what ever, on evening 21:00 ON and 23:30 OFF no problem but 21:00 ON and 01:30 OFF? That is instinctively the same day. So a myST day start on 04:00:00 and end on 27:59:59.
      On 04:00 the node switch for a while to the Home Network and synchronizes the Node time with the NTP Server time.
  • Trick 6:
    With a Web browser command, a push button or reset/restart within one minute, we can set the node in OTA mode, with a time window of 5 minutes, to upload new firmware.
  • myST_Node.h:
    Declare what to do with this Node Thing.
  • myST_Start.h:
    Test what this Node Thing have to do on a start-up.
  • myST_Cmd.h:
    Process the commands of Web browser or other nodes.
  • myST_Action.h:
    Once a minute, what should be done on this time or moment (sensor(s)).
  • Special function:
    With the (Not)AtHome Nodes we can send a set of command to other nodes whit a push button, Web browser or “onAction time function“ command. Usable to switch ON/OFF-DOWN/UP heating, door lock, boiler, lighting, shutter, sun screens, ....
  • Item labels and value fields:
    • name: Item label, used by commands.
    • mode: if > 0 time actions, by example:
      1: 07:00 ON and on Sunrise +/- offset OFF
      2: Sunset +/- offset ON and 00:30 OFF
      3: 1 and 2
    • status: OFF/ON or UP/DOWN, is set to 0 or 1 (or KaKu On/Off or KaKu-DIM, or...) on start, action time or (manual) command.
      (KaKu: 433MHz Klik aan Klik uit - Click on Click off)
    • pause: if == 1 then hold the actual status. Reset to 0 by command or on 04:00 night.
      Manual or other command are possible.
  • And a set of user Thing fields (time, offset, min/max value,...). All the Thing labels an values are, on command, visible in a Web browser.
    A Node can have more than one action sets of fields, by example: lamp, boiler, heating, door lock, pond pump, ....

mySimpleThings possibilities

All you want to, and can make, with a unlimited number of ESP32 ESP-NOW Nodes.
All Nodes has/can:

  • All Nodes can comminicate with a single or Paired set of Nodes and your WebBrowser,
  • Communicate with the Nodes over Local WiFi and Internet with a WebBrowser.
    Using a WebSocket Server ESP32/8266 and Serial2/SoftwareSerial with Node "000000".
  • OTA firmware upload, with a 5 minutes time window:
    • on restart.
    • a command.
    • push button.
  • NTP time client:
    • get and sync the time on (re)start.
    • sync the time on 04:00.
      A myST_node day ends at 03:59:59 night.
  • Calculated Sunrise and Sunset for your own location.
  • Calculated or Static DST/Summertime for your own location.
  • Use buttons, sensors, steppers, radio, Lora, bluetooth(module), relays, ....
  • Switch lamps, (un)loc doors, sun-screens and/or shutters DOWN/UP, heating ON/OFF, ...
  • (Not)AtHome: switch all what you want with only one push button or command.
    • Switch a green/red flash LED.
    • Switch lamp or ... ON/OFF or DOWN/UP.
    • Send command(s) to other Nodes to switch:
      Heating, boiler, door (un)lock, ...
  • And so on....

Code to edit:

  1. <path>/libraries/myST_lib/myST_Init.h:
    Universal used parameters for all your Nodes,
    • SSID, Password.
    •  Location, Timezone, DST/Summertime rules.
  2. Each Node:
    •  myST_<address>.ino:
      Set Shared-Paired-Private address (Building-Floor-Room)
    • myST_Node.h:
      Define what this Node have to do.
      Item fields and values, extra init(), loop() and other Node related functions.
    • myST_Start.h:
      (re)Start code for this Node.
    • myST_Cmd.h:
      Handling received commands.
    • myST_Action.h:
      Ones a minute test for actions.

HOW TO communicate with myST_nodes

First to do: Insert your LOCAL SSID and Password and the IP of your WebSocket Server Node myST_WS_Server.ino in myST_WS.html. Set the IP from the WebSocket Server myST_WS_Server.ino as STATIC in your Router. Then create a Server with this IP in your Router. Use this link to get your own Internet IP address and insert it in myST_WS.html.
This myST_WS.html is a very basic but useful tool to communicate with your Nodes. Use the code as a basic for your own (graphic)tool. If your mobile Browser not works with local html-files then use FireFox. With Apple: search Internet for local-to-store solutions or use a server.
Node addresses:
Shared-Paired-Private (Building-Floor-Room) structure:
Shared (building): "00" to "19", Paired(Floor):  "00" to "99", Private(Room):  "00" to "99", and WebBrowser(WebSocket): "WS".
Addresses from room "000000" to room "199999", or post to all rooms on a floor "0000--" to "1999--".
Posting structure:
Always a even number of fields, use a white space or period as dummy field.
Basic commands: |<toRoom(s)>|WS/<fromRoom>|<CMD>|<param>|  (we use a "|" as field delimiter).
And commands: |<toRoom(s)>|<fromRoom>|<fldName>|<valName>|<fld-x>|<val-x>|<fld-y>|<val-y>|<fld-...>|<val-...>|

(example) Item Fields as set in myST_Node.h, both Node "000100" and "000101" (same Building and Floor but other Rooms)
mode: 0/1=manual/night,  status: 0/1=OFF/ON, pause: 0/1=manual/auto (04:00 reset to auto), rise/set=offset to sunrise/set-time.
The Item "lamp" and mode=1, pause=0: ON 10 minutes before Sunset, OFF 10 minutes after Sunrise.
In this case: the same fields/values for the Item "home" ("home" is a (Not)AtHome function and can also send commands to other Nodes).

const char fld {{"name", "mode", "status", "pause", "rise", "set"}, {"name", "mode", "status", "pause", "rise", "set"}};
char val {{"lamp", "1", "0", "0", "10", "10" }, {"home", "1", "0", "0", "10", "10" }};

Basic commands:

From "WS" or from from Addr to Addr:
|<toAddr>|<fromAddr>|......(here we show it with the from-Web-Browser WS address)
|<toAddr>|WS|ITEMS|.|                    get- Items number and name list
|<toAddr>|WS|LIST|item number|      get- Item[n] parameter list
|<toAddr>|WS|DATE(ot)TIME|.|        get- date and time
|<toAddr>|WS|GETTIME|.|             get- UTC/GMT UNIX TimeStamp
|<toAddr>|WS|SUN|.|                 get- today Sunrise and Sunset local time
|<toAddr>|WS|DST|.|                  get- local DST/Summertime yes/no and dates
|<toAddr>|WS|SETTIME|TimeStamp| set- UTC/GMT UNIX TimeStamp (if not using NTP-time)
|<toAddr>|WS|SETDST|0/1|OFFSET|value|  set- 0: use manual "dstOffset", 1: calc DST |<toAddr>|WS|INITVAL|.|             set- the original initial Item values
|<toAddr>|WS|OTA|.|                 start OTA upload, time window 5 minutes ---------------------------------------------------------------------------- |<toAddr>|WS|????|.| get/set Your own added commands ---------------------------------------------------------------------------- Use the LIST Item[n] parameter list to change one or more field values by field names
|<toAddr>|<fromAddr>|<fName>|<vName>|<field-1>|<value-1>|<field-n>|<value-n>|....|....| 000000 or 0000-- private/paired command (-- not accepted by all commands) |000102|WS|name|lamp|mode|2|status|1| private 02: set lamp ON and mode to 2 |0001--|WS|name|lamp|status|1|mode|2| shared --: set lamp(s) ON and mode to 2 -- use this careful, it modifies all paired private Nodes!!! addresses are declared in "myST_??????.ino" and names and values in "myST_Node.h"