commit | abfa1984d2cfe5d53fd3b4aa08cc6e4b3558700d | [log] [tgz] |
---|---|---|
author | Renovate bot <renovate-bot@avm99963.com> | Sat Dec 30 00:05:17 2023 +0000 |
committer | Renovate bot <renovate-bot@avm99963.com> | Sat Dec 30 00:05:17 2023 +0000 |
tree | b06273dbe40df86a1b87062619ea3a43a346d968 | |
parent | 80d9ba2635c1993ed4d0b33087f3160b83e90087 [diff] |
chore(deps): pin dependencies Change-Id: I7018f088d79eda6d2d5b904e9bfa99fc6f708265
This program is a bridge to convert motion detection email notifications from the Hichip IP Cameras to MQTT messages. It runs continously as a daemon.
It is based in the Go-Guerilla SMTP server and a custom processor in order to process incoming emails, and in the Eclipse Paho MQTT client in order to interact with the MQTT broker to send the motion detected event details.
The bridge will receive email notifications from HiChip IP cameras directed to *@{HICHIPBRIDGE_SMTP_HOST}
. Then, it will process each message received by checking whether the message's body contains a token, and after that it will publish the event as a MQTT message in the {HICHIPBRIDGE_MQTT_TOPIC}/{USERNAME}/motion
topic, where {USERNAME}
is the username part of the email address sending the message.
The message will be a JSON string containing only a timestamp
field with the UNIX timestamp of the motion event. This is done like this because in the future additional fields will be added.
This is an example of the published MQTT messages:
{"timestamp":0}
online
message to {HICHIPBRIDGE_MQTT_TOPIC}/status
when it is started, and sets the offline
message as the last will message to the same topic, so it gets published when the daemon disconnects from the MQTT broker due to a manual stop/crash/etc.There are 2 ways to run the bridge: running the daemon binary directly, or running it as a Docker container.
First, install the daemon using the following command: go install gomodules.avm99963.com/hichip2mqtt/cmd/hichip2mqtt
Then you can run the daemon using hichipbridge serve
(make sure to include Go's bin folder in your PATH).
Before running it, though, you'll have to create a configuration file and set several environment variables.
In order to use the Docker image, you'll have to build it first (a CD system to publish the image at the Docker public registry will be developed later on). To build it, go to the cmd/hichipbridge
folder and run the following command: make docker-prod
.
Then, set up the docker-compose.yml
file to fit your needs, create a configuration file and set the environment variables.
After that, you can create and run the Docker container via docker-compose by running docker-compose up
.
The configuration file is used for the Go-Guerilla module, in order to configure the STMP server.
By default, the daemon looks for a config.json
file in the current directory, but a different location can be supplied via the -c
flag.
To learn its syntax, take a look at the documentation for the Go-Guerrilla module. You can also use the config.sample.json
file as a template.
allowed_hosts
setting, and the save_process
, validate_process
and primary_mail_host
subsettings in the backend_config
setting are overriden by the environmental variables, and so don't need to be configured in the config.json
file.Some settings are set via environment variables.
env.sample
file to see the list of environment variables that you should set..env
file (you can use the env.sample
file as a template).In order for the daemon to receive email notifications, the cameras have to be set up to send the email messages to the daemon's STMP server.
For that, configure your HiChip IP camera with the following settings:
config.json
file.{random_username}@{HICHIP_SMTP_HOST}
, where {random_username}
is ignored and can be set to anything, and {HICHIP_SMTP_HOST}
has to be set as the corresponding enviromental variable's value.{username}@{random_domain}
, where {username}
is what the daemon will understand as the camera's username, and will be used to form the MQTT topic name. {random_domain}
is ignored and can be set to anything, such as cams.example.com
.Y-Token: {HICHIP_EMAIL_TOKEN}
, where {HICHIP_EMAIL_TOKEN}
is the corresponding enviromental variable.