Compare commits
5 Commits
dev
...
add-networ
| Author | SHA1 | Date | |
|---|---|---|---|
| 26b955a1e8 | |||
| bb17ad6135 | |||
| 40c7d020d2 | |||
| 9b5adba3ed | |||
|
|
73740ffa39 |
@@ -93,3 +93,20 @@ sast:
|
|||||||
stage: test
|
stage: test
|
||||||
include:
|
include:
|
||||||
- template: Security/SAST.gitlab-ci.yml
|
- 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,3 +1,10 @@
|
|||||||
|
## [1.7.3](https://gitlab.evanrichardsonphotography.com/erichardson/py-eagle-mqtt/compare/v1.7.2...v1.7.3) (2021-04-12)
|
||||||
|
|
||||||
|
|
||||||
|
### Bug Fixes
|
||||||
|
|
||||||
|
* Empty commit to get recent changes into build (last commit should've been labeled this) ([e513752](https://gitlab.evanrichardsonphotography.com/erichardson/py-eagle-mqtt/commit/e513752c46cc0b3beb93530f6549661d67196905))
|
||||||
|
|
||||||
## [1.7.2](https://gitlab.evanrichardsonphotography.com/erichardson/py-eagle-mqtt/compare/v1.7.1...v1.7.2) (2021-04-08)
|
## [1.7.2](https://gitlab.evanrichardsonphotography.com/erichardson/py-eagle-mqtt/compare/v1.7.1...v1.7.2) (2021-04-08)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,10 +1,10 @@
|
|||||||
#!/usr/bin/env python3
|
#!/usr/bin/env python3
|
||||||
|
|
||||||
#===========================================================================
|
# ===========================================================================
|
||||||
#
|
#
|
||||||
# Eagle posting server
|
# Eagle posting server
|
||||||
#
|
#
|
||||||
#===========================================================================
|
# ===========================================================================
|
||||||
|
|
||||||
__doc__ = """
|
__doc__ = """
|
||||||
Starts a small web server. The Rain Forest Eagle is configured with
|
Starts a small web server. The Rain Forest Eagle is configured with
|
||||||
@@ -22,100 +22,116 @@ import json
|
|||||||
import bottle as B
|
import bottle as B
|
||||||
import tHome as T
|
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
|
||||||
|
}
|
||||||
|
|
||||||
#===========================================================================
|
return cfg.mqttEnergy, msg
|
||||||
def instant( client, data, cfg ):
|
|
||||||
msg = {
|
|
||||||
"time" : data.TimeUnix,
|
|
||||||
"power" : data.Power * 1000, # W
|
|
||||||
}
|
|
||||||
|
|
||||||
return ( cfg.mqttPower, msg )
|
|
||||||
|
|
||||||
#===========================================================================
|
# ===========================================================================
|
||||||
def price( client, data, cfg ):
|
def instant(client, data, cfg):
|
||||||
msg = {
|
msg = {
|
||||||
"time" : data.TimeUnix,
|
"time": data.TimeUnix,
|
||||||
"price" : data.Price,
|
"power": data.Power * 1000, # W
|
||||||
"tier" : data.Tier,
|
}
|
||||||
}
|
|
||||||
return ( cfg.mqttPrice, 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 network(client, data, cfg):
|
||||||
|
msg = {
|
||||||
|
"status": data.Status,
|
||||||
|
"description": data.Description,
|
||||||
|
"linkstrength": data.LinkStrength
|
||||||
|
}
|
||||||
|
return cfg.mqttNetwork, msg
|
||||||
|
|
||||||
|
|
||||||
|
# ===========================================================================
|
||||||
handlers = {
|
handlers = {
|
||||||
#"BlockPriceDetail" :
|
# "BlockPriceDetail" :
|
||||||
"CurrentSummation" : meter,
|
"CurrentSummation": meter,
|
||||||
#"DeviceInfo" :
|
# "DeviceInfo" :
|
||||||
#"FastPollStatus" :
|
# "FastPollStatus" :
|
||||||
"InstantaneousDemand" : instant,
|
"InstantaneousDemand": instant,
|
||||||
#"MessageCluster" :
|
# "MessageCluster" :
|
||||||
#"MeterInfo" :
|
# "MeterInfo" :
|
||||||
#"NetworkInfo" :
|
"NetworkInfo": network,
|
||||||
"PriceCluster" : price,
|
"PriceCluster": price,
|
||||||
#"Reading" :
|
# "Reading" :
|
||||||
#"ScheduleInfo" :
|
# "ScheduleInfo" :
|
||||||
#"TimeCluster" :
|
# "TimeCluster" :
|
||||||
}
|
}
|
||||||
|
|
||||||
#===========================================================================
|
|
||||||
|
|
||||||
@B.post( '/' )
|
# ===========================================================================
|
||||||
|
|
||||||
|
@B.post('/')
|
||||||
def root_post():
|
def root_post():
|
||||||
data = B.request.body.read( B.request.content_length )
|
data = B.request.body.read(B.request.content_length)
|
||||||
try:
|
try:
|
||||||
obj = T.eagle.parse( data )
|
obj = T.eagle.parse(data)
|
||||||
except:
|
except:
|
||||||
log.exception( "Error parsing Eagle posted data" )
|
log.exception("Error parsing Eagle posted data")
|
||||||
return "ERROR"
|
return "ERROR"
|
||||||
|
|
||||||
log.info( "Read packet: %s" % obj.name )
|
log.info("Read packet: %s" % obj.name)
|
||||||
|
|
||||||
func = handlers.get( obj.name, None )
|
func = handlers.get(obj.name, None)
|
||||||
if func:
|
if func:
|
||||||
topic, msg = func( client, obj, cfg )
|
topic, msg = func(client, obj, cfg)
|
||||||
if msg:
|
if msg:
|
||||||
log.info( "Publish: %s: %s" % ( topic, msg ) )
|
log.info("Publish: %s: %s" % (topic, msg))
|
||||||
|
|
||||||
payload = json.dumps( msg )
|
payload = json.dumps(msg)
|
||||||
client.publish( topic, payload )
|
client.publish(topic, payload)
|
||||||
|
|
||||||
return "ok"
|
return "ok"
|
||||||
|
|
||||||
#===========================================================================
|
|
||||||
|
# ===========================================================================
|
||||||
#
|
#
|
||||||
# Main applications script
|
# Main applications script
|
||||||
#
|
#
|
||||||
#===========================================================================
|
# ===========================================================================
|
||||||
|
|
||||||
p = argparse.ArgumentParser( prog=sys.argv[0],
|
p = argparse.ArgumentParser(prog=sys.argv[0],
|
||||||
description="T-Home Eagle Server" )
|
description="T-Home Eagle Server")
|
||||||
p.add_argument( "-c", "--configDir", metavar="configDir",
|
p.add_argument("-c", "--configDir", metavar="configDir",
|
||||||
default="/etc/tHome",
|
default="/etc/tHome",
|
||||||
help="Configuration file directory." )
|
help="Configuration file directory.")
|
||||||
p.add_argument( "-l", "--log", metavar="logFile",
|
p.add_argument("-l", "--log", metavar="logFile",
|
||||||
default=None, help="Logging file to use. Input 'stdout' "
|
default=None, help="Logging file to use. Input 'stdout' "
|
||||||
"to log to the screen." )
|
"to log to the screen.")
|
||||||
c = p.parse_args( sys.argv[1:] )
|
c = p.parse_args(sys.argv[1:])
|
||||||
|
|
||||||
# Parse the eagle config file.
|
# Parse the eagle config file.
|
||||||
cfg = T.eagle.config.parse( c.configDir )
|
cfg = T.eagle.config.parse(c.configDir)
|
||||||
log = T.eagle.config.log( cfg, c.log )
|
log = T.eagle.config.log(cfg, c.log)
|
||||||
|
|
||||||
# Create the MQTT client and connect it to the broker.
|
# 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
|
# Start the MQTT as a background thread. This way we can run the web
|
||||||
# server as the main thread here.
|
# server as the main thread here.
|
||||||
client.loop_start()
|
client.loop_start()
|
||||||
|
|
||||||
log.info( "Starting web server at port %d" % cfg.httpPort )
|
log.info("Starting web server at port %d" % cfg.httpPort)
|
||||||
B.run( host='0.0.0.0', port=cfg.httpPort, quiet=True )
|
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)
|
#Current rate label (returns rate label from meter)
|
||||||
mqttRateLabel = 'power/elec/Home/ratelabel'
|
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.
|
# Logging configuration. Env variables are allowed in the file name.
|
||||||
|
|||||||
3
sonar-project.properties
Normal file
3
sonar-project.properties
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
sonar.projectKey=erichardson_py-eagle-mqtt_AXkgI9tRLcemhRz3NCjo
|
||||||
|
sonar.qualitygate.wait=true
|
||||||
|
sonar.projectBaseDir=Docker/src
|
||||||
Reference in New Issue
Block a user