Compare commits
1 Commits
v1.21.0
...
add-networ
| Author | SHA1 | Date | |
|---|---|---|---|
| 26b955a1e8 |
@@ -1,64 +0,0 @@
|
||||
name: ci
|
||||
|
||||
on:
|
||||
schedule:
|
||||
- cron: "0 10 * * *"
|
||||
push:
|
||||
branches:
|
||||
- "**"
|
||||
tags:
|
||||
- "v*.*.*"
|
||||
pull_request:
|
||||
branches:
|
||||
- "main"
|
||||
|
||||
jobs:
|
||||
docker:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v4
|
||||
- name: Docker meta
|
||||
id: meta
|
||||
uses: docker/metadata-action@v5
|
||||
with:
|
||||
# list of Docker images to use as base name for tags
|
||||
images: |
|
||||
harbor.evanshome.io/library/py-eagle-mqtt
|
||||
# generate Docker tags based on the following events/attributes
|
||||
tags: |
|
||||
type=schedule
|
||||
type=ref,event=branch
|
||||
type=ref,event=pr
|
||||
type=semver,pattern={{raw}}
|
||||
type=semver,pattern={{version}}
|
||||
type=sha
|
||||
- name: Set up Docker Buildx
|
||||
uses: docker/setup-buildx-action@v3
|
||||
- name: Login to Harbor
|
||||
if: github.event_name != 'pull_request'
|
||||
uses: docker/login-action@v3
|
||||
with:
|
||||
registry: harbor.evanshome.io
|
||||
username: ${{ secrets.HARBOR_USERNAME }}
|
||||
password: ${{ secrets.HARBOR_PASSWORD }}
|
||||
|
||||
- name: echo new tag
|
||||
run: |
|
||||
echo "${{ steps.meta.outputs.tags }}"
|
||||
|
||||
|
||||
# - name: Build and push
|
||||
# uses: docker/build-push-action@v5.3.0
|
||||
# with:
|
||||
# context: ./Docker/
|
||||
# push: ${{ github.event_name != 'pull_request' }}
|
||||
# tags: ${{ steps.meta.outputs.tags }}
|
||||
# labels: ${{ steps.meta.outputs.labels }}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -1,60 +0,0 @@
|
||||
name: Bump version
|
||||
on:
|
||||
pull_request:
|
||||
types:
|
||||
- closed
|
||||
branches:
|
||||
- master
|
||||
|
||||
jobs:
|
||||
create_release_tag:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout code
|
||||
uses: actions/checkout@v4.1.1
|
||||
with:
|
||||
ref: ${{ github.event.pull_request.merge_commit_sha }}
|
||||
fetch-depth: '0'
|
||||
|
||||
- name: Create Release Tag
|
||||
id: taggerFinal
|
||||
uses: anothrNick/github-tag-action@1.67.0
|
||||
with:
|
||||
GITHUB_TOKEN: ${{ secrets.REPO_PUSH_TOKEN }}
|
||||
WITH_V: true
|
||||
GIT_API_TAGGING: false
|
||||
|
||||
- name: Docker meta
|
||||
id: meta
|
||||
uses: docker/metadata-action@v5
|
||||
with:
|
||||
# list of Docker images to use as base name for tags
|
||||
images: |
|
||||
harbor.evanshome.io/library/py-eagle-mqtt
|
||||
# generate Docker tags based on the following events/attributes
|
||||
flavor: |
|
||||
latest=true
|
||||
tags: |
|
||||
type=schedule
|
||||
type=ref,event=branch
|
||||
type=ref,event=pr
|
||||
type=raw,value=${{ steps.taggerFinal.outputs.new_tag }}
|
||||
type=semver,pattern={{raw}}
|
||||
type=semver,pattern={{version}}
|
||||
type=sha
|
||||
- name: Set up Docker Buildx
|
||||
uses: docker/setup-buildx-action@v3
|
||||
- name: Login to Harbor
|
||||
uses: docker/login-action@v3
|
||||
with:
|
||||
registry: harbor.evanshome.io
|
||||
username: ${{ secrets.HARBOR_USERNAME }}
|
||||
password: ${{ secrets.HARBOR_PASSWORD }}
|
||||
|
||||
- name: Build and push
|
||||
uses: docker/build-push-action@v5.3.0
|
||||
with:
|
||||
context: ./Docker/
|
||||
push: true
|
||||
tags: ${{ steps.meta.outputs.tags }}
|
||||
labels: ${{ steps.meta.outputs.labels }}
|
||||
130
.gitlab-ci.yml
130
.gitlab-ci.yml
@@ -4,34 +4,74 @@
|
||||
# See https://docs.gitlab.com/ee/ci/variables/#priority-of-environment-variables
|
||||
|
||||
stages:
|
||||
#- test
|
||||
- test
|
||||
- build
|
||||
- release
|
||||
- push_local
|
||||
##- push_dockerhub
|
||||
- release
|
||||
- push_dockerhub
|
||||
|
||||
.docker_base:
|
||||
image: docker:18.09.7-dind
|
||||
services:
|
||||
- docker:18.09.7-dind
|
||||
variables:
|
||||
DOCKER_DRIVER: overlay
|
||||
DOCKER_HOST: tcp://localhost:2375/
|
||||
IMAGE_TAG: "$CI_REGISTRY_IMAGE:$CI_COMMIT_REF_SLUG"
|
||||
FF_GITLAB_REGISTRY_HELPER_IMAGE: 1
|
||||
before_script:
|
||||
- docker version
|
||||
- docker info
|
||||
- docker login -u "$CI_REGISTRY_USER" -p "$CI_REGISTRY_PASSWORD" $CI_REGISTRY
|
||||
|
||||
build:
|
||||
image: docker:24.0.7-dind
|
||||
extends:
|
||||
- .docker_base
|
||||
stage: build
|
||||
only:
|
||||
refs:
|
||||
- tags
|
||||
- branches
|
||||
services:
|
||||
- name: docker:24.0.7-dind
|
||||
command: ["--tls=false"]
|
||||
variables:
|
||||
DOCKER_DRIVER: overlay2
|
||||
DOCKER_HOST: tcp://docker:2375
|
||||
DOCKER_TLS_CERTDIR: ""
|
||||
FF_GITLAB_REGISTRY_HELPER_IMAGE: 1
|
||||
script:
|
||||
- docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY
|
||||
- docker build -t $CI_REGISTRY_IMAGE:$CI_COMMIT_SHA --build-arg BUILD_DATE=$(date -u +'%Y-%m-%dT%H:%M:%SZ') --build-arg VCS_REF=$CI_COMMIT_SHORT_SHA ./Docker/
|
||||
- docker push $CI_REGISTRY_IMAGE:$CI_COMMIT_SHA
|
||||
- docker pull $CI_REGISTRY_IMAGE:latest || true
|
||||
- >
|
||||
docker build
|
||||
--pull
|
||||
--cache-from $CI_REGISTRY_IMAGE:latest
|
||||
--tag $CI_REGISTRY_IMAGE:$CI_COMMIT_SHA
|
||||
--build-arg BUILD_DATE=$(date -u +'%Y-%m-%dT%H:%M:%SZ')
|
||||
--build-arg VCS_REF=$CI_COMMIT_SHORT_SHA
|
||||
./Docker/
|
||||
- docker push $CI_REGISTRY_IMAGE:$CI_COMMIT_SHA
|
||||
|
||||
push local:
|
||||
extends:
|
||||
- .docker_base
|
||||
stage: push_local
|
||||
variables:
|
||||
GIT_STRATEGY: none
|
||||
only:
|
||||
- master
|
||||
script:
|
||||
- docker pull $CI_REGISTRY_IMAGE:$CI_COMMIT_SHA
|
||||
- docker tag $CI_REGISTRY_IMAGE:$CI_COMMIT_SHA $CI_REGISTRY_IMAGE:latest
|
||||
- docker push $CI_REGISTRY_IMAGE:latest
|
||||
|
||||
push dockerhub:
|
||||
extends:
|
||||
- .docker_base
|
||||
stage: push_dockerhub
|
||||
variables:
|
||||
GIT_STRATEGY: none
|
||||
CI_DOCKERHUB_IMAGE: index.docker.io/evanrich/py-eagle-mqtt
|
||||
CI_DOCKERHUB_REGISTRY: docker.io
|
||||
only:
|
||||
- tags
|
||||
script:
|
||||
- docker pull $CI_REGISTRY_IMAGE:$CI_COMMIT_SHA
|
||||
- docker tag $CI_REGISTRY_IMAGE:$CI_COMMIT_SHA $CI_DOCKERHUB_IMAGE:$CI_COMMIT_REF_NAME
|
||||
- docker tag $CI_REGISTRY_IMAGE:$CI_COMMIT_SHA $CI_DOCKERHUB_IMAGE:latest
|
||||
- docker login -u "$CI_DOCKERHUB_USER" -p "$CI_DOCKERHUB_PASSWORD" $CI_DOCKERHUB_REGISTRY
|
||||
- docker push $CI_DOCKERHUB_IMAGE
|
||||
|
||||
release:
|
||||
image: node:20.11.1-alpine3.18
|
||||
image: node:13
|
||||
stage: release
|
||||
only:
|
||||
refs:
|
||||
@@ -41,40 +81,32 @@ release:
|
||||
- /^(([0-9]+)\.)?([0-9]+)\.x/
|
||||
# This matches pre-releases
|
||||
- /^([0-9]+)\.([0-9]+)\.([0-9]+)(?:-([0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*))?(?:\+[0-9A-Za-z-]+)?$/
|
||||
except:
|
||||
refs:
|
||||
- tags
|
||||
script:
|
||||
- touch CHANGELOG.md
|
||||
- apk add --no-cache git
|
||||
- git config user.email "ci-bot@evanshome.io"
|
||||
- git config user.name "ci-bot"
|
||||
- npm install @semantic-release/gitlab@12.1.1 @semantic-release/changelog@6.0.3
|
||||
@semantic-release/git@10.0.1 conventional-changelog-eslint@5.0.0
|
||||
- npm install @semantic-release/gitlab @semantic-release/changelog @semantic-release/git
|
||||
- npx semantic-release
|
||||
artifacts:
|
||||
paths:
|
||||
- CHANGELOG.md
|
||||
|
||||
push local:
|
||||
image: docker:24.0.7-dind
|
||||
stage: push_local
|
||||
services:
|
||||
- name: docker:24.0.7-dind
|
||||
command: ["--tls=false"]
|
||||
variables:
|
||||
DOCKER_DRIVER: overlay2
|
||||
DOCKER_HOST: tcp://docker:2375
|
||||
DOCKER_TLS_CERTDIR: ""
|
||||
GIT_STRATEGY: none
|
||||
FF_GITLAB_REGISTRY_HELPER_IMAGE: 1
|
||||
only:
|
||||
- master
|
||||
script:
|
||||
- echo $CI_COMMIT_TAG
|
||||
- docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY
|
||||
- docker pull $CI_REGISTRY_IMAGE:$CI_COMMIT_SHA
|
||||
- docker tag $CI_REGISTRY_IMAGE:$CI_COMMIT_SHA $CI_REGISTRY_IMAGE:latest
|
||||
- docker push $CI_REGISTRY_IMAGE:latest
|
||||
sast:
|
||||
stage: test
|
||||
include:
|
||||
- template: Security/SAST.gitlab-ci.yml
|
||||
|
||||
|
||||
sonarqube-check:
|
||||
image:
|
||||
name: sonarsource/sonar-scanner-cli:latest
|
||||
entrypoint: [""]
|
||||
variables:
|
||||
SONAR_USER_HOME: "${CI_PROJECT_DIR}/.sonar" # Defines the location of the analysis task cache
|
||||
GIT_DEPTH: "0" # Tells git to fetch all the branches of the project, required by the analysis task
|
||||
cache:
|
||||
key: "${CI_JOB_NAME}"
|
||||
paths:
|
||||
- .sonar/cache
|
||||
script:
|
||||
- sonar-scanner
|
||||
allow_failure: true
|
||||
only:
|
||||
- master # or the name of your main branch
|
||||
|
||||
@@ -1,38 +1,6 @@
|
||||
plugins:
|
||||
- - "@semantic-release/commit-analyzer"
|
||||
- preset: eslint
|
||||
releaseRules:
|
||||
- tag: Breaking
|
||||
release: major
|
||||
- tag: Build
|
||||
release: patch
|
||||
- tag: Chore
|
||||
release: minor
|
||||
- tag: Fix
|
||||
release: patch
|
||||
- tag: New
|
||||
release: minor
|
||||
- tag: Update
|
||||
release: minor
|
||||
- tag: Upgrade
|
||||
release: minor
|
||||
- - "@semantic-release/release-notes-generator"
|
||||
- preset: eslint
|
||||
releaseRules:
|
||||
- tag: Breaking
|
||||
release: major
|
||||
- tag: Build
|
||||
release: patch
|
||||
- tag: Chore
|
||||
release: minor
|
||||
- tag: Fix
|
||||
release: patch
|
||||
- tag: New
|
||||
release: minor
|
||||
- tag: Update
|
||||
release: minor
|
||||
- tag: Upgrade
|
||||
release: minor
|
||||
- "@semantic-release/commit-analyzer"
|
||||
- "@semantic-release/release-notes-generator"
|
||||
- - "@semantic-release/changelog"
|
||||
- changelogFile: CHANGELOG.md
|
||||
- "@semantic-release/gitlab"
|
||||
|
||||
58
CHANGELOG.md
58
CHANGELOG.md
@@ -1,61 +1,3 @@
|
||||
## [1.7.10](https://gitlab.evanshome.io/erichardson/py-eagle-mqtt/compare/v1.7.9...v1.7.10) (2023-12-03)
|
||||
|
||||
|
||||
### Build
|
||||
|
||||
* fix build pipeline order ([1cf67d1](https://gitlab.evanshome.io/erichardson/py-eagle-mqtt/commit/1cf67d139b8ce3954a42afeeef49262c72d9b0a5))
|
||||
|
||||
### CI
|
||||
|
||||
* add branches to refs for building ([e0da9b1](https://gitlab.evanshome.io/erichardson/py-eagle-mqtt/commit/e0da9b110e69fc4f18f6588d297589ca71a27c08))
|
||||
* Add push latest tag on master ([8e6130d](https://gitlab.evanshome.io/erichardson/py-eagle-mqtt/commit/8e6130d9195c19933054d9a4efbeeb3d025b5301))
|
||||
* fix ordering of stages ([385c1d8](https://gitlab.evanshome.io/erichardson/py-eagle-mqtt/commit/385c1d88d85e64591fd0d3814111a7e335ea45f8))
|
||||
|
||||
## [1.7.9](https://gitlab.evanshome.io/erichardson/py-eagle-mqtt/compare/v1.7.8...v1.7.9) (2023-12-03)
|
||||
|
||||
|
||||
### Build
|
||||
|
||||
* bump docker base to python:3.12-alpine ([6489f3d](https://gitlab.evanshome.io/erichardson/py-eagle-mqtt/commit/6489f3d01a71fba8e1a4ac35de2b0bffdf2529bd))
|
||||
|
||||
## [1.7.8](https://gitlab.evanshome.io/erichardson/py-eagle-mqtt/compare/v1.7.7...v1.7.8) (2023-12-03)
|
||||
|
||||
|
||||
### ci
|
||||
|
||||
* fix semantic versioning and docker push to local registry ([9ce6bb5](https://gitlab.evanshome.io/erichardson/py-eagle-mqtt/commit/9ce6bb579847fba7fd31cc7ece4bcbb0661247b8))
|
||||
|
||||
### Fix
|
||||
|
||||
* semantic versioning and docker push to local registry ([08069d6](https://gitlab.evanshome.io/erichardson/py-eagle-mqtt/commit/08069d61d135eff8c2ee5b210279589c4e4eed8f))
|
||||
|
||||
## [1.7.6](https://gitlab.evanrichardsonphotography.com/erichardson/py-eagle-mqtt/compare/v1.7.5...v1.7.6) (2021-05-10)
|
||||
|
||||
|
||||
### Build
|
||||
|
||||
* Change docker driver to overlay2 ([13cb517](https://gitlab.evanrichardsonphotography.com/erichardson/py-eagle-mqtt/commit/13cb51706b97f25486f62dd6985903e834d28ee2))
|
||||
|
||||
## [1.7.5](https://gitlab.evanrichardsonphotography.com/erichardson/py-eagle-mqtt/compare/v1.7.4...v1.7.5) (2021-05-09)
|
||||
|
||||
|
||||
### Build
|
||||
|
||||
* push all tags instead of just latest ([b143379](https://gitlab.evanrichardsonphotography.com/erichardson/py-eagle-mqtt/commit/b143379f2018f410677a9646234e7b483d9277d3))
|
||||
|
||||
## [1.7.4](https://gitlab.evanrichardsonphotography.com/erichardson/py-eagle-mqtt/compare/v1.7.3...v1.7.4) (2021-05-09)
|
||||
|
||||
|
||||
### Build
|
||||
|
||||
* cleanup long install line ([de1d073](https://gitlab.evanrichardsonphotography.com/erichardson/py-eagle-mqtt/commit/de1d073c6daf5d43fb7d9b7dafddd3b0cbcffc9b))
|
||||
|
||||
### ci
|
||||
|
||||
* Add git to node image ([6eb2d01](https://gitlab.evanrichardsonphotography.com/erichardson/py-eagle-mqtt/commit/6eb2d0145eff50c3243a364d821e769ae2ee06c9))
|
||||
* change semantic release image to alpine to save space, updated to node 16 ([b1ca049](https://gitlab.evanrichardsonphotography.com/erichardson/py-eagle-mqtt/commit/b1ca0497b0b51e0c50ca1e5f99e5c8abd4224d53))
|
||||
* Update DinD base to 20.10.6 and semantic release to node:15. Also pin sonar-scanner-cli to 4.6 ([589fb4f](https://gitlab.evanrichardsonphotography.com/erichardson/py-eagle-mqtt/commit/589fb4fcf7841d3c5f08327d7fb5d5c107562ed6))
|
||||
|
||||
## [1.7.3](https://gitlab.evanrichardsonphotography.com/erichardson/py-eagle-mqtt/compare/v1.7.2...v1.7.3) (2021-04-12)
|
||||
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
FROM python:3.12-alpine
|
||||
FROM python:3.9.4-alpine3.13
|
||||
LABEL maintainer="Evan Richardson (evanrich81[at]gmail.com)"
|
||||
|
||||
ARG BUILD_DATE
|
||||
@@ -14,20 +14,13 @@ LABEL org.label-schema.vendor="Evan Richardson"
|
||||
LABEL org.label-schema.docker.cmd="docker run --name=py-eagle-mqtt -e MQTT_BROKER_IP=<IP> -e MQTT_BROKER_PORT=1883 -p 22042:22042 -d evanrich/py-eagle-mqtt"
|
||||
|
||||
WORKDIR /app
|
||||
|
||||
COPY requirements.txt /app
|
||||
COPY ./src/conf/logrotate/tHome /etc/logrotate.d/
|
||||
|
||||
ENV PYTHONPATH=/app/src/python
|
||||
|
||||
RUN apk --update add --no-cache logrotate && \
|
||||
apk upgrade && \
|
||||
pip3 install --no-cache-dir --upgrade pip && \
|
||||
pip3 install --no-cache-dir -r requirements.txt && \
|
||||
rm -rf /var/cache/apk/*
|
||||
|
||||
RUN apk --update add --no-cache logrotate \
|
||||
&& pip3 install --no-cache-dir --upgrade pip \
|
||||
&& pip3 install --no-cache-dir -r requirements.txt
|
||||
COPY . /app
|
||||
|
||||
CMD ["python3", "-u", "/app/src/bin/tHome-eagle.py", "-c", "/app/src/conf", "-l", "stdout"]
|
||||
CMD ["/app/src/bin/tHome-eagle.py", "-c", "/app/src/conf"]
|
||||
|
||||
EXPOSE 22042
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
paho-mqtt==2.0.0
|
||||
bottle==0.12.25
|
||||
paho-mqtt==1.5.1
|
||||
bottle==0.12.19
|
||||
defusedxml==0.7.1
|
||||
|
||||
@@ -26,7 +26,7 @@ class Client ( mqtt.Client ):
|
||||
self.on_connect = Client.on_connect
|
||||
self.on_message = Client.on_message
|
||||
|
||||
def on_connect( self, userdata, flags, reason_code, properties ):
|
||||
def on_connect( self, userData, flags, rc ):
|
||||
self.subscribe( '#' )
|
||||
|
||||
def on_message( self, userData, msg ):
|
||||
@@ -62,4 +62,4 @@ client.loop_start()
|
||||
while True:
|
||||
pass
|
||||
|
||||
client.loop_stop()
|
||||
client.loop_stop( force=True )
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
#===========================================================================
|
||||
# ===========================================================================
|
||||
#
|
||||
# Eagle posting server
|
||||
#
|
||||
#===========================================================================
|
||||
# ===========================================================================
|
||||
|
||||
__doc__ = """
|
||||
Starts a small web server. The Rain Forest Eagle is configured with
|
||||
@@ -22,100 +22,116 @@ import json
|
||||
import bottle as B
|
||||
import tHome as T
|
||||
|
||||
#===========================================================================
|
||||
def meter( client, data, cfg ):
|
||||
msg = {
|
||||
"time" : data.TimeUnix,
|
||||
"consumed" : data.Consumed, # kWh
|
||||
"produced" : data.Produced, # kWh
|
||||
}
|
||||
|
||||
return ( cfg.mqttEnergy, msg )
|
||||
# ===========================================================================
|
||||
def meter(client, data, cfg):
|
||||
msg = {
|
||||
"time": data.TimeUnix,
|
||||
"consumed": data.Consumed, # kWh
|
||||
"produced": data.Produced, # kWh
|
||||
}
|
||||
|
||||
#===========================================================================
|
||||
def instant( client, data, cfg ):
|
||||
msg = {
|
||||
"time" : data.TimeUnix,
|
||||
"power" : data.Power * 1000, # W
|
||||
}
|
||||
return cfg.mqttEnergy, msg
|
||||
|
||||
return ( cfg.mqttPower, msg )
|
||||
|
||||
#===========================================================================
|
||||
def price( client, data, cfg ):
|
||||
msg = {
|
||||
"time" : data.TimeUnix,
|
||||
"price" : data.Price,
|
||||
"tier" : data.Tier,
|
||||
}
|
||||
return ( cfg.mqttPrice, msg )
|
||||
|
||||
#===========================================================================
|
||||
# ===========================================================================
|
||||
def instant(client, data, cfg):
|
||||
msg = {
|
||||
"time": data.TimeUnix,
|
||||
"power": data.Power * 1000, # W
|
||||
}
|
||||
|
||||
return cfg.mqttPower, msg
|
||||
|
||||
|
||||
# ===========================================================================
|
||||
def price(client, data, cfg):
|
||||
msg = {
|
||||
"time": data.TimeUnix,
|
||||
"price": data.Price,
|
||||
"tier": data.Tier,
|
||||
}
|
||||
return cfg.mqttPrice, msg
|
||||
|
||||
|
||||
# ===========================================================================
|
||||
def network(client, data, cfg):
|
||||
msg = {
|
||||
"status": data.Status,
|
||||
"description": data.Description,
|
||||
"linkstrength": data.LinkStrength
|
||||
}
|
||||
return cfg.mqttNetwork, msg
|
||||
|
||||
|
||||
# ===========================================================================
|
||||
handlers = {
|
||||
#"BlockPriceDetail" :
|
||||
"CurrentSummation" : meter,
|
||||
#"DeviceInfo" :
|
||||
#"FastPollStatus" :
|
||||
"InstantaneousDemand" : instant,
|
||||
#"MessageCluster" :
|
||||
#"MeterInfo" :
|
||||
#"NetworkInfo" :
|
||||
"PriceCluster" : price,
|
||||
#"Reading" :
|
||||
#"ScheduleInfo" :
|
||||
#"TimeCluster" :
|
||||
}
|
||||
# "BlockPriceDetail" :
|
||||
"CurrentSummation": meter,
|
||||
# "DeviceInfo" :
|
||||
# "FastPollStatus" :
|
||||
"InstantaneousDemand": instant,
|
||||
# "MessageCluster" :
|
||||
# "MeterInfo" :
|
||||
"NetworkInfo": network,
|
||||
"PriceCluster": price,
|
||||
# "Reading" :
|
||||
# "ScheduleInfo" :
|
||||
# "TimeCluster" :
|
||||
}
|
||||
|
||||
#===========================================================================
|
||||
|
||||
@B.post( '/' )
|
||||
# ===========================================================================
|
||||
|
||||
@B.post('/')
|
||||
def root_post():
|
||||
data = B.request.body.read( B.request.content_length )
|
||||
try:
|
||||
obj = T.eagle.parse( data )
|
||||
except:
|
||||
log.exception( "Error parsing Eagle posted data" )
|
||||
return "ERROR"
|
||||
data = B.request.body.read(B.request.content_length)
|
||||
try:
|
||||
obj = T.eagle.parse(data)
|
||||
except:
|
||||
log.exception("Error parsing Eagle posted data")
|
||||
return "ERROR"
|
||||
|
||||
log.info( "Read packet: %s" % obj.name )
|
||||
|
||||
func = handlers.get( obj.name, None )
|
||||
if func:
|
||||
topic, msg = func( client, obj, cfg )
|
||||
if msg:
|
||||
log.info( "Publish: %s: %s" % ( topic, msg ) )
|
||||
|
||||
payload = json.dumps( msg )
|
||||
client.publish( topic, payload )
|
||||
log.info("Read packet: %s" % obj.name)
|
||||
|
||||
return "ok"
|
||||
func = handlers.get(obj.name, None)
|
||||
if func:
|
||||
topic, msg = func(client, obj, cfg)
|
||||
if msg:
|
||||
log.info("Publish: %s: %s" % (topic, msg))
|
||||
|
||||
#===========================================================================
|
||||
payload = json.dumps(msg)
|
||||
client.publish(topic, payload)
|
||||
|
||||
return "ok"
|
||||
|
||||
|
||||
# ===========================================================================
|
||||
#
|
||||
# Main applications script
|
||||
#
|
||||
#===========================================================================
|
||||
# ===========================================================================
|
||||
|
||||
p = argparse.ArgumentParser( prog=sys.argv[0],
|
||||
description="T-Home Eagle Server" )
|
||||
p.add_argument( "-c", "--configDir", metavar="configDir",
|
||||
default="/etc/tHome",
|
||||
help="Configuration file directory." )
|
||||
p.add_argument( "-l", "--log", metavar="logFile",
|
||||
default=None, help="Logging file to use. Input 'stdout' "
|
||||
"to log to the screen." )
|
||||
c = p.parse_args( sys.argv[1:] )
|
||||
p = argparse.ArgumentParser(prog=sys.argv[0],
|
||||
description="T-Home Eagle Server")
|
||||
p.add_argument("-c", "--configDir", metavar="configDir",
|
||||
default="/etc/tHome",
|
||||
help="Configuration file directory.")
|
||||
p.add_argument("-l", "--log", metavar="logFile",
|
||||
default=None, help="Logging file to use. Input 'stdout' "
|
||||
"to log to the screen.")
|
||||
c = p.parse_args(sys.argv[1:])
|
||||
|
||||
# Parse the eagle config file.
|
||||
cfg = T.eagle.config.parse( c.configDir )
|
||||
log = T.eagle.config.log( cfg, c.log )
|
||||
cfg = T.eagle.config.parse(c.configDir)
|
||||
log = T.eagle.config.log(cfg, c.log)
|
||||
|
||||
# Create the MQTT client and connect it to the broker.
|
||||
client = T.broker.connect( c.configDir, log )
|
||||
client = T.broker.connect(c.configDir, log)
|
||||
|
||||
# Start the MQTT as a background thread. This way we can run the web
|
||||
# server as the main thread here.
|
||||
client.loop_start()
|
||||
|
||||
log.info( "Starting web server at port %d" % cfg.httpPort )
|
||||
B.run( host='0.0.0.0', port=cfg.httpPort, quiet=True )
|
||||
log.info("Starting web server at port %d" % cfg.httpPort)
|
||||
B.run(host='0.0.0.0', port=cfg.httpPort, quiet=True)
|
||||
|
||||
@@ -23,6 +23,9 @@ mqttPrice = 'power/elec/Home/price'
|
||||
#Current rate label (returns rate label from meter)
|
||||
mqttRateLabel = 'power/elec/Home/ratelabel'
|
||||
|
||||
#Network Info Topic (returns status, description and link strength from meter)
|
||||
mqttNetwork = 'power/elec/Home/network'
|
||||
|
||||
#===========================================================================
|
||||
#
|
||||
# Logging configuration. Env variables are allowed in the file name.
|
||||
|
||||
@@ -7,11 +7,11 @@ from . import config
|
||||
import paho.mqtt.client as mqtt
|
||||
|
||||
#===========================================================================
|
||||
class Client( mqtt.Client ):
|
||||
class Client( mqtt.Client ):
|
||||
"""Logging client
|
||||
"""
|
||||
def __init__( self, log=None ):
|
||||
mqtt.Client.__init__( self, mqtt.CallbackAPIVersion.VERSION2 )
|
||||
mqtt.Client.__init__( self )
|
||||
self._logger = log
|
||||
# Restore callbacks overwritten by stupid mqtt library
|
||||
self.on_log = Client.on_log
|
||||
|
||||
@@ -3,9 +3,8 @@
|
||||
# Arbitrary file importing utility. Does NOT modify sys.modules
|
||||
#
|
||||
#===========================================================================
|
||||
#import importlib
|
||||
import imp
|
||||
import os
|
||||
import types
|
||||
|
||||
def fimport( filePath ):
|
||||
# Read the file and compile the code. This will fail if the file
|
||||
@@ -20,7 +19,7 @@ def fimport( filePath ):
|
||||
rootName, ext = os.path.splitext( fileName )
|
||||
|
||||
# Create a new module and exec the code in it's context.
|
||||
m = types.ModuleType( rootName )
|
||||
m = imp.new_module( rootName )
|
||||
m.__file__ = absPath
|
||||
exec(code, m.__dict__)
|
||||
|
||||
|
||||
@@ -1,12 +0,0 @@
|
||||
{
|
||||
"$schema": "https://docs.renovatebot.com/renovate-schema.json",
|
||||
"extends": [
|
||||
"config:base",
|
||||
":semanticCommits"
|
||||
],
|
||||
"prConcurrentLimit": 5,
|
||||
"labels": [
|
||||
"upgrade",
|
||||
"bot"
|
||||
]
|
||||
}
|
||||
Reference in New Issue
Block a user