Skip to content

MPZinke/SmartCurtain

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

172 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

SmartCurtain


Description

This folder is what goes on the Arduino.

Contents

  • ./Node.ino The main Arduino program file.
  • ./Headers/ The header files for the Arduino program.
  • ./src/ The .cpp files for the Arduino program.

Installation

  • Open ~/Node/Node.ino into Arduino IDE (or equivalent).
  • Install ESP32 board library https://dl.espressif.com/dl/package_esp32_index.json
  • Install ArduinoJson library.
  • Install ArduinoMQTTClient library.
  • Edit ./src/Config.cpp.template adding your values for,
    • The pins as they are attached to the stepper driver.
    • The pulse wait time in coordination to the stepper driver settings.
    • The MQTT broker domain & port.
    • The MAC address of the device as needed.
    • Your WiFi login.
  • Save your edited ./src/Config.cpp.template as ./src/Config.cpp.
  • Compile the project to the ESP32.

Communication

The hub and curtain do a shout out to the other when they turn on. This way if the hub is already running and a curtain powers on, the hub will know, and vice versa. image

Commands

There are 3 basenames that describe a type of action:

  • ../move Command to move a curtain or set of curtains to a position.
  • ../status Command to request the status of a curtain or set of curtains.
    • Publishing to a status topic is the request for the state of the topic's subscriber.
  • ../update Command to update a curtain.
    • Publishing to an update topic is the posting of the state of the topic's publisher.
    • IE. The subscriber's known information will be updated.

Grouping

The move and status commands can be grouped on a home or room level. The curtains under either the home or room (indicated by the topic) will pickup the commands by subscribing to that topic.

Path formatting is as follows:

  • SmartCurtain/all/<command>
  • SmartCurtain/hub/<command>
  • SmartCurtain/<home_id>/<command>
  • SmartCurtain/-/<room_id>/<command>
  • SmartCurtain/-/-/<curtain_id>/<command>

Noteably, because the id for a home regardless of the home or curtain, the room regardless of the home or curtain and the curtain regardless of the home or room are unique to their respective areas, the above paths allow for easy grouping.

image

Subscribing

The Curtain automatically subscribes to

  • SmartCurtain/all/move
  • SmartCurtain/all/status
  • SmartCurtain/-/-/<curtain_id>/move
  • SmartCurtain/-/-/<curtain_id>/status
  • SmartCurtain/-/-/<curtain_id>/update

When the hub updates the curtain, it will then subscribe to

  • SmartCurtain/<home_id>/move
  • SmartCurtain/<home_id>/status
  • SmartCurtain/-/<room_id>/move
  • SmartCurtain/-/<room_id>/status

../move

Request

On a move command, a event JSON is sent

{
	"percentage": 100  // (0-100)
}

Response

Upon starting and completion of a move command, the curtain updates the hub with its status

{
	"id": 1,  // Curtain's ID (1-4294967295)
	"Home.id": 0,  // Curtain's Home's ID (1-4294967295)
	"Room.id": 0,  // Curtain's Room's ID (1-4294967295)
	// ———— HUB CAN SET CURTAIN ———— //
	"Auto Correct": false,  // Whether the Curtain is allowed to Auto Correct
	"length": 32000,  // The allowed length of the Curtain (Sets to minimum of Hub's length & Curtain's length)
	// ———— CURTAIN CAN SET HUB ———— //
	"percentage": 100,  // The current percentage of the Curtain
	"is_moving": true  // Whether the Curtain is moving
}

../status

Request

No message is sent on a status request

Response

On a status command, the curtain updates the hub with its status

{
	"id": 1,  // Curtain's ID (1-4294967295)
	// ———— HUB CAN SET CURTAIN ———— //
	"Home.id": 0,  // Curtain's Home's ID (0-4294967295)
	"Room.id": 0,  // Curtain's Room's ID (0-4294967295)
	"Auto Correct": false,  // Whether the Curtain is allowed to Auto Correct
	"length": 32000,  // The allowed length of the Curtain (Sets to minimum of Hub's length & Curtain's length)
	// ———— CURTAIN CAN SET HUB ———— //
	"percentage": 100,  // The current percentage of the Curtain
	"is_moving": true  // Whether the Curtain is moving
}

../update

Request

On an update request, the known information is received and updated where allowed if it is does not match

{
	"id": 1,  // Curtain's ID (1-4294967295)
	// ———— HUB CAN SET CURTAIN ———— //
	"Home.id": 1,  // Curtain's Home's ID (1-4294967295)
	"Room.id": 1,  // Curtain's Room's ID (1-4294967295)
	"Auto Correct": false,  // Whether the Curtain is allowed to Auto Correct
	"length": 32000,  // The allowed length of the Curtain (Sets to minimum of Hub's length & Curtain's length)
	// ———— CURTAIN CAN SET HUB ———— //
	"percentage": 0,  // The current percentage of the Curtain
	"is_moving": false  // Whether the Curtain is moving
}

Response

On an update command, the curtain does not update the Hub, as not doing so give the Curtain the power to choose what to update about itself. This also prevents possible infinite looping.


Software

Architecture

image

Sequencing

image

Hardware

image

About

RTOS multi-threaded code for an ESP-32 microcontroller to receive commands to move a curtain.

Topics

Resources

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages