Skip to content

Commit

Permalink
Integrated interface for HC-12 wireless transmission
Browse files Browse the repository at this point in the history
  • Loading branch information
Hydrosys4 committed Jul 30, 2021
1 parent 55137dd commit 88d9d44
Show file tree
Hide file tree
Showing 207 changed files with 142,110 additions and 149 deletions.
Binary file removed Documentation/Hardware NewPCB v6.odp
Binary file not shown.
Binary file removed Documentation/Hardware NewPCB v7.odp
Binary file not shown.
Binary file removed Documentation/Hardware v6.odp
Binary file not shown.
Binary file removed Documentation/application/Autowatering-problem.png
Binary file not shown.
Binary file removed Documentation/application/IMG_20160818_205134.jpg
Binary file not shown.
Binary file removed Documentation/application/IMG_20160819_084647.jpg
Binary file not shown.
Binary file removed Documentation/application/fertirrigator-items.jpg
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file removed Documentation/hardware/12v-valve.png
Binary file not shown.
Binary file removed Documentation/hardware/Black-pipe.png
Binary file not shown.
Binary file removed Documentation/hardware/Camera-Servo.jpg
Binary file not shown.
Binary file removed Documentation/hardware/Carbon-plates.jpg
Binary file not shown.
Binary file removed Documentation/hardware/DAC-MCP3008.png
Binary file not shown.
Binary file removed Documentation/hardware/DHT22.png
Binary file not shown.
Binary file removed Documentation/hardware/DS18B20tempsensor.png
Binary file not shown.
Binary file removed Documentation/hardware/Fertilizer-schema.png
Binary file not shown.
Binary file removed Documentation/hardware/Hygrometer circuit.png
Binary file not shown.
Binary file removed Documentation/hardware/Hygrometer-PWR.png
Binary file not shown.
Binary file removed Documentation/hardware/I2C-all.png
Binary file not shown.
Binary file removed Documentation/hardware/IMG_20171215_230528.jpg
Binary file not shown.
Binary file removed Documentation/hardware/Multi-fertilizers.jpg
Binary file not shown.
Binary file removed Documentation/hardware/Nema17-motor.png
Binary file not shown.
Binary file removed Documentation/hardware/PCB-mounted-text.png
Binary file not shown.
Binary file removed Documentation/hardware/Pipe-valve.jpg
Binary file not shown.
Binary file removed Documentation/hardware/Pipe-valve2.jpg
Binary file not shown.
Binary file removed Documentation/hardware/Power Protection.png
Binary file not shown.
Binary file removed Documentation/hardware/Realtimeclock.png
Diff not rendered.
Binary file removed Documentation/hardware/ServoMotor.png
Diff not rendered.
Binary file removed Documentation/hardware/StepperMotor-Connection.png
Diff not rendered.
Binary file removed Documentation/hardware/StepperMotorShieldI2C.png
Diff not rendered.
Binary file removed Documentation/hardware/assembly/AssemblyClosed.jpg
Diff not rendered.
Diff not rendered.
Diff not rendered.
Binary file removed Documentation/hardware/assembly/AssembyOpen1.jpg
Diff not rendered.
Diff not rendered.
Binary file removed Documentation/hardware/assembly/New PCB mounted.jpg
Diff not rendered.
Binary file removed Documentation/hardware/assembly/NewPCBgoodOK.jpg
Diff not rendered.
Binary file removed Documentation/hardware/assembly/camera details.jpg
Diff not rendered.
Binary file removed Documentation/hardware/assembly/electric box.jpg
Diff not rendered.
Binary file removed Documentation/hardware/electro-valve.png
Diff not rendered.
Binary file removed Documentation/hardware/ferilizer-dosing-schema.png
Diff not rendered.
Diff not rendered.
Binary file removed Documentation/hardware/fertilizer_tank.jpg
Diff not rendered.
Binary file removed Documentation/hardware/hygrometer probe2.jpg
Diff not rendered.
Binary file removed Documentation/hardware/hygrometer-measure.png
Diff not rendered.
Binary file removed Documentation/hardware/hygrometer-probe1.jpg
Diff not rendered.
Binary file removed Documentation/hardware/pipe-valve-items.jpg
Diff not rendered.
Binary file removed Documentation/hardware/power-schema.png
Diff not rendered.
Binary file removed Documentation/hardware/powersupply-dcdc.png
Diff not rendered.
Binary file removed Documentation/hardware/relay.png
Diff not rendered.
Binary file removed Documentation/hardware/relay2.png
Diff not rendered.
Binary file removed Documentation/hardware/sprinkler.png
Diff not rendered.
Binary file removed Documentation/hardware/webcam.png
Diff not rendered.
Binary file removed Documentation/setting/1-Menu.png
Diff not rendered.
Binary file removed Documentation/setting/1-Setting-ActuatorTest.png
Diff not rendered.
Binary file removed Documentation/setting/1-Setting-Clock.png
Diff not rendered.
Binary file removed Documentation/setting/1-Setting-Mail.png
Diff not rendered.
Binary file removed Documentation/setting/1-Setting-Webcam.png
Diff not rendered.
Binary file removed Documentation/setting/1-data.png
Diff not rendered.
Binary file removed Documentation/setting/1-fertilizerplan.png
Diff not rendered.
Binary file removed Documentation/setting/1-homepage.png
Diff not rendered.
Binary file removed Documentation/setting/1-image.png
Diff not rendered.
Binary file removed Documentation/setting/1-login.png
Diff not rendered.
Binary file removed Documentation/setting/1-network.png
Diff not rendered.
Binary file removed Documentation/setting/1-video.png
Diff not rendered.
Binary file removed Documentation/setting/1-wateringplan.png
Diff not rendered.
Binary file removed Documentation/setting/ActuatorTest.png
Diff not rendered.
Binary file removed Documentation/setting/Actuatortestgoing.png
Diff not rendered.
Binary file removed Documentation/setting/Automation-chart.png
Diff not rendered.
Binary file removed Documentation/setting/Automation-setting.png
Diff not rendered.
Binary file removed Documentation/setting/Login page.png
Diff not rendered.
Binary file removed Documentation/setting/Networkpage.png
Diff not rendered.
Binary file removed Documentation/setting/Networksaved.png
Diff not rendered.
Binary file removed Documentation/setting/Restoresetting.png
Diff not rendered.
Diff not rendered.
Diff not rendered.
Binary file removed Documentation/setting/SensorRealTime.png
Diff not rendered.
Binary file removed Documentation/setting/actuatortestwater2.png
Diff not rendered.
Binary file removed Documentation/setting/automation.odp
Binary file not shown.
Binary file removed Documentation/setting/clockreadings.png
Diff not rendered.
Binary file removed Documentation/setting/clocksetting.png
Diff not rendered.
Binary file removed Documentation/setting/emailsettingred.png
Diff not rendered.
Binary file removed Documentation/setting/homepage.png
Diff not rendered.
Binary file removed Documentation/setting/homepageV2.png
Diff not rendered.
Binary file removed Documentation/setting/login-2.png
Diff not rendered.
Binary file removed Documentation/setting/mailcredential.png
Diff not rendered.
Binary file removed Documentation/setting/mailexample1.png
Diff not rendered.
Binary file removed Documentation/setting/mailexample2.png
Diff not rendered.
Binary file removed Documentation/setting/mailsettingdaily.png
Diff not rendered.
Binary file removed Documentation/setting/menu.png
Diff not rendered.
Binary file removed Documentation/setting/networkconfirm.png
Diff not rendered.
Binary file removed Documentation/setting/networkpassword.png
Diff not rendered.
Binary file removed Documentation/setting/schemaP1.png
Diff not rendered.
Binary file removed Documentation/setting/schemaP4.png
Diff not rendered.
Binary file removed Documentation/setting/schemaP4v2.png
Diff not rendered.
79 changes: 0 additions & 79 deletions Documentation/setting/user guide.html

This file was deleted.

Binary file removed Documentation/setting/water2example.png
Diff not rendered.
Binary file removed Documentation/setting/wateringDOWN.png
Diff not rendered.
Binary file removed Documentation/setting/wateringUP.png
Diff not rendered.
Binary file removed Documentation/setting/webcamphototaken.png
Diff not rendered.
Binary file removed Documentation/setting/webcamsetting.png
Diff not rendered.
Binary file removed Documentation/setting/webcamsettingv1.png
Diff not rendered.
Binary file removed Documentation/setting/wpa_cli_listnetwork.png
Diff not rendered.
6 changes: 5 additions & 1 deletion GPIOEXPI2Ccontrol.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,19 +68,23 @@ def initMCP23017():
global MCPDEVICES
global ISGPIOEXP
global HWCONTROLLIST
global EXPGPIOPINLIST

MCPDEVICES={}
for i in range(0x20,0x28):
print(hex(i))

obj = MCP23017(address = i, num_gpios = 16) # MCP23017
if obj.error:
print(obj.errormsg)
else:
MCPDEVICES[hex(i)]=obj
print("MCP23017 found at address = ", hex(i))

# Add to the list of possible commands
ISGPIOEXP=False
if MCPDEVICES:
ISGPIOEXP=True

if ISGPIOEXP:
HWCONTROLLIST=["pulse/I2CGPIOEXP","stoppulse/I2CGPIOEXP","pinstate/I2CGPIOEXP","hbridge/I2CGPIOEXP"]
else:
Expand Down
223 changes: 223 additions & 0 deletions HC12control.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,223 @@
# -*- coding: utf-8 -*-

import time
from datetime import datetime,date,timedelta
import threading
import logging
import statusdataDBmod
import json
import HC12mod

logger = logging.getLogger("hydrosys4."+__name__)

ISRPI=False
HWCONTROLLIST=[]
pinlist=["14","15","4"]

def initHC12():
HC12mod.initHC12()
global ISRPI
global HWCONTROLLIST
ISRPI=HC12mod.HC12radionet.mediumconnected
if ISRPI:
HWCONTROLLIST=["readinput/HC12"]
else:
HWCONTROLLIST=[]





# IMPORTANT *****************************************************************************
# the following pins should not be set as output otherwise they lose the Serial configuration
# PIN=14 TX PIN=15 RX


# status variables

def toint(thestring, outwhenfail):
try:
f=float(thestring)
n=int(f)
return n
except:
return outwhenfail

def tonumber(thestring, outwhenfail):
try:
n=float(thestring)
return n
except:
return outwhenfail


def execute_task(cmd, message, recdata):

print(" WELLCOME TO THE HC12 CONTROL ")
print("MESSAGE " + message)

if cmd in HWCONTROLLIST:


if cmd==HWCONTROLLIST[0]: # readinput
return readinput_HC12(cmd, message, recdata)


else:
print("Command not found")
recdata.append(cmd)
recdata.append("e")
recdata.append(0)
return False;
return False;





def readinput_HC12(cmd, message, recdata):

print("HC12 inputs ..............................")

# This provides the latest reading of the device, the reading is passive, it means that the system is not sendig command to get the reading ,
# it just record the latest value send by the sensor



msgarray=message.split(":")

PIN_str=""
if len(msgarray)>1:
PIN_str=msgarray[1]


measureUnit=""
if len(msgarray)>4:
measureUnit=msgarray[4]

SensorAddress=""
if len(msgarray)>6:
SensorAddress=msgarray[6]

PIN2_str=""
if len(msgarray)>7:
PIN2_str=msgarray[7]

Topic=""
if len(msgarray)>8:
Topic=msgarray[8]

Timeperiodstr=""
if len(msgarray)>9:
Timeperiodstr=msgarray[9]
Timeperiodsec=tonumber(Timeperiodstr,0) # zero is a special case , never expire

print(" Timeperiodsec " , msgarray[9], " " , Timeperiodsec)

PIN=toint(PIN_str,-1)
PIN2=toint(PIN2_str,-1)



if (Topic==""):
print("Error, HC12 reading no topic defined", Topic)
# address not correct
logger.error("HC12 reading no topic defined %s", Topic)
recdata.append(cmd)
recdata.append("Topic not configured ")
recdata.append(0)
return True

# Get the last value pubished for this topic.
reading=0

datadict=HC12mod.GetEntityLastData(Topic)
if datadict:
result=datadict.get("value")
timestamp=datadict.get("timestamp")
isok=True
else:
print("Error, HC12 reading no Reading for the topic ", Topic)
# address not correct
logger.error("HC12 reading no Reading for the topic %s", Topic)
recdata.append(cmd)
recdata.append("Error, HC12 no Reading for the topic " + Topic)
recdata.append(0)
return True

deltaseconds=(datetime.utcnow()-timestamp).total_seconds()

print(" deltaseconds " , deltaseconds)

if deltaseconds<0:
# reading happenend in the future .... somethign wrong, issue error
print("Error, reading in the future ")
# address not correct
logger.error("reading in the future")
recdata.append(cmd)
recdata.append("Error, reading in the future ...")
recdata.append(0)
return True


# extract value
print ("HC12 sensor ", isok, " " , result)


if Timeperiodsec>0:
if ((deltaseconds+1)>Timeperiodsec):
# value not valid because too old, replace with empty string
result=""


if isok:
if result=="":
print("Error, no updates from the sensor since ", str(deltaseconds) , " (sec)")
# address not correct
logger.error(" no updates from the sensor %s (sec)", str(deltaseconds))
recdata.append(cmd)
recdata.append("Error, no updates from the sensor")
recdata.append(0)
return True

else:
reading=result
successflag=1
logger.info("HC12 input reading: %s", reading)
print("HC12 input reading ", reading)
recdata.append(cmd)
recdata.append(reading)
recdata.append(successflag)
statusmsg="HC12 last update " + '{:.1f}'.format(deltaseconds) + " seconds "
recdata.append(statusmsg)
return True


print("Error, HC12 reading")
logger.error("HC12 reading")
recdata.append(cmd)
recdata.append("Generic Error, MQTT reading")
recdata.append(0)

return True


def sendcommand(cmd, message, recdata):
# as future upgrade this function might be run asincronously using "import threading"

if ISRPI:
ack=execute_task(cmd, message, recdata)
else:
print(" Client to support HC12 not installed")
return ack


if __name__ == '__main__':

"""
to be acknowledge a message should include the command and a message to identyfy it "identifier" (example "temp"),
if arduino answer including the same identifier then the message is acknowledged (return true) command is "1"
the data answer "recdata" is a vector. the [0] field is the identifier, from [1] start the received data
"""


Loading

0 comments on commit 88d9d44

Please sign in to comment.