mirror of https://github.com/fhem/fhem-mirror.git
Compare commits
No commits in common. "4.3" and "travis" have entirely different histories.
|
@ -0,0 +1,11 @@
|
|||
# To get started with Dependabot version updates, you'll need to specify which
|
||||
# package ecosystems to update and where the package manifests are located.
|
||||
# Please see the documentation for all configuration options:
|
||||
# https://help.github.com/github/administering-a-repository/configuration-options-for-dependency-updates
|
||||
|
||||
version: 2
|
||||
updates:
|
||||
- package-ecosystem: "github-actions" # See documentation for possible values
|
||||
directory: "/" # Location of package manifests
|
||||
schedule:
|
||||
interval: "daily"
|
|
@ -0,0 +1,104 @@
|
|||
name: Update cache from SVN
|
||||
|
||||
on:
|
||||
# Allows you to run this workflow manually from the Actions tab
|
||||
workflow_dispatch:
|
||||
|
||||
#schedule:
|
||||
#- cron: '59 */3 * * *' # every third hour to keep cache up to date
|
||||
|
||||
jobs:
|
||||
# This workflow contains a single job called "build"
|
||||
mirror:
|
||||
# The type of runner that the job will run on
|
||||
runs-on: ubuntu-latest
|
||||
continue-on-error: true
|
||||
|
||||
steps:
|
||||
- name: install git-svn package
|
||||
run: |
|
||||
sudo apt-get remove git git-man
|
||||
sudo apt-get update
|
||||
sudo apt-get install git-svn --no-install-recommends
|
||||
|
||||
- name: checkout authors
|
||||
uses: actions/checkout@v4.1.5
|
||||
with:
|
||||
ref: travis
|
||||
path: ./authors
|
||||
|
||||
- name: Get current date
|
||||
id: get-date
|
||||
run: |
|
||||
echo "::set-output name=timestamp::$(/bin/date -u "+%Y%m%d%H" )"
|
||||
shell: bash
|
||||
|
||||
- name: Cache runners svn-2-git-fhem mirror directory
|
||||
# Some room for improvement because we create a new cache on every run where a new ref is fetched, this isn't very nice, normaly we need only the last one and it takes 7 days until they are deleted
|
||||
id: cache-fhem
|
||||
uses: actions/cache@v4.0.2
|
||||
with:
|
||||
path: |
|
||||
./src/fhem-mirror/.git
|
||||
key: ${{ runner.os }}-fhemsvndir-${{ steps.get-date.outputs.timestamp }}
|
||||
restore-keys: |
|
||||
${{ runner.os }}-fhemsvndir-
|
||||
|
||||
#- name: remove gitconfig
|
||||
# run: |
|
||||
# rm ./src/fhem-mirror/.git/config
|
||||
|
||||
- name: checkout main branch
|
||||
uses: actions/checkout@v4.1.5
|
||||
with:
|
||||
path: ./src/fhem-mirror
|
||||
clean: false
|
||||
|
||||
- name: generate merged authors file
|
||||
run: |
|
||||
cd /tmp
|
||||
svn log https://svn.fhem.de/fhem --xml --quiet | grep author | sort -u | perl -pe 's/.*>(.*?)<.*/$1 = $1 <>/' > ${GITHUB_WORKSPACE}/authors/authors_svn.txt;
|
||||
cat ${GITHUB_WORKSPACE}/authors/authors.txt ${GITHUB_WORKSPACE}/authors/authors_svn.txt | sort -u -k1,1 > ${GITHUB_WORKSPACE}/authors/authors_merged.txt;
|
||||
ls -la ${GITHUB_WORKSPACE}/authors/authors_merged.txt;
|
||||
|
||||
- name: fetch from svn
|
||||
id: fetchsvn
|
||||
timeout-minutes: 120
|
||||
working-directory: ./src/fhem-mirror
|
||||
run: |
|
||||
echo "::group::git svn init"
|
||||
git svn init --trunk=trunk --tags=tags --prefix=svn/ https://svn.fhem.de/fhem;
|
||||
git config --replace-all svn.authorsfile "${GITHUB_WORKSPACE}/authors/authors_merged.txt"
|
||||
git config --replace-all svn-remote.svn.preserve-empty-dirs "true" ;
|
||||
git config --replace-all svn-remote.svn.placeholder-filename ".gitkeep" ;
|
||||
echo "Current .git/config file content:";
|
||||
cat ${GITHUB_WORKSPACE}/src/fhem-mirror/.git/config;
|
||||
echo "::endgroup::"
|
||||
|
||||
echo "::set-output name=SVN_FETCH_STATUS::incomplete"
|
||||
# Run fetches after init, go pick up some base refs for the cache on first run only!
|
||||
RET=124
|
||||
c=1
|
||||
while [ $RET -eq 124 ]; do
|
||||
echo "::group::Fetch ${c}/5"
|
||||
timeout 1200 git svn --log-window-size=200 -q fetch && RET=$? || true
|
||||
if [ "$RET" -ne 0 ] && [ "$RET" -ne 124 ]; then
|
||||
echo "::set-output name=SVN_FETCH_STATUS::error"
|
||||
fi
|
||||
((c++)) && ((c==6)) && break
|
||||
echo "::endgroup::"
|
||||
done
|
||||
if [ "$RET" -eq 0 ]; then
|
||||
echo "::set-output name=SVN_FETCH_STATUS::complete"
|
||||
fi
|
||||
|
||||
# - name: Copy Workflow Files to target
|
||||
# if: ${{ steps.fetchsvn.outputs.SVN_FETCH_STATUS == 'complete' }}
|
||||
# run: |
|
||||
# cp -R ${GITHUB_WORKSPACE}/main/.github ./src/fhem-mirror
|
||||
|
||||
- name: Verify no fetch error state
|
||||
if: ${{ steps.fetchsvn.outputs.SVN_FETCH_STATUS == 'error' }}
|
||||
run: |
|
||||
echo "A permanent error occured"
|
||||
exit 1
|
|
@ -0,0 +1,143 @@
|
|||
name: Mirror from SVN
|
||||
|
||||
on:
|
||||
push:
|
||||
|
||||
# Allows you to run this workflow manually from the Actions tab
|
||||
workflow_dispatch:
|
||||
|
||||
schedule:
|
||||
- cron: '10 */10 * * *' # every hour to keep cache up to date
|
||||
|
||||
jobs:
|
||||
# This workflow contains a single job called "build"
|
||||
mirror:
|
||||
# The type of runner that the job will run on
|
||||
runs-on: ubuntu-latest
|
||||
continue-on-error: true
|
||||
|
||||
steps:
|
||||
|
||||
- name: install git-svn package
|
||||
run: |
|
||||
sudo apt-get remove git git-man
|
||||
sudo apt-get update
|
||||
sudo apt-get install git-svn --no-install-recommends
|
||||
|
||||
- name: checkout mirror config branch
|
||||
uses: actions/checkout@v4.1.5
|
||||
|
||||
- name: Get current date as seconds
|
||||
id: get-date
|
||||
run: |
|
||||
echo "timestamp=$(/bin/date -u "+%Y%m%d%H" )" >> $GITHUB_OUTPUT
|
||||
|
||||
shell: bash
|
||||
|
||||
- name: generate merged authors file
|
||||
run: |
|
||||
ls -RLa ${GITHUB_WORKSPACE}
|
||||
cd /tmp
|
||||
mkdir -p ${GITHUB_WORKSPACE}/authors
|
||||
svn log https://svn.fhem.de/fhem --xml --quiet | grep author | sort -u | perl -pe 's/.*>(.*?)<.*/$1 = $1 <>/' > ${GITHUB_WORKSPACE}/authors_svn.txt;
|
||||
cat ${GITHUB_WORKSPACE}/authors.txt ${GITHUB_WORKSPACE}/authors_svn.txt | sort -u -k1,1 > ${GITHUB_WORKSPACE}/authors/authors_merged.txt;
|
||||
ls -la ${GITHUB_WORKSPACE}/authors/authors_merged.txt;
|
||||
|
||||
- name: create tmpfs for svn repo
|
||||
run: |
|
||||
mkdir -p ./src/fhem-mirror
|
||||
sudo mount -t tmpfs -o size=3G tmpfs ./src/fhem-mirror
|
||||
|
||||
- name: Cache runners svn-2-git-fhem mirror directory
|
||||
# Some room for improvement because we create a new cache on every run where a new ref is fetched, this isn't very nice, normaly weneed only the last one and it takes 7 days until they are deleted
|
||||
id: cache-fhem
|
||||
uses: actions/cache@v4.0.2
|
||||
with:
|
||||
path: ./src/fhem-mirror/.git
|
||||
key: ${{ runner.os }}-fhemsvndir-${{ steps.get-date.outputs.timestamp }}
|
||||
restore-keys: |
|
||||
${{ runner.os }}-fhemsvndir-
|
||||
|
||||
- name: list filesystem
|
||||
run: |
|
||||
df -h ./src/fhem-mirror
|
||||
|
||||
- name: clean cache
|
||||
env:
|
||||
Clean_Cache: ${{ secrets.CLEANCACHE }}
|
||||
if: "${{ env.Clean_Cache == 'true' }}"
|
||||
run: |
|
||||
rm -r ./src/fhem-mirror/.git
|
||||
|
||||
#- name: 'Tar files'
|
||||
# run: tar -cvf ${GITHUB_WORKSPACE}/svnMirror.tar ./src/fhem-mirror/
|
||||
|
||||
#- uses: actions/upload-artifact@v2
|
||||
# with:
|
||||
# name: mirror-artifact
|
||||
# path: ./svnMirror.tar
|
||||
|
||||
- name: init mirror repository if it is not already a mirror
|
||||
timeout-minutes: 1800
|
||||
run: |
|
||||
if [[ ! -d "${GITHUB_WORKSPACE}/src/fhem-mirror/.git" ]]; then
|
||||
git init "${GITHUB_WORKSPACE}/src/fhem-mirror" ;
|
||||
cd "${GITHUB_WORKSPACE}/src/fhem-mirror";
|
||||
git svn init --trunk=trunk --tags=tags --prefix=svn/ https://svn.fhem.de/fhem;
|
||||
git config --replace-all svn-remote.svn.preserve-empty-dirs "true" ;
|
||||
git config --replace-all svn-remote.svn.placeholder-filename ".gitkeep" ;
|
||||
git config --replace-all svn.authorsfile "${GITHUB_WORKSPACE}/authors/authors_merged.txt" ;
|
||||
# Run extra fetches after init, go pick up some base refs for the cache on first run only!
|
||||
timeout 900 git svn -q fetch || timeout 900 git svn -q fetch || timeout 900 git svn -q fetch || true
|
||||
else
|
||||
echo "Current .git/config file content:";
|
||||
cat ${GITHUB_WORKSPACE}/src/fhem-mirror/.git/config;
|
||||
fi
|
||||
|
||||
- name: fetch svn to git master branch
|
||||
id: fetchsvn
|
||||
timeout-minutes: 1800
|
||||
run: |
|
||||
echo "SVN_FETCH_STATUS=incomplete" >> $GITHUB_OUTPUT
|
||||
cd "${GITHUB_WORKSPACE}/src/fhem-mirror";
|
||||
RET=0
|
||||
timeout 1800 git svn -q --log-window-size=5000 fetch || timeout 1500 git svn -q --log-window-size=5000 fetch || RET=$?;
|
||||
if [[ $RET == 0 ]]; then
|
||||
git switch master
|
||||
git config --global user.email "actions@gitbhub.com"
|
||||
git config --global user.name "Github Actions"
|
||||
git reset --hard "remotes/svn/trunk"
|
||||
echo "SVN_FETCH_STATUS=complete" >> $GITHUB_OUTPUT
|
||||
elif [[ $RET != 124 ]]; then
|
||||
echo "SVN_FETCH_STATUS=error" >> $GITHUB_OUTPUT
|
||||
fi
|
||||
|
||||
- name: Verify no fetch error state
|
||||
if: ${{ steps.fetchsvn.outputs.SVN_FETCH_STATUS == 'error' }}
|
||||
run: |
|
||||
echo "A permanent error occured"
|
||||
exit 1
|
||||
|
||||
- name: Recreate tags from svn
|
||||
if: ${{ steps.fetchsvn.outputs.SVN_FETCH_STATUS == 'complete' }}
|
||||
working-directory: ./src/fhem-mirror
|
||||
run: |
|
||||
git for-each-ref --format="%(refname:lstrip=-1) %(objectname)" refs/remotes/svn/tags/FHEM_*_? \
|
||||
| while read BRANCH REF
|
||||
do
|
||||
TAG_NAME=${BRANCH#FHEM_}
|
||||
TAG_NAME=$(echo $TAG_NAME | sed 's/_/./g')
|
||||
BODY="$(git log -1 --format=format:%B $REF)"
|
||||
echo "branch=$BRANCH ref=$REF parent=$(git rev-parse $REF^) tagname=$TAG_NAME body=$BODY" >&2
|
||||
git tag -a -f -m "$BODY" $TAG_NAME $REF^
|
||||
# git branch -r -d origin/tags/$BRANCH
|
||||
done
|
||||
|
||||
- name: push tags and commits into master branch (force)
|
||||
if: ${{ steps.fetchsvn.outputs.SVN_FETCH_STATUS == 'complete' }}
|
||||
working-directory: ./src/fhem-mirror
|
||||
run: |
|
||||
git remote set-url origin https://x-access-token:${{ secrets.GITHUB_TOKEN }}@github.com/${{ github.repository }} || git remote add origin https://x-access-token:${{ secrets.GITHUB_TOKEN }}@github.com/${{ github.repository }}
|
||||
git fetch --unshallow || true
|
||||
git push origin master --force --tags
|
||||
|
|
@ -1,13 +0,0 @@
|
|||
# The "checkoutlist" file is used to support additional version controlled
|
||||
# administrative files in $CVSROOT/CVSROOT, such as template files.
|
||||
#
|
||||
# The first entry on a line is a filename which will be checked out from
|
||||
# the corresponding RCS file in the $CVSROOT/CVSROOT directory.
|
||||
# The remainder of the line is an error message to use if the file cannot
|
||||
# be checked out.
|
||||
#
|
||||
# File format:
|
||||
#
|
||||
# [<whitespace>]<filename><whitespace><error message><end-of-line>
|
||||
#
|
||||
# comment lines begin with '#'
|
|
@ -1,15 +0,0 @@
|
|||
# The "commitinfo" file is used to control pre-commit checks.
|
||||
# The filter on the right is invoked with the repository and a list
|
||||
# of files to check. A non-zero exit of the filter program will
|
||||
# cause the commit to be aborted.
|
||||
#
|
||||
# The first entry on a line is a regular expression which is tested
|
||||
# against the directory that the change is being committed to, relative
|
||||
# to the $CVSROOT. For the first match that is found, then the remainder
|
||||
# of the line is the name of the filter to run.
|
||||
#
|
||||
# If the repository name does not match any of the regular expressions in this
|
||||
# file, the "DEFAULT" line is used, if it is specified.
|
||||
#
|
||||
# If the name "ALL" appears as a regular expression it is always used
|
||||
# in addition to the first matching regex or "DEFAULT".
|
|
@ -1,21 +0,0 @@
|
|||
# Set this to "no" if pserver shouldn't check system users/passwords
|
||||
#SystemAuth=no
|
||||
|
||||
# Put CVS lock files in this directory rather than directly in the repository.
|
||||
#LockDir=/var/lock/cvs
|
||||
|
||||
# Set `TopLevelAdmin' to `yes' to create a CVS directory at the top
|
||||
# level of the new working directory when using the `cvs checkout'
|
||||
# command.
|
||||
#TopLevelAdmin=no
|
||||
|
||||
# Set `LogHistory' to `all' or `TOFEWGCMAR' to log all transactions to the
|
||||
# history file, or a subset as needed (ie `TMAR' logs all write operations)
|
||||
#LogHistory=TOFEWGCMAR
|
||||
|
||||
# Set `RereadLogAfterVerify' to `always' (the default) to allow the verifymsg
|
||||
# script to change the log message. Set it to `stat' to force CVS to verify# that the file has changed before reading it (this can take up to an extra
|
||||
# second per directory being committed, so it is not recommended for large
|
||||
# repositories. Set it to `never' (the previous CVS behavior) to prevent
|
||||
# verifymsg scripts from changing the log message.
|
||||
#RereadLogAfterVerify=always
|
|
@ -1,19 +0,0 @@
|
|||
# This file affects handling of files based on their names.
|
||||
#
|
||||
# The -m option specifies whether CVS attempts to merge files.
|
||||
#
|
||||
# The -k option specifies keyword expansion (e.g. -kb for binary).
|
||||
#
|
||||
# Format of wrapper file ($CVSROOT/CVSROOT/cvswrappers or .cvswrappers)
|
||||
#
|
||||
# wildcard [option value][option value]...
|
||||
#
|
||||
# where option is one of
|
||||
# -f from cvs filter value: path to filter
|
||||
# -t to cvs filter value: path to filter
|
||||
# -m update methodology value: MERGE or COPY
|
||||
# -k expansion mode value: b, o, kkv, &c
|
||||
#
|
||||
# and value is a single-quote delimited value.
|
||||
# For example:
|
||||
#*.gif -k 'b'
|
|
@ -1,21 +0,0 @@
|
|||
# The "editinfo" file is used to allow verification of logging
|
||||
# information. It works best when a template (as specified in the
|
||||
# rcsinfo file) is provided for the logging procedure. Given a
|
||||
# template with locations for, a bug-id number, a list of people who
|
||||
# reviewed the code before it can be checked in, and an external
|
||||
# process to catalog the differences that were code reviewed, the
|
||||
# following test can be applied to the code:
|
||||
#
|
||||
# Making sure that the entered bug-id number is correct.
|
||||
# Validating that the code that was reviewed is indeed the code being
|
||||
# checked in (using the bug-id number or a seperate review
|
||||
# number to identify this particular code set.).
|
||||
#
|
||||
# If any of the above test failed, then the commit would be aborted.
|
||||
#
|
||||
# Actions such as mailing a copy of the report to each reviewer are
|
||||
# better handled by an entry in the loginfo file.
|
||||
#
|
||||
# One thing that should be noted is the the ALL keyword is not
|
||||
# supported. There can be only one entry that matches a given
|
||||
# repository.
|
|
@ -1,26 +0,0 @@
|
|||
# The "loginfo" file controls where "cvs commit" log information
|
||||
# is sent. The first entry on a line is a regular expression which must match
|
||||
# the directory that the change is being made to, relative to the
|
||||
# $CVSROOT. If a match is found, then the remainder of the line is a filter
|
||||
# program that should expect log information on its standard input.
|
||||
#
|
||||
# If the repository name does not match any of the regular expressions in this
|
||||
# file, the "DEFAULT" line is used, if it is specified.
|
||||
#
|
||||
# If the name ALL appears as a regular expression it is always used
|
||||
# in addition to the first matching regex or DEFAULT.
|
||||
#
|
||||
# You may specify a format string as part of the
|
||||
# filter. The string is composed of a `%' followed
|
||||
# by a single format character, or followed by a set of format
|
||||
# characters surrounded by `{' and `}' as separators. The format
|
||||
# characters are:
|
||||
#
|
||||
# s = file name
|
||||
# V = old version number (pre-checkin)
|
||||
# v = new version number (post-checkin)
|
||||
#
|
||||
# For example:
|
||||
#DEFAULT (echo ""; id; echo %s; date; cat) >> $CVSROOT/CVSROOT/commitlog
|
||||
# or
|
||||
#DEFAULT (echo ""; id; echo %{sVv}; date; cat) >> $CVSROOT/CVSROOT/commitlog
|
|
@ -1,26 +0,0 @@
|
|||
# Three different line formats are valid:
|
||||
# key -a aliases...
|
||||
# key [options] directory
|
||||
# key [options] directory files...
|
||||
#
|
||||
# Where "options" are composed of:
|
||||
# -i prog Run "prog" on "cvs commit" from top-level of module.
|
||||
# -o prog Run "prog" on "cvs checkout" of module.
|
||||
# -e prog Run "prog" on "cvs export" of module.
|
||||
# -t prog Run "prog" on "cvs rtag" of module.
|
||||
# -u prog Run "prog" on "cvs update" of module.
|
||||
# -d dir Place module in directory "dir" instead of module name.
|
||||
# -l Top-level directory only -- do not recurse.
|
||||
#
|
||||
# NOTE: If you change any of the "Run" options above, you'll have to
|
||||
# release and re-checkout any working directories of these modules.
|
||||
#
|
||||
# And "directory" is a path to a directory relative to $CVSROOT.
|
||||
#
|
||||
# The "-a" option specifies an alias. An alias is interpreted as if
|
||||
# everything on the right of the "-a" had been typed on the command line.
|
||||
#
|
||||
# You can encode a module within a module by using the special '&'
|
||||
# character to interpose another module into the current module. This
|
||||
# can be useful for creating a module that consists of many directories
|
||||
# spread out over the entire source repository.
|
|
@ -1,12 +0,0 @@
|
|||
# The "notify" file controls where notifications from watches set by
|
||||
# "cvs watch add" or "cvs edit" are sent. The first entry on a line is
|
||||
# a regular expression which is tested against the directory that the
|
||||
# change is being made to, relative to the $CVSROOT. If it matches,
|
||||
# then the remainder of the line is a filter program that should contain
|
||||
# one occurrence of %s for the user to notify, and information on its
|
||||
# standard input.
|
||||
#
|
||||
# "ALL" or "DEFAULT" can be used in place of the regular expression.
|
||||
#
|
||||
# For example:
|
||||
#ALL mail -s "CVS notification" %s
|
|
@ -1,13 +0,0 @@
|
|||
# The "rcsinfo" file is used to control templates with which the editor
|
||||
# is invoked on commit and import.
|
||||
#
|
||||
# The first entry on a line is a regular expression which is tested
|
||||
# against the directory that the change is being made to, relative to the
|
||||
# $CVSROOT. For the first match that is found, then the remainder of the
|
||||
# line is the name of the file that contains the template.
|
||||
#
|
||||
# If the repository name does not match any of the regular expressions in this
|
||||
# file, the "DEFAULT" line is used, if it is specified.
|
||||
#
|
||||
# If the name "ALL" appears as a regular expression it is always used
|
||||
# in addition to the first matching regex or "DEFAULT".
|
|
@ -1,20 +0,0 @@
|
|||
# The "taginfo" file is used to control pre-tag checks.
|
||||
# The filter on the right is invoked with the following arguments:
|
||||
#
|
||||
# $1 -- tagname
|
||||
# $2 -- operation "add" for tag, "mov" for tag -F, and "del" for tag -d
|
||||
# $3 -- repository
|
||||
# $4-> file revision [file revision ...]
|
||||
#
|
||||
# A non-zero exit of the filter program will cause the tag to be aborted.
|
||||
#
|
||||
# The first entry on a line is a regular expression which is tested
|
||||
# against the directory that the change is being committed to, relative
|
||||
# to the $CVSROOT. For the first match that is found, then the remainder
|
||||
# of the line is the name of the filter to run.
|
||||
#
|
||||
# If the repository name does not match any of the regular expressions in this
|
||||
# file, the "DEFAULT" line is used, if it is specified.
|
||||
#
|
||||
# If the name "ALL" appears as a regular expression it is always used
|
||||
# in addition to the first matching regex or "DEFAULT".
|
|
@ -1,21 +0,0 @@
|
|||
# The "verifymsg" file is used to allow verification of logging
|
||||
# information. It works best when a template (as specified in the
|
||||
# rcsinfo file) is provided for the logging procedure. Given a
|
||||
# template with locations for, a bug-id number, a list of people who
|
||||
# reviewed the code before it can be checked in, and an external
|
||||
# process to catalog the differences that were code reviewed, the
|
||||
# following test can be applied to the code:
|
||||
#
|
||||
# Making sure that the entered bug-id number is correct.
|
||||
# Validating that the code that was reviewed is indeed the code being
|
||||
# checked in (using the bug-id number or a seperate review
|
||||
# number to identify this particular code set.).
|
||||
#
|
||||
# If any of the above test failed, then the commit would be aborted.
|
||||
#
|
||||
# Actions such as mailing a copy of the report to each reviewer are
|
||||
# better handled by an entry in the loginfo file.
|
||||
#
|
||||
# One thing that should be noted is the the ALL keyword is not
|
||||
# supported. There can be only one entry that matches a given
|
||||
# repository.
|
|
@ -0,0 +1,339 @@
|
|||
GNU GENERAL PUBLIC LICENSE
|
||||
Version 2, June 1991
|
||||
|
||||
Copyright (C) 1989, 1991 Free Software Foundation, Inc.,
|
||||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
Everyone is permitted to copy and distribute verbatim copies
|
||||
of this license document, but changing it is not allowed.
|
||||
|
||||
Preamble
|
||||
|
||||
The licenses for most software are designed to take away your
|
||||
freedom to share and change it. By contrast, the GNU General Public
|
||||
License is intended to guarantee your freedom to share and change free
|
||||
software--to make sure the software is free for all its users. This
|
||||
General Public License applies to most of the Free Software
|
||||
Foundation's software and to any other program whose authors commit to
|
||||
using it. (Some other Free Software Foundation software is covered by
|
||||
the GNU Lesser General Public License instead.) You can apply it to
|
||||
your programs, too.
|
||||
|
||||
When we speak of free software, we are referring to freedom, not
|
||||
price. Our General Public Licenses are designed to make sure that you
|
||||
have the freedom to distribute copies of free software (and charge for
|
||||
this service if you wish), that you receive source code or can get it
|
||||
if you want it, that you can change the software or use pieces of it
|
||||
in new free programs; and that you know you can do these things.
|
||||
|
||||
To protect your rights, we need to make restrictions that forbid
|
||||
anyone to deny you these rights or to ask you to surrender the rights.
|
||||
These restrictions translate to certain responsibilities for you if you
|
||||
distribute copies of the software, or if you modify it.
|
||||
|
||||
For example, if you distribute copies of such a program, whether
|
||||
gratis or for a fee, you must give the recipients all the rights that
|
||||
you have. You must make sure that they, too, receive or can get the
|
||||
source code. And you must show them these terms so they know their
|
||||
rights.
|
||||
|
||||
We protect your rights with two steps: (1) copyright the software, and
|
||||
(2) offer you this license which gives you legal permission to copy,
|
||||
distribute and/or modify the software.
|
||||
|
||||
Also, for each author's protection and ours, we want to make certain
|
||||
that everyone understands that there is no warranty for this free
|
||||
software. If the software is modified by someone else and passed on, we
|
||||
want its recipients to know that what they have is not the original, so
|
||||
that any problems introduced by others will not reflect on the original
|
||||
authors' reputations.
|
||||
|
||||
Finally, any free program is threatened constantly by software
|
||||
patents. We wish to avoid the danger that redistributors of a free
|
||||
program will individually obtain patent licenses, in effect making the
|
||||
program proprietary. To prevent this, we have made it clear that any
|
||||
patent must be licensed for everyone's free use or not licensed at all.
|
||||
|
||||
The precise terms and conditions for copying, distribution and
|
||||
modification follow.
|
||||
|
||||
GNU GENERAL PUBLIC LICENSE
|
||||
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
|
||||
|
||||
0. This License applies to any program or other work which contains
|
||||
a notice placed by the copyright holder saying it may be distributed
|
||||
under the terms of this General Public License. The "Program", below,
|
||||
refers to any such program or work, and a "work based on the Program"
|
||||
means either the Program or any derivative work under copyright law:
|
||||
that is to say, a work containing the Program or a portion of it,
|
||||
either verbatim or with modifications and/or translated into another
|
||||
language. (Hereinafter, translation is included without limitation in
|
||||
the term "modification".) Each licensee is addressed as "you".
|
||||
|
||||
Activities other than copying, distribution and modification are not
|
||||
covered by this License; they are outside its scope. The act of
|
||||
running the Program is not restricted, and the output from the Program
|
||||
is covered only if its contents constitute a work based on the
|
||||
Program (independent of having been made by running the Program).
|
||||
Whether that is true depends on what the Program does.
|
||||
|
||||
1. You may copy and distribute verbatim copies of the Program's
|
||||
source code as you receive it, in any medium, provided that you
|
||||
conspicuously and appropriately publish on each copy an appropriate
|
||||
copyright notice and disclaimer of warranty; keep intact all the
|
||||
notices that refer to this License and to the absence of any warranty;
|
||||
and give any other recipients of the Program a copy of this License
|
||||
along with the Program.
|
||||
|
||||
You may charge a fee for the physical act of transferring a copy, and
|
||||
you may at your option offer warranty protection in exchange for a fee.
|
||||
|
||||
2. You may modify your copy or copies of the Program or any portion
|
||||
of it, thus forming a work based on the Program, and copy and
|
||||
distribute such modifications or work under the terms of Section 1
|
||||
above, provided that you also meet all of these conditions:
|
||||
|
||||
a) You must cause the modified files to carry prominent notices
|
||||
stating that you changed the files and the date of any change.
|
||||
|
||||
b) You must cause any work that you distribute or publish, that in
|
||||
whole or in part contains or is derived from the Program or any
|
||||
part thereof, to be licensed as a whole at no charge to all third
|
||||
parties under the terms of this License.
|
||||
|
||||
c) If the modified program normally reads commands interactively
|
||||
when run, you must cause it, when started running for such
|
||||
interactive use in the most ordinary way, to print or display an
|
||||
announcement including an appropriate copyright notice and a
|
||||
notice that there is no warranty (or else, saying that you provide
|
||||
a warranty) and that users may redistribute the program under
|
||||
these conditions, and telling the user how to view a copy of this
|
||||
License. (Exception: if the Program itself is interactive but
|
||||
does not normally print such an announcement, your work based on
|
||||
the Program is not required to print an announcement.)
|
||||
|
||||
These requirements apply to the modified work as a whole. If
|
||||
identifiable sections of that work are not derived from the Program,
|
||||
and can be reasonably considered independent and separate works in
|
||||
themselves, then this License, and its terms, do not apply to those
|
||||
sections when you distribute them as separate works. But when you
|
||||
distribute the same sections as part of a whole which is a work based
|
||||
on the Program, the distribution of the whole must be on the terms of
|
||||
this License, whose permissions for other licensees extend to the
|
||||
entire whole, and thus to each and every part regardless of who wrote it.
|
||||
|
||||
Thus, it is not the intent of this section to claim rights or contest
|
||||
your rights to work written entirely by you; rather, the intent is to
|
||||
exercise the right to control the distribution of derivative or
|
||||
collective works based on the Program.
|
||||
|
||||
In addition, mere aggregation of another work not based on the Program
|
||||
with the Program (or with a work based on the Program) on a volume of
|
||||
a storage or distribution medium does not bring the other work under
|
||||
the scope of this License.
|
||||
|
||||
3. You may copy and distribute the Program (or a work based on it,
|
||||
under Section 2) in object code or executable form under the terms of
|
||||
Sections 1 and 2 above provided that you also do one of the following:
|
||||
|
||||
a) Accompany it with the complete corresponding machine-readable
|
||||
source code, which must be distributed under the terms of Sections
|
||||
1 and 2 above on a medium customarily used for software interchange; or,
|
||||
|
||||
b) Accompany it with a written offer, valid for at least three
|
||||
years, to give any third party, for a charge no more than your
|
||||
cost of physically performing source distribution, a complete
|
||||
machine-readable copy of the corresponding source code, to be
|
||||
distributed under the terms of Sections 1 and 2 above on a medium
|
||||
customarily used for software interchange; or,
|
||||
|
||||
c) Accompany it with the information you received as to the offer
|
||||
to distribute corresponding source code. (This alternative is
|
||||
allowed only for noncommercial distribution and only if you
|
||||
received the program in object code or executable form with such
|
||||
an offer, in accord with Subsection b above.)
|
||||
|
||||
The source code for a work means the preferred form of the work for
|
||||
making modifications to it. For an executable work, complete source
|
||||
code means all the source code for all modules it contains, plus any
|
||||
associated interface definition files, plus the scripts used to
|
||||
control compilation and installation of the executable. However, as a
|
||||
special exception, the source code distributed need not include
|
||||
anything that is normally distributed (in either source or binary
|
||||
form) with the major components (compiler, kernel, and so on) of the
|
||||
operating system on which the executable runs, unless that component
|
||||
itself accompanies the executable.
|
||||
|
||||
If distribution of executable or object code is made by offering
|
||||
access to copy from a designated place, then offering equivalent
|
||||
access to copy the source code from the same place counts as
|
||||
distribution of the source code, even though third parties are not
|
||||
compelled to copy the source along with the object code.
|
||||
|
||||
4. You may not copy, modify, sublicense, or distribute the Program
|
||||
except as expressly provided under this License. Any attempt
|
||||
otherwise to copy, modify, sublicense or distribute the Program is
|
||||
void, and will automatically terminate your rights under this License.
|
||||
However, parties who have received copies, or rights, from you under
|
||||
this License will not have their licenses terminated so long as such
|
||||
parties remain in full compliance.
|
||||
|
||||
5. You are not required to accept this License, since you have not
|
||||
signed it. However, nothing else grants you permission to modify or
|
||||
distribute the Program or its derivative works. These actions are
|
||||
prohibited by law if you do not accept this License. Therefore, by
|
||||
modifying or distributing the Program (or any work based on the
|
||||
Program), you indicate your acceptance of this License to do so, and
|
||||
all its terms and conditions for copying, distributing or modifying
|
||||
the Program or works based on it.
|
||||
|
||||
6. Each time you redistribute the Program (or any work based on the
|
||||
Program), the recipient automatically receives a license from the
|
||||
original licensor to copy, distribute or modify the Program subject to
|
||||
these terms and conditions. You may not impose any further
|
||||
restrictions on the recipients' exercise of the rights granted herein.
|
||||
You are not responsible for enforcing compliance by third parties to
|
||||
this License.
|
||||
|
||||
7. If, as a consequence of a court judgment or allegation of patent
|
||||
infringement or for any other reason (not limited to patent issues),
|
||||
conditions are imposed on you (whether by court order, agreement or
|
||||
otherwise) that contradict the conditions of this License, they do not
|
||||
excuse you from the conditions of this License. If you cannot
|
||||
distribute so as to satisfy simultaneously your obligations under this
|
||||
License and any other pertinent obligations, then as a consequence you
|
||||
may not distribute the Program at all. For example, if a patent
|
||||
license would not permit royalty-free redistribution of the Program by
|
||||
all those who receive copies directly or indirectly through you, then
|
||||
the only way you could satisfy both it and this License would be to
|
||||
refrain entirely from distribution of the Program.
|
||||
|
||||
If any portion of this section is held invalid or unenforceable under
|
||||
any particular circumstance, the balance of the section is intended to
|
||||
apply and the section as a whole is intended to apply in other
|
||||
circumstances.
|
||||
|
||||
It is not the purpose of this section to induce you to infringe any
|
||||
patents or other property right claims or to contest validity of any
|
||||
such claims; this section has the sole purpose of protecting the
|
||||
integrity of the free software distribution system, which is
|
||||
implemented by public license practices. Many people have made
|
||||
generous contributions to the wide range of software distributed
|
||||
through that system in reliance on consistent application of that
|
||||
system; it is up to the author/donor to decide if he or she is willing
|
||||
to distribute software through any other system and a licensee cannot
|
||||
impose that choice.
|
||||
|
||||
This section is intended to make thoroughly clear what is believed to
|
||||
be a consequence of the rest of this License.
|
||||
|
||||
8. If the distribution and/or use of the Program is restricted in
|
||||
certain countries either by patents or by copyrighted interfaces, the
|
||||
original copyright holder who places the Program under this License
|
||||
may add an explicit geographical distribution limitation excluding
|
||||
those countries, so that distribution is permitted only in or among
|
||||
countries not thus excluded. In such case, this License incorporates
|
||||
the limitation as if written in the body of this License.
|
||||
|
||||
9. The Free Software Foundation may publish revised and/or new versions
|
||||
of the General Public License from time to time. Such new versions will
|
||||
be similar in spirit to the present version, but may differ in detail to
|
||||
address new problems or concerns.
|
||||
|
||||
Each version is given a distinguishing version number. If the Program
|
||||
specifies a version number of this License which applies to it and "any
|
||||
later version", you have the option of following the terms and conditions
|
||||
either of that version or of any later version published by the Free
|
||||
Software Foundation. If the Program does not specify a version number of
|
||||
this License, you may choose any version ever published by the Free Software
|
||||
Foundation.
|
||||
|
||||
10. If you wish to incorporate parts of the Program into other free
|
||||
programs whose distribution conditions are different, write to the author
|
||||
to ask for permission. For software which is copyrighted by the Free
|
||||
Software Foundation, write to the Free Software Foundation; we sometimes
|
||||
make exceptions for this. Our decision will be guided by the two goals
|
||||
of preserving the free status of all derivatives of our free software and
|
||||
of promoting the sharing and reuse of software generally.
|
||||
|
||||
NO WARRANTY
|
||||
|
||||
11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
|
||||
FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
|
||||
OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
|
||||
PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
|
||||
OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
|
||||
TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
|
||||
PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
|
||||
REPAIR OR CORRECTION.
|
||||
|
||||
12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
|
||||
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
|
||||
REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
|
||||
INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
|
||||
OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
|
||||
TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
|
||||
YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
|
||||
PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
|
||||
POSSIBILITY OF SUCH DAMAGES.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
How to Apply These Terms to Your New Programs
|
||||
|
||||
If you develop a new program, and you want it to be of the greatest
|
||||
possible use to the public, the best way to achieve this is to make it
|
||||
free software which everyone can redistribute and change under these terms.
|
||||
|
||||
To do so, attach the following notices to the program. It is safest
|
||||
to attach them to the start of each source file to most effectively
|
||||
convey the exclusion of warranty; and each file should have at least
|
||||
the "copyright" line and a pointer to where the full notice is found.
|
||||
|
||||
<one line to give the program's name and a brief idea of what it does.>
|
||||
Copyright (C) <year> <name of author>
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License along
|
||||
with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
|
||||
Also add information on how to contact you by electronic and paper mail.
|
||||
|
||||
If the program is interactive, make it output a short notice like this
|
||||
when it starts in an interactive mode:
|
||||
|
||||
Gnomovision version 69, Copyright (C) year name of author
|
||||
Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
|
||||
This is free software, and you are welcome to redistribute it
|
||||
under certain conditions; type `show c' for details.
|
||||
|
||||
The hypothetical commands `show w' and `show c' should show the appropriate
|
||||
parts of the General Public License. Of course, the commands you use may
|
||||
be called something other than `show w' and `show c'; they could even be
|
||||
mouse-clicks or menu items--whatever suits your program.
|
||||
|
||||
You should also get your employer (if you work as a programmer) or your
|
||||
school, if any, to sign a "copyright disclaimer" for the program, if
|
||||
necessary. Here is a sample; alter the names:
|
||||
|
||||
Yoyodyne, Inc., hereby disclaims all copyright interest in the program
|
||||
`Gnomovision' (which makes passes at compilers) written by James Hacker.
|
||||
|
||||
<signature of Ty Coon>, 1 April 1989
|
||||
Ty Coon, President of Vice
|
||||
|
||||
This General Public License does not permit incorporating your program into
|
||||
proprietary programs. If your program is a subroutine library, you may
|
||||
consider it more useful to permit linking proprietary applications with the
|
||||
library. If this is what you want to do, use the GNU Lesser General
|
||||
Public License instead of this License.
|
|
@ -0,0 +1,23 @@
|
|||
# fhem-mirror
|
||||
READ-ONLY mirror of the [main Subversion repository](http://svn.fhem.de/fhem/trunk), updated multiple times every day.
|
||||
|
||||
## Branches
|
||||
1. The [`master`](https://github.com/fhem/fhem-mirror/tree/master) branch hosts the current source code from [FHEM SVN Trunk](http://svn.fhem.de/fhem/trunk).
|
||||
2. The [`travis`](https://github.com/fhem/fhem-mirror/tree/travis) branch is controlling the mirroring process, running on [Github Actions](https://github.com/fhem/fhem-mirror/actions/workflows/mirror.yml).
|
||||
3. Under [`tags`](https://github.com/fhem/fhem-mirror/tags) FHEM Releases are mirrored also.
|
||||
|
||||
## Pull requests
|
||||
Pull requests to any other branch besides [`travis`](https://github.com/fhem/fhem-mirror/tree/travis) will be rejected.
|
||||
Instead, a module may have its own repository here on [Github.com/fhem](https://www.github.com/fhem) and will accept your patch using a [pull request](https://help.github.com/en/articles/about-pull-requests).
|
||||
|
||||
If you can't find a repository for the module you would like to contribute, visit the official [FHEM support forum](https://forum.fhem.de/) to post your patch. However, it might not be very welcome as it easily mixes up with user support requests and makes version control extremely difficult to handle. For that particular reason, please consider contacting the maintainer using the forum direct message function and send a link to where s/he can find your changed version or patch file.
|
||||
|
||||
## Author matching
|
||||
Authors from the Subversion repository will be referred here without any email relation.
|
||||
|
||||
Those that also have an Github.com account might have a different username here.
|
||||
|
||||
The [`authors.txt`](https://github.com/fhem/fhem-mirror/blob/travis/authors.txt) file will ensure to re-write authors from the Subversion repository to their Github.com username and email address.
|
||||
Should an author want to be re-matched for any _future_ commits, s/he may modify [`authors.txt`](https://github.com/fhem/fhem-mirror/blob/travis/authors.txt) file and send a [Git pull request](https://help.github.com/articles/creating-a-pull-request-from-a-fork/).
|
||||
|
||||
For that purpose, remember to fork the correct branch [`travis`](https://github.com/fhem/fhem-mirror/tree/travis), _not_ the [`master`](https://github.com/fhem/fhem-mirror/tree/master) branch.
|
|
@ -0,0 +1,17 @@
|
|||
(no author) = unknown <>
|
||||
root = unknown <>
|
||||
fhemupdate = svc8083 <svc8083@users.noreply.github.com>
|
||||
loredo = jpawlowski <jpawlowski@users.noreply.github.com>
|
||||
justme1968 = justme-1968 <justme-1968@users.noreply.github.com>
|
||||
CoolTux = LeonGaultier <LeonGaultier@users.noreply.github.com>
|
||||
neubert = borisneubert <borisneubert@users.noreply.github.com>
|
||||
Sidey = sidey79 <sidey79@users.noreply.github.com>
|
||||
yoda_gh = gernot-h <gernot-h@users.noreply.github.com>
|
||||
DeeSPe = deespe <DeeSPe@users.noreply.github.com>
|
||||
igami = igami <igami@users.noreply.github.com>
|
||||
KernSani = KernSani <KernSani@users.noreply.github.com>
|
||||
hexenmeister = hexenmeister <hexenmeister@users.noreply.github.com>
|
||||
eisler = eisler <eisler@users.noreply.github.com>
|
||||
marvin78 = marvin78 <marvin78@users.noreply.github.com>
|
||||
dominik = dominikkarall <dominikkarall@users.noreply.github.com>
|
||||
DS_Starter = nasseeder1 <nasseeder1@users.noreply.github.com>
|
412
fhem/CHANGED
412
fhem/CHANGED
|
@ -1,412 +0,0 @@
|
|||
- 2005-10-27 (1.3)
|
||||
- Bugfix: multiple at commands at the same time.</pre>
|
||||
|
||||
- 2005-11-10 (1.4)
|
||||
- Reformatting the package and the documentation
|
||||
- New links
|
||||
|
||||
- 2005-12-26 (1.5)
|
||||
- "modularized" in preparation for the FHZ80B -> each device has a type
|
||||
- added relative "at" commands (with +HH:MM:SS)
|
||||
- multiple commands on one line separated with ;
|
||||
- sleeping 0.22 seconds after an ST command
|
||||
- some commands/syntax changed:
|
||||
- switch => set
|
||||
- device => fhzdevice
|
||||
- define <name> ... => define <name> <type> ...
|
||||
- the state of the devices and the at commands are saved
|
||||
- at start always sending a "set 0001 00 01" to enable the FHZ receiever.
|
||||
This is a workaround.
|
||||
- doc rewrite, examples directory
|
||||
|
||||
- 2006-01-03 (1.6)
|
||||
- signal handling (to save the state on shutdown)
|
||||
- module FHZ addded (for the FHZ1000PC device itself)
|
||||
- added the get function (to make the initialization prettier)
|
||||
- the module ST was renamed to FS20
|
||||
- FS20 timer commands added
|
||||
- modules command removed (we are loading everything from the modpath
|
||||
directory)
|
||||
- FHT80b module added (yes, it is already useful, you can set
|
||||
and view a lot of values)
|
||||
- documentation adapted
|
||||
- Added a TODO file
|
||||
|
||||
- 2006-01-04 (1.7)
|
||||
- the at command can be used to execute something repeatedly with *
|
||||
- ntfy can filter on device or on device+event with a regexp
|
||||
- checking the delete and notify regexps if they make sense
|
||||
- the FHT init string is now a set command (refreshvalues)
|
||||
- shutdown saves the detailed device information too
|
||||
|
||||
- 2006-01-05 (1.8)
|
||||
- Bugfix: detailed FS20 status was not set from external event
|
||||
- Bugfix: setstate for FS20 returned the last state set
|
||||
- Bugfix: undefined FS20 devices (can) crash the server
|
||||
- HMS module added by Martin Mueller
|
||||
(currently supporting the HMS100T & HMS100TF)
|
||||
- Log modules added, the first one being a simple FileLog
|
||||
(inspired by Martin Mueller)
|
||||
- A little gnuplot script to display temperature and actuator changes
|
||||
|
||||
- 2006-02-10 (1.9)
|
||||
(aka as the Juergen release)
|
||||
- The FHZ1300 is reported to work
|
||||
- Bugfix: spaces before comment in the config file should be ignored
|
||||
- added FS20STR codes to 10_FS20.pm
|
||||
- names restricted to A-Za-z0-9.:- (especially _ is not allowed)
|
||||
- delete calles now an UndefFn in the module
|
||||
- implementation of FS20 function group/local master/global master
|
||||
- the list command tells you the definition of the device too
|
||||
|
||||
- 2006-02-12 (1.9a)
|
||||
- Bugfix: wrong rights for HMS and wrong place for readonly
|
||||
(thanks to Juergen)
|
||||
|
||||
- 2006-02-12 (1.9b)
|
||||
- Bugfix: Fixing the same bug again (thanks to Martin)
|
||||
|
||||
- 2006-04-02 (2.0)
|
||||
- XmlList and webfrontend/pgm1 programs from Raoul Matthiessen
|
||||
- list tries to display the state and not the last command
|
||||
- Both log facilities (FileLog and Log) take wildcards
|
||||
(week, year, month, etc) to make logfile rotating easier
|
||||
- webfrontend/pgm2
|
||||
|
||||
- 2006-04-15 (2.1)
|
||||
- webfrontend/pgm2 changes:
|
||||
- make it work on Asus dsl-routers (no "use warnings")
|
||||
- css/readonly configurable
|
||||
- Formatting for HMS data
|
||||
- comments can be added to each device (setstate <dev> comment:xxx)
|
||||
- testbed to dry-test functionality (test directory)
|
||||
- added an empty hull for the KS300 weather module
|
||||
- added undocumented "exec" function to call arbitrary program parts
|
||||
for debugging. Example: exec FhzDecode("81xx04xx0101a0011234030011");
|
||||
- webfrontend/pgm3, contributed by Martin Haas
|
||||
- fixed pgm1: changing values should work now
|
||||
|
||||
- 2006-05-20 (2.2)
|
||||
- FHZ1300 support verified (+ doc changes)
|
||||
- KS300 support added (with Temperature, Humidity, Wind speed, Rain).
|
||||
Not verified/undecoded: subzero temp, weak battery, Is-raining flag,
|
||||
wind speed > 100km/h
|
||||
- webpgm2 log fix for "offed" FHT devices (with no actuator data)
|
||||
- webpgm3 upgrade (by Martin Haas, see webpgm/pgm3/docs/CHANGES for details)
|
||||
- HMS logging/state format changed to make it similar to KS300
|
||||
- added HMS100WD (thanks to Sascha Pollok)
|
||||
- ntfy/logging changed to be able to notify for multiple attributes
|
||||
arriving in one message
|
||||
- central FHTcode settable (see commandref.html)
|
||||
- optionally listen for non-local requests (port <num> global)
|
||||
- unknown logging
|
||||
- FAQ
|
||||
|
||||
- 2006-6-22 (2.3)
|
||||
- CRC checking (i.e. ignoring messages with bad CRC, message on verbose 4)
|
||||
- contrib/checkmesg.pl added to check message consistency (debugging)
|
||||
- FHT: unknown_aa, unknown_ba codes added. What they are for?
|
||||
- Empty modpath / no modpath error messages added (some user think modpath is
|
||||
superfluous)
|
||||
- Unparsed messages (verbose 5) now printed as hex
|
||||
- Try to reattach to the usb device if it disappears: no need to
|
||||
restart the server if the device is pulled out from the USB socket and
|
||||
plugged in again (old versions go into a busy loop here).
|
||||
- Supressing the seldom (ca 1 out of 700) short KS300 messages.
|
||||
(not sure how to interpret them)
|
||||
- Added KS300 "israining" status flag. Note: this not always triggers when it
|
||||
is raining, but there seems to be a correlation. To be evaluated in more
|
||||
detail.
|
||||
- notifyon can now execute "private" perl code as well (updated
|
||||
commandref.html, added the file example/99_PRIV.pm)
|
||||
- another "perl code" example is logging the data into the database
|
||||
(with DBI), see the file contrib/91_DbLog.pm. Tested with an Oracle DB.
|
||||
- logs added to the xmllist
|
||||
- FHT80b: Fix measured-temp over 25.5 (handling the tempadd messages better)
|
||||
|
||||
- 2006-07-23 (2.4)
|
||||
- contrib/four2hex (to convert between ELV and our codes) by Peter Stark
|
||||
- make dist added to set version (it won't work in a released version)
|
||||
- reload function to reload (private) perl modules
|
||||
- 20_FHT.pm fix: undef occures once without old data
|
||||
- "setstate comment" is replaced with the attr command (i.e. attribute).
|
||||
The corresponding xmllist COMMENT tag is replaced with the ATTR tag.
|
||||
Devices or logs can have attr definitions.
|
||||
- webfrontend/pgm2 (fhzweb.pl) updated to handle "room" attributes(showing
|
||||
only devices in this room).
|
||||
- version 0.4.2 of webfrontend/pgm3 integrated.
|
||||
- contrib/ks300avg.pl to compute daily and monthly avarage values.
|
||||
- the 40_KS300.pm module is computing daily and monthly avarages for the
|
||||
temp/hum and wind values and sum of the rain. The cum_day and cum_month
|
||||
state variables are used as helper values. To log the avarage use the
|
||||
.*avg.* regexp. The regexp for the intraday log will trigger it also.
|
||||
- Added the contrib file garden.pl as a more complex example: garden
|
||||
irrigation. The program computes the time for irrigation from the avarage
|
||||
temperature reported by the ks300-2.
|
||||
- Enable uppercase hex codes (Bug reported by STefan Mayer)
|
||||
- Renamed the unknown_XX FHT80b codes to code_XXXXXX, this will produce
|
||||
"Undefined type" messages when reading the old save file
|
||||
- RM100-2 added (thanks for the codes from andikt).
|
||||
|
||||
- 2006-08-13 (2.5)
|
||||
Special thanks to STefan Mayer for a lot of suggestions and bug reports
|
||||
- If a command is enclosed in {}, then it will be evaluated as a perl
|
||||
expression, if it is enclosed in "" then it is a shell command, else it is
|
||||
a "normal" fhz1000 command.
|
||||
"at" and "notifyon" follow this convention too.
|
||||
Note: a shell command will always be issued in the background.
|
||||
- won't die anymore if the at spec contains an unknown command
|
||||
- rereadcfg added. Sending a HUP should work better now
|
||||
- escaping % and @ in the notify argument is now possible with %% or @@
|
||||
- new command trigger to test notify commands
|
||||
- where you could specify an fhz command, now you can specify a list of
|
||||
them, separated by ";". Escape is ;;
|
||||
- KS300 sometimes reports "negative" rain when it begins to rain. Filter
|
||||
such values. israining is set when the raincounter changed or the ks300
|
||||
israining bit is set.
|
||||
- sleep command, with millisecond accuracy
|
||||
- HMS 100MG support by Peter Stark.
|
||||
- Making FHT and FS20 messages more uniform
|
||||
- contrib/fs20_holidays.sh by STefan Mayer
|
||||
(simulate presence while on holiday)
|
||||
- webfrontends/pgm4 by STefan Mayer: fs20.php
|
||||
- KS300 avg. monthly values fixed (hopefully)
|
||||
- deleted undocumented "exec" function (you can write it now as {...})
|
||||
|
||||
- 2006-09-08 (2.6)
|
||||
- bugfix: updated the examples (hint from Juergen)
|
||||
- bugfix: leading and trailing whitespaces in commands are ignored now
|
||||
- feature: making life easier for perl oneliners: see commandref.html
|
||||
(motivated by STefans suggestions)
|
||||
- feature: include command and multiline commands in the configfiles (\)
|
||||
- bugfix: web/pgm2 KS300 rain plot knows about the avg data
|
||||
- bugfix: the FHT > 25.5 problem. Needs to be tested.
|
||||
- feature: log unknown devices (peters idea, see notifyon description)
|
||||
- feature: HMS wildcard device id for all HMS devices. See the define/HMS
|
||||
section in the commandref.html for details.
|
||||
NOTE: the wildcard for RM100-2 changed from 1001 to 1003.
|
||||
(peters idea)
|
||||
- feature: rolwzo_no_off.sh contrib file (for those who were already closed
|
||||
out by automatically closing rollades, by Martin)
|
||||
- feature: the current version (0.4.5) of the pgm3 from Martin.
|
||||
|
||||
- 2006-09-13 (2.6a)
|
||||
- bugfix: the FHT > 25.5 problem again. A never ending story.
|
||||
|
||||
- 2006-10-03 (2.7)
|
||||
- bugfix: Another try on the > 25.5 problem. (Peters suggestion)
|
||||
- feature: 99_ALARM.pm from Martin (in the contrib directory)
|
||||
- feature: HMS100TFK von Peter P.
|
||||
- feature: attribute loglevel
|
||||
- feature: attribute dummy
|
||||
- feature: attr command documented
|
||||
- feature: the current version (0.5a) of the pgm3 from Martin.
|
||||
|
||||
- 2006-11-08 (2.8)
|
||||
- feature: store oldvalue for triggers. perl only. requested by peter.
|
||||
- feature: inform cmd. Patch by Martin. There are many Martins around here :-)
|
||||
- bugfix: XML: fix & and < and co
|
||||
- bugfix: Accept KS300 negative temperature values
|
||||
- change: the FS20 msg "rain-msg" is called now "activate"
|
||||
- feature: start/stop rc script from Stefan (in the contrib directory)
|
||||
- feature: attribute extra_notify: setting the device will trigger a notify
|
||||
- feature: optional repeat count for the at command
|
||||
- feature: skip_next attribute for the at command
|
||||
- feature: WS300 support by Martin. Check the contrib/ws300 directory.
|
||||
- bugfix: 91_DbLog.pm: retry if the connection is broken by Peter
|
||||
- feature: Martin's pgm3-0.5.2 (see the CHANGELOG on his webpage)
|
||||
- feature: RRD logging example by Peter (in the contrib/rrd directory)
|
||||
|
||||
- 2006-11-19 (2.9)
|
||||
- bugfix: fhz1000.pl dies at startup if the savefile does not exist
|
||||
- bugfix: oldvalue hash is not initialized at startup (peter, Nov 09)
|
||||
- feature: Notify reorganization (requested by juergen and matthias) :
|
||||
- inform will be notified on both real events and set or trigger commands
|
||||
- filelogs will additionally be notified on set or trigger commands
|
||||
- the extra_notify flag is gone: it is default now, there is a
|
||||
do_not_notify flag for the opposite behaviour.
|
||||
- feature: at timespec as a function. Example: at +*{sunset()}
|
||||
commandref.html and examples revisited.
|
||||
- feature: 99_SUNRISE.pm added to use with the new at functionality
|
||||
(replaces the old 99_SUNSET.pm)
|
||||
- feature: webpgm2 "everything" room, at/notify section, arbitrary command
|
||||
- bugfix: resetting the KS300
|
||||
- feature: updated ws300pc (from martin klerx, Nov 08)
|
||||
- bugfix: parsing timed commands implemented => thermo-off,thermo-on and
|
||||
activate replaced with timed off-for-timer,on-for-timer and
|
||||
on-old-for-timer (reported by martin klerx, Nov 08)
|
||||
- feature: pidfile (requested by peter, Nov 10)
|
||||
- bugfix: function 81 is not allowed
|
||||
|
||||
- 2006-11-27 (2.9a)
|
||||
- bugfix: FileLog+Unknown device generates undefined messages
|
||||
- bugfix: trigger with unknown device generates undefined messages
|
||||
|
||||
- 2006-12-28 (3.0)
|
||||
- bugfix: KS300: Make the temperature negative, not the humidity
|
||||
- bugfix: generate correct xmllist even with fhzdev none (Martin, 12.12)
|
||||
- feature: one set command can handle multiple devices (range and enumeration)
|
||||
- feature: new FS20 command on-till
|
||||
- feature: perl: the current state is stored in the %value hash
|
||||
- feature: perl: sunset renamed to sunset_rel, sunset_abs added (for on-till)
|
||||
- feature: perl: isday function added
|
||||
- feature: follow-on-for-timer attribute added to set the state to off
|
||||
- bugfix: the ws300pc negative-temp bugfix included (from Martin Klerx)
|
||||
- feature: version 0.6.2 of the webpgm3 included (from Martin Haas)
|
||||
|
||||
- 2007-01-08 (3.1)
|
||||
- bugfix: delete checks the arg first "exactly", then as a regexp
|
||||
- bugfix: sun*_rel does not work correctly with offset (Martin)
|
||||
- feature: FAQ entry on how to install the sunrise stuff.
|
||||
- feature: the inner core is modified to be able to handle
|
||||
more than one "IO" device, i.e multiple FHZ at the same time,
|
||||
or FHZ + FS10 + WS300. Consequences:
|
||||
- "fhzdev <usbdevice>" replaced with "define <FHZNAME> FHZ <usbdevice>"
|
||||
- "sendraw <fn> <code>" replaced with "set <FHZNAME> raw <fn> <code>"
|
||||
- module function parameters changed (for module developers)
|
||||
- set FHZ activefor dev
|
||||
- select instead sleep after sending FHZ commands
|
||||
- the at timer is more exact (around 1msec instead of 1 sec)
|
||||
- ignoring FS20 device 0001/00/00
|
||||
- feature: contrib/serial.pm to debug serial devices.
|
||||
- feature: WS300 integrated: no external program needed (Martin)
|
||||
- feature: updated to pgm3-0.7.0, see the CHANGELOG at Martins site
|
||||
|
||||
- 2007-01-14 (3.2)
|
||||
- bugfix: example $state changed to $value (remco)
|
||||
- bugfix: sun*_rel does not work correctly with offset (Sebastian)
|
||||
- feature: new HMS100TF codes (Sebastian)
|
||||
- feature: logging unknown HMS with both unique and class ID (Sebastian)
|
||||
- feature: WS300: "Wetter-Willi-Status", rain_raw/rain_cum added, historic
|
||||
data (changes by Martin & Markus)
|
||||
- bugfix: broken rereadcfg / CommandChain after init
|
||||
(reported by Sebastian and Peter)
|
||||
- bugfix: sunrise_coord returned "3", which is irritating
|
||||
|
||||
- 2007-01-25 (3.3)
|
||||
- bugfix: 50_WS300.pm fix from Martin
|
||||
- bugfix: pidfile does not work as expected (reported by Martin)
|
||||
- bugfix: %U in the log-filename is wrong (bugreport by Juergen)
|
||||
- feature: %V added to the log-filename
|
||||
- feature: KS300 wind calibration possibility added
|
||||
- feature: (software) filtering repeater messages (suggested by Martin)
|
||||
- feature: the "client" fhz1000.pl can address another host
|
||||
- bugfix: empty FHT battery is not reported (by Holger)
|
||||
- feature: new FHT codes, e.g. month/day/hour/minute setting (by Holger)
|
||||
|
||||
- 2007-04-14 (4.0)
|
||||
- bugfix: deny at +{3}... (only +*{3} allowed), reported by Bernd, 25.01
|
||||
- bugfix: allow numbers greater then 9 in at +{<number>}
|
||||
- feature: new 50_WS300.pm from Martin (bugfix + rain statistics, 26.01)
|
||||
- feature: renamed fhz1000 to fhem
|
||||
- feature: added HISTORY and README.DEV
|
||||
- doc: Added description of attribute "model".
|
||||
- bugfix: delete the pidfile when terminating. (reported by Martin and Peter)
|
||||
- feature: attribute showtime in web-pgm2 (show time instead of state)
|
||||
- feature: defattr (default attribute for following defines)
|
||||
- feature: added em1010.pl to the contrib directory
|
||||
- doc: added linux.html (multiple devices, udev-links)
|
||||
- REORGANIZATION:
|
||||
- at/notify "renamed" to "define <name> at/notify"
|
||||
- logfile/modpath/pidfile/port/verbose "renamed" to "attr global xxx"
|
||||
- savefile renamed to "attr global statefile"
|
||||
- save command added, it writes the configfile and the statefile
|
||||
- delattr added
|
||||
- list/xmllist format changed
|
||||
- disable attribute for at/notify/filelog
|
||||
See HISTORY for details and reasoning
|
||||
- added rename command
|
||||
- webpgm2 adapted to the new syntax, added device specific attribute
|
||||
and "set" support, gnuplot files are configurable, links to the
|
||||
documentation added.
|
||||
- bugfix: more thorough serial line initialization
|
||||
|
||||
- 2007-08-05 (4.1)
|
||||
- doc: linux.html (private udev-rules, not 50-..., ATTRS)
|
||||
- bugfix: setting devices with "-" in their name did not work
|
||||
- doc: fhem.pl and commandref.html (notifyon -> notify, correction
|
||||
of examples)
|
||||
- feature: modify command added
|
||||
- feature: The "-" in the name is not allowed any more
|
||||
- bugfix: disabled notify causes "uninitialized value" (STefan, 1.5)
|
||||
- bugfix: deleted FS20 items are still logging (zombie) (Gerhard, 16.5)
|
||||
- bugfix: added FS20S8, removed stty_parmrk (Martin, 24.5)
|
||||
- feature: added archivedir/archivecmd to the FileLog
|
||||
- feature: added EM1010PC/EM1000WZ/EM1000EM support
|
||||
- bugfix: undefined messages for unknown HMS devs (Peter, 8.6)
|
||||
- bugfix: em1010 and %oldvalue bugs (Peter, 9.6)
|
||||
- bugfix: SCIVT solar controller (peterp, 1.7)
|
||||
- bugfix: WS300 loglevel change (from 2 to 5 or device specific loglevel)
|
||||
- feature: First steps for a Fritz!Box port. See the fritzbox.html
|
||||
|
||||
- 2007-12-02 (4.2)
|
||||
- feature: added archivedir/archivecmd to the the main logfile
|
||||
- feature: 99_Sunrise_EL.pm (does not need any Date modules)
|
||||
- bugfix: seldom xmllist error resulting in corrupt xml (Martin/Peter, 4.9)
|
||||
- bugfix: FHT mode holiday_short added (9.9, Dirk)
|
||||
- bugfix: Modifying a device from its own trigger crashes (Klaus, 10.9)
|
||||
- feature: webpgm2 output reformatted
|
||||
- feature: webpgm2 displaying multiple plots
|
||||
- feature: FHT lime-protection code discovered by Dirk (7.10)
|
||||
- feature: softwarebuffer for FHT devices (Dirk 17.10)
|
||||
- feature: FHT low temperatur warning and offset (Dirk 17.10)
|
||||
- change: change FHT state into warnings (Dirk 17.10)
|
||||
NOTE: you'll get an undefined type state &
|
||||
undefined type unknown_85 after upgrade.
|
||||
- feature: Softwarebuffer code simplified (Rudi 22.11)
|
||||
- bugfix: bug #12327 doppeltes my
|
||||
- bugfix: set STATE from trigger
|
||||
- bugfix: readings state vs STATE problem (xmllist/trigger)
|
||||
- change: SUNRISE doc changed (99_SUNRISE.pm -> 99_SUNRISE_EL.pm)
|
||||
- feature: support for the M232 ELV device (Boris, 25.11)
|
||||
- feature: alternativ Quad-based numbers for the FS20 (Matthias, 24.11)
|
||||
- feature: dummy type added (contrib/99_dummy.pm)
|
||||
|
||||
- ==DATE== (4.3)
|
||||
- bugfix: KS300 state was wrong after the STATE bugfix
|
||||
- feature: HMS100CO (by Peter)
|
||||
- feature: EMGZ (by Peter)
|
||||
- feature: Generate warning if too many commands were sent in the last hour
|
||||
- doc: linux.html: Introduction (Peter S.)
|
||||
- feature: contrib/82_M232Voltage.pm (by Boris, 24.12)
|
||||
- feature: delattr renamed to deleteattr (Rudi, 29.12)
|
||||
- feature: defattr renamed to setdefaultattr (Rudi, 29.12)
|
||||
- feature: device spec (list/range/regexp) for most commands implemented
|
||||
- feature: %NAME, %EVENT, %TYPE parameters in notify definition
|
||||
- feature: added 93_DbLog.pm, database logging facility (Boris, 30.12.)
|
||||
- feature: webfrontend/pgm2 converted to a FHEM module
|
||||
- bugfix: 99_SUNRISE_EL.pm: may schedule double events
|
||||
- bugfix: 62_EMEM.pl, contrib/em1010.pl: correct readings for energy_kWh
|
||||
and energy_kWh_w (Boris, 06.01.08)
|
||||
- feature: global attr allowfrom, as wished by Holger (8.1.2008)
|
||||
- feature: FHT: multiple commands, softbuffer changes, cmd rename, doc
|
||||
- feature: EM1010PC: automatic reset
|
||||
- feature: contrib/00_LIRC.pm (25.3, by Bernhard)
|
||||
- bugfix : 00_FHZ: additional stty settings for strange Linux versions
|
||||
- bugfix : pgm2 wrong temp summary for FHT's (reported by O.D., 16.4.2008)
|
||||
- feature: FHEM modules may live on a filesystem with "ignorant" casing (FAT)
|
||||
- feature: FileLog "set reopen" for manual tweaking of logfiles.
|
||||
- feature: multiline commands are supported through the command line
|
||||
- feature: pgm2 installation changes, multiple instances, external css
|
||||
- feature: 87_ws2000.pm (thomas 10.05.08)
|
||||
- contrib: ws2000_reader.pl Standalone decoder and server (thomas 10.05.08)
|
||||
- doc: update fhem.html and commandline.html reflecting ws2000 and
|
||||
windows installation(thomas 10.05.08)
|
||||
- feature: add ReadyFn to fhem.pl in main loop to have an alternative for
|
||||
select, which is not working on windows (thomas 11.05)
|
||||
- feature: set timeout to 0.2s, if HandleTimeout returns undef=forever
|
||||
- bugfix : WS2000:fixed serial port access on windows by replacing FD with
|
||||
ReadyFn
|
||||
- bugfix : FileLog: dont use FH->sync on windows (not implemented there)
|
||||
- feature: EM, WS300, FHZ:Add Switch for Device::SerialPort and
|
||||
Win32::SerialPort to get it running in Windows (sorry, untested)
|
||||
- bugfix: FileLog undefined $data in FileLog_Get
|
||||
- feature: fhem.pl check modules for compiletime errors and do not initialize
|
||||
them
|
||||
- feature: M232 add windows support (thomas 12.05.08)
|
||||
- feature: add simple ELV IPWE1 support (thomas 12.05.08)
|
||||
- feature: FileLog get to read logfiles. Used heavily by webpgm2
|
||||
- feature: webpgm2: gnuplot-scroll mode to navigate/zoom in logfiles
|
||||
- bugfix: deleting FS20 device won't result in unknown device (Daniel, 11.7)
|
||||
- feature: webpgm2 generates SVG's from logs: no need for gnuplot
|
||||
- bugfix: examples corrected to work with current syntax
|
|
@ -1,665 +0,0 @@
|
|||
##############################################
|
||||
package main;
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
use Time::HiRes qw(gettimeofday);
|
||||
|
||||
|
||||
sub FHZ_Write($$$);
|
||||
sub FHZ_Read($);
|
||||
sub FHZ_ReadAnswer($$);
|
||||
sub FhzCrc(@);
|
||||
sub CheckFhzCrc($);
|
||||
sub XmitLimitCheck($$);
|
||||
|
||||
my $msgstart = pack('H*', "81");# Every msg starts wit this
|
||||
|
||||
my %gets = (
|
||||
"init1" => "c9 02011f64",
|
||||
"init2" => "c9 02011f60",
|
||||
"init3" => "c9 02011f0a",
|
||||
"serial" => "04 c90184570208",
|
||||
"fhtbuf" => "04 c90185",
|
||||
);
|
||||
my %sets = (
|
||||
"time" => "c9 020161",
|
||||
"initHMS" => "04 c90186",
|
||||
"initFS20" => "04 c90196",
|
||||
"FHTcode" => "04 c901839e0101",
|
||||
|
||||
"activefor"=> "xx xx",
|
||||
"raw" => "xx xx",
|
||||
);
|
||||
my %setnrparam = (
|
||||
"time" => 0,
|
||||
"initHMS" => 0,
|
||||
"initFS20" => 0,
|
||||
"FHTcode" => 1,
|
||||
"activefor"=> 1,
|
||||
"raw" => 2,
|
||||
);
|
||||
|
||||
my %codes = (
|
||||
"^8501..\$" => "fhtbuf",
|
||||
);
|
||||
|
||||
my $def;
|
||||
my %msghist; # Used when more than one FHZ is attached
|
||||
my $msgcount = 0;
|
||||
my $xmit_limit = 163; # Maximum nr of transmissions per hour (unconfirmed).
|
||||
|
||||
#####################################
|
||||
# Note: we are a data provider _and_ a consumer at the same time
|
||||
sub
|
||||
FHZ_Initialize($)
|
||||
{
|
||||
my ($hash) = @_;
|
||||
|
||||
|
||||
# Provider
|
||||
$hash->{ReadFn} = "FHZ_Read";
|
||||
$hash->{WriteFn} = "FHZ_Write";
|
||||
$hash->{Clients} = ":FHZ:FS20:FHT:HMS:KS300:";
|
||||
|
||||
# Consumer
|
||||
$hash->{Match} = "^81..C9..0102";
|
||||
$hash->{DefFn} = "FHZ_Define";
|
||||
$hash->{UndefFn} = "FHZ_Undef";
|
||||
$hash->{GetFn} = "FHZ_Get";
|
||||
$hash->{SetFn} = "FHZ_Set";
|
||||
$hash->{StateFn} = "FHZ_SetState";
|
||||
$hash->{ParseFn} = "FHZ_Parse";
|
||||
$hash->{ReadyFn} = "FHZ_Ready" if ($^O eq 'MSWin32');
|
||||
$hash->{AttrList}= "do_not_notify:1,0 dummy:1,0 filtertimeout repeater:1,0 " .
|
||||
"showtime:1,0 model:fhz1000,fhz1300 loglevel:0,1,2,3,4,5,6 ".
|
||||
"fhtsoftbuffer:1,0";
|
||||
}
|
||||
#####################################
|
||||
sub
|
||||
FHZ_Ready($$)
|
||||
{
|
||||
my ($hash, $dev) = @_;
|
||||
my $po=$hash->{PortObj};
|
||||
return undef if !$po;
|
||||
my ($BlockingFlags, $InBytes, $OutBytes, $ErrorFlags)=$po->status;
|
||||
return ($InBytes>0);
|
||||
}
|
||||
#####################################
|
||||
sub
|
||||
FHZ_Set($@)
|
||||
{
|
||||
my ($hash, @a) = @_;
|
||||
|
||||
return "Need one to three parameter" if(@a < 2);
|
||||
return "Unknown argument $a[1], choose one of " . join(" ", sort keys %sets)
|
||||
if(!defined($sets{$a[1]}));
|
||||
return "Need one to three parameter" if(@a > 4);
|
||||
return "Wrong number of parameters for $a[1], need " . ($setnrparam{$a[1]}+2)
|
||||
if(@a != ($setnrparam{$a[1]} + 2));
|
||||
|
||||
my ($fn, $arg) = split(" ", $sets{$a[1]});
|
||||
|
||||
my $v = join(" ", @a);
|
||||
my $name = $hash->{NAME};
|
||||
Log GetLogLevel($name,2), "FHZ set $v";
|
||||
|
||||
if($a[1] eq "activefor") {
|
||||
|
||||
my $dhash = $defs{$a[2]};
|
||||
return "device $a[2] unknown" if(!defined($dhash));
|
||||
|
||||
return "Cannot handle $dhash->{TYPE} devices"
|
||||
if($modules{FHZ}->{Clients} !~ m/:$dhash->{TYPE}:/);
|
||||
|
||||
$dhash->{IODev} = $hash;
|
||||
return undef;
|
||||
|
||||
} elsif($a[1] eq "raw") {
|
||||
|
||||
$fn = $a[2];
|
||||
$arg = $a[3];
|
||||
|
||||
} elsif($a[1] eq "time") {
|
||||
|
||||
my @t = localtime;
|
||||
$arg .= sprintf("%02x%02x%02x%02x%02x",
|
||||
$t[5]%100, $t[4]+1, $t[3], $t[2], $t[1]);
|
||||
|
||||
} elsif($a[1] eq "FHTcode") {
|
||||
|
||||
return "invalid argument, must be hex" if(!$a[2] ||
|
||||
$a[2] !~ m/^[A-F0-9]{2}$/);
|
||||
$arg .= $a[2];
|
||||
|
||||
}
|
||||
|
||||
FHZ_Write($hash, $fn, $arg) if(!IsDummy("FHZ"));
|
||||
return undef;
|
||||
}
|
||||
|
||||
#####################################
|
||||
sub
|
||||
FHZ_Get($@)
|
||||
{
|
||||
my ($hash, @a) = @_;
|
||||
|
||||
return "\"get FHZ\" needs only one parameter" if(@a != 2);
|
||||
return "Unknown argument $a[1], choose one of " . join(",", sort keys %gets)
|
||||
if(!defined($gets{$a[1]}));
|
||||
|
||||
my ($fn, $arg) = split(" ", $gets{$a[1]});
|
||||
|
||||
my $v = join(" ", @a);
|
||||
my $name = $hash->{NAME};
|
||||
Log GetLogLevel($name,2), "FHZ get $v";
|
||||
|
||||
FHZ_Write($hash, $fn, $arg) if(!IsDummy("FHZ"));
|
||||
|
||||
my $msg = FHZ_ReadAnswer($hash, $a[1]);
|
||||
return $msg if(!$msg || $msg !~ /^81..c9..0102/);
|
||||
|
||||
if($a[1] eq "serial") {
|
||||
$v = substr($msg, 22, 8)
|
||||
|
||||
} elsif($a[1] eq "fhtbuf") {
|
||||
$v = substr($msg, 16, 2);
|
||||
|
||||
} else {
|
||||
$v = substr($msg, 12);
|
||||
}
|
||||
$hash->{READINGS}{$a[1]}{VAL} = $v;
|
||||
$hash->{READINGS}{$a[1]}{TIME} = TimeNow();
|
||||
|
||||
return "$a[0] $a[1] => $v";
|
||||
}
|
||||
|
||||
#####################################
|
||||
sub
|
||||
FHZ_SetState($$$$)
|
||||
{
|
||||
my ($hash, $tim, $vt, $val) = @_;
|
||||
|
||||
return "Undefined value $vt" if(!defined($gets{$vt}));
|
||||
return undef;
|
||||
}
|
||||
|
||||
|
||||
#####################################
|
||||
sub
|
||||
DoInit($)
|
||||
{
|
||||
my $name = shift;
|
||||
my @init;
|
||||
push(@init, "get $name init2");
|
||||
push(@init, "get $name serial");
|
||||
push(@init, "set $name initHMS");
|
||||
push(@init, "set $name initFS20");
|
||||
push(@init, "set $name time");
|
||||
|
||||
# Workaround: Sending "set 0001 00 off" after initialization to enable
|
||||
# the fhz1000 receiver, else we won't get anything reported.
|
||||
push(@init, "set $name raw 04 01010100010000");
|
||||
|
||||
CommandChain(3, \@init);
|
||||
|
||||
# Reset the counter
|
||||
my $hash = $defs{$name};
|
||||
delete($hash->{XMIT_TIME});
|
||||
delete($hash->{NR_CMD_LAST_H});
|
||||
}
|
||||
|
||||
#####################################
|
||||
sub
|
||||
FHZ_Define($$)
|
||||
{
|
||||
my ($hash, $def) = @_;
|
||||
my @a = split("[ \t][ \t]*", $def);
|
||||
my $po;
|
||||
$hash->{STATE} = "Initialized";
|
||||
|
||||
delete $hash->{PortObj};
|
||||
delete $hash->{FD};
|
||||
|
||||
my $name = $a[0];
|
||||
my $dev = $a[2];
|
||||
|
||||
$attr{$name}{savefirst} = 1;
|
||||
$attr{$name}{fhtsoftbuffer} = 0;
|
||||
|
||||
if($dev eq "none") {
|
||||
Log 1, "FHZ device is none, commands will be echoed only";
|
||||
$attr{$name}{dummy} = 1;
|
||||
return undef;
|
||||
}
|
||||
|
||||
Log 3, "FHZ opening FHZ device $dev";
|
||||
if ($^O=~/Win/) {
|
||||
require Win32::SerialPort;
|
||||
$po = new Win32::SerialPort ($dev);
|
||||
} else {
|
||||
require Device::SerialPort;
|
||||
$po = new Device::SerialPort ($dev);
|
||||
}
|
||||
return "Can't open $dev: $!\n" if(!$po);
|
||||
Log 3, "FHZ opened FHZ device $dev";
|
||||
|
||||
$po->reset_error();
|
||||
$po->baudrate(9600);
|
||||
$po->databits(8);
|
||||
$po->parity('none');
|
||||
$po->stopbits(1);
|
||||
$po->handshake('none');
|
||||
|
||||
# This part is for some Linux kernel versions whih has strange default
|
||||
# settings. Device::SerialPort is nice: if the flag is not defined for your
|
||||
# OS then it will be ignored.
|
||||
$po->stty_icanon(0);
|
||||
#$po->stty_parmrk(0); # The debian standard install does not have it
|
||||
$po->stty_icrnl(0);
|
||||
$po->stty_echoe(0);
|
||||
$po->stty_echok(0);
|
||||
$po->stty_echoctl(0);
|
||||
|
||||
# Needed for some strange distros
|
||||
$po->stty_echo(0);
|
||||
$po->stty_icanon(0);
|
||||
$po->stty_isig(0);
|
||||
$po->stty_opost(0);
|
||||
$po->stty_icrnl(0);
|
||||
$po->write_settings;
|
||||
|
||||
|
||||
$hash->{PortObj} = $po;
|
||||
$hash->{FD} = $po->FILENO if !( $^O =~ /Win/ );
|
||||
|
||||
|
||||
$hash->{DeviceName} = $dev;
|
||||
$hash->{PARTIAL} = "";
|
||||
|
||||
DoInit($name);
|
||||
|
||||
return undef;
|
||||
}
|
||||
|
||||
#####################################
|
||||
sub
|
||||
FHZ_Undef($$)
|
||||
{
|
||||
my ($hash, $arg) = @_;
|
||||
my $name = $hash->{NAME};
|
||||
|
||||
foreach my $d (sort keys %defs) {
|
||||
if(defined($defs{$d}) &&
|
||||
defined($defs{$d}{IODev}) &&
|
||||
$defs{$d}{IODev} == $hash)
|
||||
{
|
||||
Log GetLogLevel($name,2), "deleting port for $d";
|
||||
delete $defs{$d}{IODev};
|
||||
}
|
||||
}
|
||||
$hash->{PortObj}->close() if($hash->{PortObj});
|
||||
return undef;
|
||||
}
|
||||
|
||||
#####################################
|
||||
sub
|
||||
FHZ_Parse($$)
|
||||
{
|
||||
my ($hash,$msg) = @_;
|
||||
|
||||
my $omsg = $msg;
|
||||
$msg = substr($msg, 12); # The first 12 bytes are not really interesting
|
||||
|
||||
my $type = "";
|
||||
my $name = $hash->{NAME};
|
||||
foreach my $c (keys %codes) {
|
||||
if($msg =~ m/$c/) {
|
||||
$type = $codes{$c};
|
||||
last;
|
||||
}
|
||||
}
|
||||
|
||||
if(!$type) {
|
||||
Log 4, "FHZ $name unknown: $omsg";
|
||||
$def->{CHANGED}[0] = "$msg";
|
||||
return $hash->{NAME};
|
||||
}
|
||||
|
||||
|
||||
if($type eq "fhtbuf") {
|
||||
$msg = substr($msg, 4, 2);
|
||||
}
|
||||
|
||||
Log 4, "FHZ $name $type: $msg";
|
||||
$def->{CHANGED}[0] = "$type: $msg";
|
||||
return $hash->{NAME};
|
||||
}
|
||||
|
||||
#####################################
|
||||
sub
|
||||
FhzCrc(@)
|
||||
{
|
||||
my $sum = 0;
|
||||
map { $sum += $_; } @_;
|
||||
return $sum & 0xFF;
|
||||
}
|
||||
|
||||
#####################################
|
||||
sub
|
||||
CheckFhzCrc($)
|
||||
{
|
||||
my $msg = shift;
|
||||
return 0 if(length($msg) < 8);
|
||||
|
||||
my @data;
|
||||
for(my $i = 8; $i < length($msg); $i += 2) {
|
||||
push(@data, ord(pack('H*', substr($msg, $i, 2))));
|
||||
}
|
||||
my $crc = hex(substr($msg, 6, 2));
|
||||
|
||||
# FS20 Repeater generate a CRC which is one or two greater then the computed
|
||||
# one. The FHZ1000 filters such pakets, so we do not see them
|
||||
return (($crc eq FhzCrc(@data)) ? 1 : 0);
|
||||
}
|
||||
|
||||
|
||||
#####################################
|
||||
# This is a direct read for commands like get
|
||||
sub
|
||||
FHZ_ReadAnswer($$)
|
||||
{
|
||||
my ($hash,$arg) = @_;
|
||||
|
||||
return undef if(!$hash || !defined($hash->{FD}));
|
||||
|
||||
my ($mfhzdata, $rin) = ("", '');
|
||||
my $nfound;
|
||||
for(;;) {
|
||||
if($^O eq 'MSWin32') {
|
||||
$nfound=FHZ_Ready($hash,$def);
|
||||
} else {
|
||||
vec($rin, $hash->{FD}, 1) = 1;
|
||||
$nfound = select($rin, undef, undef, 3); # 3 seconds timeout
|
||||
if($nfound < 0) {
|
||||
next if ($! == EAGAIN() || $! == EINTR() || $! == 0);
|
||||
die("Select error $nfound / $!\n");
|
||||
}
|
||||
}
|
||||
return "Timeout reading answer for get $arg" if($nfound == 0);
|
||||
|
||||
my $buf = $hash->{PortObj}->input();
|
||||
|
||||
Log 5, "FHZ/RAW: " . unpack('H*',$buf);
|
||||
$mfhzdata .= $buf;
|
||||
next if(length($mfhzdata) < 2);
|
||||
|
||||
my $len = ord(substr($mfhzdata,1,1)) + 2;
|
||||
if($len>20) {
|
||||
Log 4, "Oversized message (" . unpack('H*',$mfhzdata) .
|
||||
"), dropping it ...";
|
||||
return undef;
|
||||
}
|
||||
return unpack('H*', $mfhzdata) if(length($mfhzdata) == $len);
|
||||
}
|
||||
}
|
||||
|
||||
##############
|
||||
sub
|
||||
FHZ_CompleteMsg($$)
|
||||
{
|
||||
my ($fn,$msg) = @_;
|
||||
my $len = length($msg);
|
||||
my @data;
|
||||
for(my $i = 0; $i < $len; $i += 2) {
|
||||
push(@data, ord(pack('H*', substr($msg, $i, 2))));
|
||||
}
|
||||
return pack('C*', 0x81, $len/2+2, ord(pack('H*',$fn)), FhzCrc(@data), @data);
|
||||
}
|
||||
|
||||
|
||||
#####################################
|
||||
# Check if the 1% limit is reached and trigger notifies
|
||||
sub
|
||||
XmitLimitCheck($$)
|
||||
{
|
||||
my ($hash,$bstring) = @_;
|
||||
my $now = time();
|
||||
|
||||
$bstring = unpack('H*', $bstring);
|
||||
return if($bstring =~ m/c90185$/); # fhtbuf
|
||||
|
||||
if(!$hash->{XMIT_TIME}) {
|
||||
$hash->{XMIT_TIME}[0] = $now;
|
||||
$hash->{NR_CMD_LAST_H} = 1;
|
||||
return;
|
||||
}
|
||||
|
||||
my $nowM1h = $now-3600;
|
||||
my @b = grep { $_ > $nowM1h } @{$hash->{XMIT_TIME}};
|
||||
|
||||
if(@b > $xmit_limit) {
|
||||
|
||||
my $me = $hash->{NAME};
|
||||
Log GetLogLevel($me,2), "FHZ TRANSMIT LIMIT EXCEEDED";
|
||||
DoTrigger($me, "TRANSMIT LIMIT EXCEEDED");
|
||||
|
||||
} else {
|
||||
|
||||
push(@b, $now);
|
||||
|
||||
}
|
||||
$hash->{XMIT_TIME} = \@b;
|
||||
$hash->{NR_CMD_LAST_H} = int(@b);
|
||||
}
|
||||
|
||||
#####################################
|
||||
sub
|
||||
FHZ_Write($$$)
|
||||
{
|
||||
my ($hash,$fn,$msg) = @_;
|
||||
|
||||
if(!$hash || !defined($hash->{PortObj})) {
|
||||
Log 5, "FHZ device $hash->{NAME} is not active, cannot send";
|
||||
return;
|
||||
}
|
||||
|
||||
###############
|
||||
# insert value into the msghist. At the moment this only makes sense for FS20
|
||||
# devices. As the transmitted value differs from the received one, we have to
|
||||
# recompute.
|
||||
if($fn eq "04" && substr($msg,0,6) eq "010101") {
|
||||
my $nmsg = "0101a001" . substr($msg, 6, 6) . "00" . substr($msg, 12);
|
||||
$msghist{$msgcount}{TIME} = gettimeofday();
|
||||
$msghist{$msgcount}{NAME} = $hash->{NAME};
|
||||
$msghist{$msgcount}{MSG} = unpack('H*', FHZ_CompleteMsg($fn, $nmsg));
|
||||
$msgcount++;
|
||||
}
|
||||
|
||||
my $bstring = FHZ_CompleteMsg($fn, $msg);
|
||||
Log 5, "Sending " . unpack('H*', $bstring);
|
||||
|
||||
if(!$hash->{QUEUECNT}) {
|
||||
|
||||
XmitLimitCheck($hash,$bstring);
|
||||
$hash->{PortObj}->write($bstring);
|
||||
|
||||
##############
|
||||
# Write the next buffer not earlier than 0.22 seconds (= 65.6ms + 10ms +
|
||||
# 65.6ms + 10ms + 65.6ms), else it will be discarded by the FHZ1X00 PC
|
||||
InternalTimer(gettimeofday()+0.25, "FHZ_HandleWriteQueue", $hash, 1);
|
||||
|
||||
} elsif($hash->{QUEUECNT} == 1) {
|
||||
$hash->{QUEUE} = [ $bstring ];
|
||||
} else {
|
||||
push(@{$hash->{QUEUE}}, $bstring);
|
||||
}
|
||||
$hash->{QUEUECNT}++;
|
||||
|
||||
|
||||
}
|
||||
|
||||
#####################################
|
||||
sub
|
||||
FHZ_HandleWriteQueue($)
|
||||
{
|
||||
my $hash = shift;
|
||||
my $cnt = --$hash->{QUEUECNT};
|
||||
if($cnt > 0) {
|
||||
my $bstring = shift(@{$hash->{QUEUE}});
|
||||
XmitLimitCheck($hash,$bstring);
|
||||
$hash->{PortObj}->write($bstring);
|
||||
InternalTimer(gettimeofday()+0.25, "FHZ_HandleWriteQueue", $hash, 1);
|
||||
}
|
||||
}
|
||||
|
||||
#####################################
|
||||
sub
|
||||
FHZ_Read($)
|
||||
{
|
||||
my ($hash) = @_;
|
||||
|
||||
my $buf = $hash->{PortObj}->input();
|
||||
my $iohash = $modules{$hash->{TYPE}};
|
||||
my $name = $hash->{NAME};
|
||||
|
||||
###########
|
||||
# Lets' try again: Some drivers return len(0) on the first read...
|
||||
if(defined($buf) && length($buf) == 0) {
|
||||
$buf = $hash->{PortObj}->input();
|
||||
}
|
||||
|
||||
if(!defined($buf) || length($buf) == 0) {
|
||||
|
||||
my $devname = $hash->{DeviceName};
|
||||
Log 1, "USB device $devname disconnected, waiting to reappear";
|
||||
$hash->{PortObj}->close();
|
||||
for(;;) {
|
||||
sleep(5);
|
||||
if ($^O eq 'MSWin32') {
|
||||
$hash->{PortObj} = new Win32::SerialPort($devname);
|
||||
}else{
|
||||
$hash->{PortObj} = new Device::SerialPort($devname);
|
||||
}
|
||||
|
||||
if($hash->{PortObj}) {
|
||||
Log 1, "USB device $devname reappeared";
|
||||
$hash->{FD} = $hash->{PortObj}->FILENO if !($^O eq 'MSWin32');
|
||||
DoInit($name);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
my $fhzdata = $hash->{PARTIAL};
|
||||
Log 5, "FHZ/RAW: " . unpack('H*',$buf) .
|
||||
" (Unparsed: " . unpack('H*', $fhzdata) . ")";
|
||||
$fhzdata .= $buf;
|
||||
|
||||
while(length($fhzdata) > 2) {
|
||||
|
||||
###################################
|
||||
# Skip trash.
|
||||
my $si = index($fhzdata, $msgstart);
|
||||
if($si) {
|
||||
if($si == -1) {
|
||||
Log(5, "Bogus message received, no start character found");
|
||||
$fhzdata = "";
|
||||
last;
|
||||
} else {
|
||||
Log(5, "Bogus message received, skipping to start character");
|
||||
$fhzdata = substr($fhzdata, $si);
|
||||
}
|
||||
}
|
||||
|
||||
my $len = ord(substr($fhzdata,1,1)) + 2;
|
||||
if($len>20) {
|
||||
Log 4,
|
||||
"Oversized message (" . unpack('H*',$fhzdata) . "), dropping it ...";
|
||||
$fhzdata = "";
|
||||
next;
|
||||
}
|
||||
|
||||
last if(length($fhzdata) < $len);
|
||||
|
||||
my $dmsg = unpack('H*', substr($fhzdata, 0, $len));
|
||||
if(CheckFhzCrc($dmsg)) {
|
||||
|
||||
if(substr($fhzdata,2,1) eq $msgstart) { # Skip function 0x81
|
||||
$fhzdata = substr($fhzdata, 2);
|
||||
next;
|
||||
}
|
||||
|
||||
###############
|
||||
# check for duplicate msg from different FHZ's
|
||||
my $now = gettimeofday();
|
||||
my $skip;
|
||||
my $meetoo = ($attr{$name}{repeater} ? 1 : 0);
|
||||
|
||||
my $to = 3;
|
||||
if(defined($attr{$name}) && defined($attr{$name}{filtertimeout})) {
|
||||
$to = $attr{$name}{filtertimeout};
|
||||
}
|
||||
foreach my $oidx (keys %msghist) {
|
||||
if($now-$msghist{$oidx}{TIME} > $to) {
|
||||
delete($msghist{$oidx});
|
||||
next;
|
||||
}
|
||||
if($msghist{$oidx}{MSG} eq $dmsg &&
|
||||
($meetoo || $msghist{$oidx}{NAME} ne $name)) {
|
||||
Log 5, "Skipping $msghist{$oidx}{MSG}";
|
||||
$skip = 1;
|
||||
}
|
||||
}
|
||||
goto NEXTMSG if($skip);
|
||||
$msghist{$msgcount}{TIME} = $now;
|
||||
$msghist{$msgcount}{NAME} = $name;
|
||||
$msghist{$msgcount}{MSG} = $dmsg;
|
||||
$msgcount++;
|
||||
|
||||
|
||||
my @found;
|
||||
my $last_module;
|
||||
foreach my $m (sort { $modules{$a}{ORDER} cmp $modules{$b}{ORDER} }
|
||||
grep {defined($modules{$_}{ORDER});}keys %modules) {
|
||||
next if($iohash->{Clients} !~ m/:$m:/);
|
||||
next if($dmsg !~ m/$modules{$m}{Match}/i);
|
||||
no strict "refs";
|
||||
@found = &{$modules{$m}{ParseFn}}($hash,$dmsg);
|
||||
use strict "refs";
|
||||
$last_module = $m;
|
||||
last if(int(@found));
|
||||
}
|
||||
if(!int(@found)) {
|
||||
Log 1, "Unknown code $dmsg, help me!";
|
||||
goto NEXTMSG;
|
||||
}
|
||||
|
||||
goto NEXTMSG if($found[0] eq ""); # Special return: Do not notify
|
||||
|
||||
if($found[0] =~ m/^(UNDEFINED) ([^ ]*) (.*)$/) {
|
||||
my $d = $1;
|
||||
$defs{$d}{NAME} = $1;
|
||||
$defs{$d}{TYPE} = $last_module;
|
||||
DoTrigger($d, "$2 $3");
|
||||
delete $defs{$d};
|
||||
goto NEXTMSG;
|
||||
}
|
||||
|
||||
foreach my $found (@found) {
|
||||
DoTrigger($found, undef);
|
||||
}
|
||||
NEXTMSG:
|
||||
$fhzdata = substr($fhzdata, $len);
|
||||
|
||||
} else {
|
||||
|
||||
Log 4, "Bad CRC message, skipping it (Bogus message follows)";
|
||||
$fhzdata = substr($fhzdata, 2);
|
||||
|
||||
}
|
||||
}
|
||||
$hash->{PARTIAL} = $fhzdata;
|
||||
}
|
||||
|
||||
1;
|
|
@ -1,96 +0,0 @@
|
|||
##############################################
|
||||
package main;
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
use Time::HiRes qw(gettimeofday);
|
||||
use Lirc::Client;
|
||||
use IO::Select;
|
||||
|
||||
my $def;
|
||||
|
||||
#####################################
|
||||
# Note: we are a data provider _and_ a consumer at the same time
|
||||
sub
|
||||
LIRC_Initialize($)
|
||||
{
|
||||
my ($hash) = @_;
|
||||
Log 1, "LIRC_Initialize";
|
||||
|
||||
# Provider
|
||||
$hash->{ReadFn} = "LIRC_Read";
|
||||
$hash->{Clients} = ":LIRC:";
|
||||
|
||||
# Consumer
|
||||
$hash->{DefFn} = "LIRC_Define";
|
||||
$hash->{UndefFn} = "LIRC_Undef";
|
||||
}
|
||||
|
||||
#####################################
|
||||
sub
|
||||
LIRC_Define($$)
|
||||
{
|
||||
my ($hash, $def) = @_;
|
||||
my @a = split("[ \t][ \t]*", $def);
|
||||
|
||||
$hash->{STATE} = "Initialized";
|
||||
|
||||
delete $hash->{LircObj};
|
||||
delete $hash->{FD};
|
||||
|
||||
my $name = $a[0];
|
||||
my $config = $a[2];
|
||||
|
||||
Log 3, "LIRC opening LIRC device $config";
|
||||
my $lirc = Lirc::Client->new({
|
||||
prog => 'fhem',
|
||||
rcfile => "$config",
|
||||
debug => 0,
|
||||
fake => 0,
|
||||
});
|
||||
return "Can't open $config: $!\n" if(!$lirc);
|
||||
Log 3, "LIRC opened $name device $config";
|
||||
|
||||
my $select = IO::Select->new();
|
||||
$select->add( $lirc->sock );
|
||||
|
||||
$hash->{LircObj} = $lirc;
|
||||
$hash->{FD} = $lirc->sock;
|
||||
$hash->{SelectObj} = $select;
|
||||
$hash->{DeviceName} = $name;
|
||||
$hash->{STATE} = "Opened";
|
||||
|
||||
return undef;
|
||||
}
|
||||
|
||||
#####################################
|
||||
sub
|
||||
LIRC_Undef($$)
|
||||
{
|
||||
my ($hash, $arg) = @_;
|
||||
|
||||
$hash->{LircObj}->close() if($hash->{LircObj});
|
||||
return undef;
|
||||
}
|
||||
|
||||
#####################################
|
||||
sub
|
||||
LIRC_Read($)
|
||||
{
|
||||
my ($hash) = @_;
|
||||
|
||||
my $lirc= $hash->{LircObj};
|
||||
my $select= $hash->{SelectObj};
|
||||
|
||||
if( my @ready = $select->can_read(0) ){
|
||||
# an ir event has been received (if you are tracking other filehandles, you need to make sure it is lirc)
|
||||
my @codes = $lirc->next_codes; # should not block
|
||||
for my $code (@codes){
|
||||
Log 3, "LIRC code: $code\n";
|
||||
DoTrigger($code, "toggle");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
1;
|
|
@ -1,398 +0,0 @@
|
|||
##############################################
|
||||
package main;
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
|
||||
my %codes = (
|
||||
"00" => "off",
|
||||
"01" => "dim06%",
|
||||
"02" => "dim12%",
|
||||
"03" => "dim18%",
|
||||
"04" => "dim25%",
|
||||
"05" => "dim31%",
|
||||
"06" => "dim37%",
|
||||
"07" => "dim43%",
|
||||
"08" => "dim50%",
|
||||
"09" => "dim56%",
|
||||
"0a" => "dim62%",
|
||||
"0b" => "dim68%",
|
||||
"0c" => "dim75%",
|
||||
"0d" => "dim81%",
|
||||
"0e" => "dim87%",
|
||||
"0f" => "dim93%",
|
||||
"10" => "dim100%",
|
||||
"11" => "on", # Set to previous dim value (before switching it off)
|
||||
"12" => "toggle", # between off and previous dim val
|
||||
"13" => "dimup",
|
||||
"14" => "dimdown",
|
||||
"15" => "dimupdown",
|
||||
"16" => "timer",
|
||||
"17" => "sendstate",
|
||||
"18" => "off-for-timer",
|
||||
"19" => "on-for-timer",
|
||||
"1a" => "on-old-for-timer",
|
||||
"1b" => "reset",
|
||||
"1c" => "ramp-on-time", #time to reach the desired dim value on dimmers
|
||||
"1d" => "ramp-off-time", #time to reach the off state on dimmers
|
||||
);
|
||||
|
||||
my %readonly = (
|
||||
"thermo-on" => 1,
|
||||
"thermo-off" => 1,
|
||||
);
|
||||
|
||||
use vars qw(%fs20_c2b); # Peter would like to access it from outside
|
||||
|
||||
# defptr{XMIT BTN}{DEVNAME} -> Ptr to global defs entry for this device
|
||||
my %defptr;
|
||||
|
||||
my %follow;
|
||||
my $fs20_simple ="off off-for-timer on on-for-timer on-till reset timer toggle";
|
||||
my %models = (
|
||||
fs20hgs => 'sender',
|
||||
fs20pira => 'sender',
|
||||
fs20piri => 'sender',
|
||||
fs20s20 => 'sender',
|
||||
fs20s4 => 'sender',
|
||||
fs20s4a => 'sender',
|
||||
fs20s4m => 'sender',
|
||||
fs20s4u => 'sender',
|
||||
fs20s4ub => 'sender',
|
||||
fs20sd => 'sender',
|
||||
fs20sn => 'sender',
|
||||
fs20sr => 'sender',
|
||||
fs20ss => 'sender',
|
||||
fs20str => 'sender',
|
||||
fs20tfk => 'sender',
|
||||
fs20tk => 'sender',
|
||||
fs20uts => 'sender',
|
||||
fs20ze => 'sender',
|
||||
|
||||
fs20ms2 => 'simple',
|
||||
fs20as1 => 'simple',
|
||||
fs20as4 => 'simple',
|
||||
fs20di => 'dimmer',
|
||||
fs20du => 'dimmer',
|
||||
fs20rst => 'simple',
|
||||
fs20sa => 'simple',
|
||||
fs20sig => 'simple',
|
||||
fs20st => 'simple',
|
||||
fs20sv => 'simple',
|
||||
fs20sv => 'simple',
|
||||
fs20usr => 'simple',
|
||||
);
|
||||
|
||||
|
||||
sub
|
||||
FS20_Initialize($)
|
||||
{
|
||||
my ($hash) = @_;
|
||||
|
||||
foreach my $k (keys %codes) {
|
||||
$fs20_c2b{$codes{$k}} = $k;
|
||||
}
|
||||
$fs20_c2b{"on-till"} = 99;
|
||||
|
||||
$hash->{Match} = "^81..(04|0c)..0101a001";
|
||||
$hash->{SetFn} = "FS20_Set";
|
||||
$hash->{StateFn} = "FS20_SetState";
|
||||
$hash->{DefFn} = "FS20_Define";
|
||||
$hash->{UndefFn} = "FS20_Undef";
|
||||
$hash->{ParseFn} = "FS20_Parse";
|
||||
$hash->{AttrList} = "follow-on-for-timer:1,0 do_not_notify:1,0 dummy:1,0 showtime:1,0 model;fs20hgs,fs20hgs,fs20pira,fs20piri,fs20s20,fs20s8,fs20s4,fs20s4a,fs20s4m,fs20s4u,fs20s4ub,fs20sd,fs20sn,fs20sr,fs20ss,fs20str,fs20tfk,fs20tfk,fs20tk,fs20uts,fs20ze,fs20as1,fs20as4,fs20di,fs20du,fs20ms2,fs20rst,fs20sa,fs20sig,fs20st,fs20sv,fs20usr loglevel:0,1,2,3,4,5,6";
|
||||
|
||||
}
|
||||
|
||||
#####################################
|
||||
sub
|
||||
FS20_SetState($$$$)
|
||||
{
|
||||
my ($hash, $tim, $vt, $val) = @_;
|
||||
|
||||
$val = $1 if($val =~ m/^(.*) \d+$/);
|
||||
return "Undefined value $val" if(!defined($fs20_c2b{$val}));
|
||||
return undef;
|
||||
}
|
||||
|
||||
#############################
|
||||
sub
|
||||
Do_On_Till($@)
|
||||
{
|
||||
my ($hash, @a) = @_;
|
||||
return "Timespec (HH:MM[:SS]) needed for the on-till command" if(@a != 3);
|
||||
|
||||
my ($err, $hr, $min, $sec, $fn) = GetTimeSpec($a[2]);
|
||||
return $err if($err);
|
||||
|
||||
my @lt = localtime;
|
||||
my $hms_till = sprintf("%02d:%02d:%02d", $hr, $min, $sec);
|
||||
my $hms_now = sprintf("%02d:%02d:%02d", $lt[2], $lt[1], $lt[0]);
|
||||
if($hms_now ge $hms_till) {
|
||||
Log 4, "on-till: won't switch as now ($hms_now) is later than $hms_till";
|
||||
return "";
|
||||
}
|
||||
|
||||
my @b = ($a[0], "on");
|
||||
FS20_Set($hash, @b);
|
||||
CommandDefine(undef, $hash->{NAME} . "_till at $hms_till set $a[0] off");
|
||||
|
||||
}
|
||||
|
||||
|
||||
###################################
|
||||
sub
|
||||
FS20_Set($@)
|
||||
{
|
||||
my ($hash, @a) = @_;
|
||||
my $ret = undef;
|
||||
my $na = int(@a);
|
||||
|
||||
return "no set value specified" if($na < 2 || $na > 3);
|
||||
return "Readonly value $a[1]" if(defined($readonly{$a[1]}));
|
||||
|
||||
my $c = $fs20_c2b{$a[1]};
|
||||
if(!defined($c)) {
|
||||
|
||||
# Model specific set arguments
|
||||
if(defined($attr{$a[0]}) && defined($attr{$a[0]}{"model"})) {
|
||||
my $mt = $models{$attr{$a[0]}{"model"}};
|
||||
return "Unknown argument $a[1], choose one of "
|
||||
if($mt && $mt eq "sender");
|
||||
return "Unknown argument $a[1], choose one of $fs20_simple"
|
||||
if($mt && $mt eq "simple");
|
||||
}
|
||||
return "Unknown argument $a[1], choose one of " .
|
||||
join(" ", sort keys %fs20_c2b);
|
||||
|
||||
}
|
||||
|
||||
return Do_On_Till($hash, @a) if($a[1] eq "on-till");
|
||||
|
||||
return "Bad time spec" if($na == 3 && $a[2] !~ m/^\d*\.?\d+$/);
|
||||
|
||||
my $v = join(" ", @a);
|
||||
Log GetLogLevel($a[0],2), "FS20 set $v";
|
||||
(undef, $v) = split(" ", $v, 2); # Not interested in the name...
|
||||
|
||||
my $val;
|
||||
if($na == 2) {
|
||||
|
||||
IOWrite($hash, "04", "010101" . $hash->{XMIT} . $hash->{BTN} . $c)
|
||||
if(!IsDummy($a[0]));
|
||||
|
||||
} else {
|
||||
|
||||
$c =~ s/1/3/; # Set the extension bit
|
||||
|
||||
########################
|
||||
# Calculating the time.
|
||||
LOOP: for(my $i = 0; $i <= 12; $i++) {
|
||||
for(my $j = 0; $j <= 15; $j++) {
|
||||
$val = (2**$i)*$j*0.25;
|
||||
if($val >= $a[2]) {
|
||||
if($val != $a[2]) {
|
||||
$ret = "FS20 Setting timeout to $val from $a[2]";
|
||||
Log GetLogLevel($a[0],2), $ret;
|
||||
}
|
||||
$c .= sprintf("%x%x", $i, $j);
|
||||
last LOOP;
|
||||
}
|
||||
}
|
||||
}
|
||||
return "Specified timeout too large, max is 15360" if(length($c) == 2);
|
||||
|
||||
IOWrite($hash, "04", "010101" . $hash->{XMIT} . $hash->{BTN} . $c)
|
||||
if(!IsDummy($a[0]));
|
||||
|
||||
}
|
||||
|
||||
###########################################
|
||||
# Set the state of a device to off if on-for-timer is called
|
||||
if($follow{$a[0]}) {
|
||||
CommandDelete(undef, "at .*setstate.*$a[0]");
|
||||
delete $follow{$a[0]};
|
||||
}
|
||||
if($a[1] eq "on-for-timer" && $na == 3 &&
|
||||
defined($attr{$a[0]}) && defined($attr{$a[0]}{"follow-on-for-timer"})) {
|
||||
my $to = sprintf("%02d:%02d:%02d", $val/3600, ($val%3600)/60, $val%60);
|
||||
$follow{$a[0]} = $to;
|
||||
Log 4, "Follow: +$to setstate $a[0] off";
|
||||
CommandDefine(undef, $a[0] . "_timer at +$to setstate $a[0] off");
|
||||
}
|
||||
|
||||
##########################
|
||||
# Look for all devices with the same code, and set state, timestamp
|
||||
my $code = "$hash->{XMIT} $hash->{BTN}";
|
||||
my $tn = TimeNow();
|
||||
foreach my $n (keys %{ $defptr{$code} }) {
|
||||
|
||||
my $lh = $defptr{$code}{$n};
|
||||
$lh->{CHANGED}[0] = $v;
|
||||
$lh->{STATE} = $v;
|
||||
$lh->{READINGS}{state}{TIME} = $tn;
|
||||
$lh->{READINGS}{state}{VAL} = $v;
|
||||
}
|
||||
return $ret;
|
||||
}
|
||||
|
||||
#############################
|
||||
sub
|
||||
FS20_Define($$)
|
||||
{
|
||||
my ($hash, $def) = @_;
|
||||
my @a = split("[ \t][ \t]*", $def);
|
||||
|
||||
my $u = "wrong syntax: define <name> FS20 housecode " .
|
||||
"addr [fg addr] [lm addr] [gm FF]";
|
||||
|
||||
return $u if(int(@a) < 4);
|
||||
return "Define $a[0]: wrong housecode format: specify a 4 digit hex value ".
|
||||
"or an 8 digit quad value"
|
||||
if( ($a[2] !~ m/^[a-f0-9]{4}$/i) && ($a[2] !~ m/^[1-4]{8}$/i) );
|
||||
|
||||
return "Define $a[0]: wrong btn format: specify a 2 digit hex value " .
|
||||
"or a 4 digit quad value"
|
||||
if( ($a[3] !~ m/^[a-f0-9]{2}$/i) && ($a[3] !~ m/^[1-4]{4}$/i) );
|
||||
|
||||
my $housecode = $a[2];
|
||||
$housecode = four2hex($housecode,4) if (length($housecode) == 8);
|
||||
|
||||
my $btncode = $a[3];
|
||||
$btncode = four2hex($btncode,2) if (length($btncode) == 4);
|
||||
|
||||
$hash->{XMIT} = lc($housecode);
|
||||
$hash->{BTN} = lc($btncode);
|
||||
|
||||
my $code = "$housecode $btncode";
|
||||
my $ncode = 1;
|
||||
my $name = $a[0];
|
||||
|
||||
$hash->{CODE}{$ncode++} = $code;
|
||||
$defptr{$code}{$name} = $hash;
|
||||
|
||||
for(my $i = 4; $i < int(@a); $i += 2) {
|
||||
|
||||
return "No address specified for $a[$i]" if($i == int(@a)-1);
|
||||
|
||||
$a[$i] = lc($a[$i]);
|
||||
if($a[$i] eq "fg") {
|
||||
return "Bad fg address for $name, see the doc"
|
||||
if( ($a[$i+1] !~ m/^f[a-f0-9]$/) && ($a[$i+1] !~ m/^44[1-4][1-4]$/));
|
||||
} elsif($a[$i] eq "lm") {
|
||||
return "Bad lm address for $name, see the doc"
|
||||
if( ($a[$i+1] !~ m/^[a-f0-9]f$/) && ($a[$i+1] !~ m/^[1-4][1-4]44$/));
|
||||
} elsif($a[$i] eq "gm") {
|
||||
return "Bad gm address for $name, must be ff"
|
||||
if( ($a[$i+1] ne "ff") && ($a[$i+1] ne "4444"));
|
||||
} else {
|
||||
return $u;
|
||||
}
|
||||
|
||||
my $grpcode = $a[$i+1];
|
||||
if (length($grpcode) == 4) {
|
||||
$grpcode = four2hex($grpcode,2);
|
||||
}
|
||||
|
||||
$code = "$housecode $grpcode";
|
||||
$hash->{CODE}{$ncode++} = $code;
|
||||
$defptr{$code}{$name} = $hash;
|
||||
}
|
||||
AssignIoPort($hash);
|
||||
}
|
||||
|
||||
#############################
|
||||
sub
|
||||
FS20_Undef($$)
|
||||
{
|
||||
my ($hash, $name) = @_;
|
||||
foreach my $c (keys %{ $hash->{CODE} } ) {
|
||||
$c = $hash->{CODE}{$c};
|
||||
delete($defptr{$c}{$name}) if($defptr{$c});
|
||||
delete($defptr{$c}{$name}) if(!%{$defptr{$c}});
|
||||
}
|
||||
return undef;
|
||||
}
|
||||
|
||||
sub
|
||||
FS20_Parse($$)
|
||||
{
|
||||
my ($hash, $msg) = @_;
|
||||
|
||||
# Msg format:
|
||||
# 81 0b 04 f7 0101 a001 HHHH 01 00 11
|
||||
|
||||
my $dev = substr($msg, 16, 4);
|
||||
my $btn = substr($msg, 20, 2);
|
||||
my $cde = substr($msg, 24, 2);
|
||||
|
||||
|
||||
my $dur = 0;
|
||||
my $cx = hex($cde);
|
||||
if($cx & 0x20) {
|
||||
$dur = hex(substr($msg, 26, 2));
|
||||
my $i = ($dur & 0xf0) / 16;
|
||||
my $j = ($dur & 0xf);
|
||||
$dur = (2**$i)*$j*0.25;
|
||||
$cde = sprintf("%02x", $cx & ~0x20);
|
||||
}
|
||||
|
||||
my $v = $codes{$cde};
|
||||
$v = "unknown_$cde" if(!defined($v));
|
||||
$v .= " $dur" if($dur);
|
||||
|
||||
my $def = $defptr{"$dev $btn"};
|
||||
if($def) {
|
||||
my @list;
|
||||
foreach my $n (keys %{ $def }) {
|
||||
my $lh = $def->{$n};
|
||||
$lh->{CHANGED}[0] = $v;
|
||||
$lh->{STATE} = $v;
|
||||
$lh->{READINGS}{state}{TIME} = TimeNow();
|
||||
$lh->{READINGS}{state}{VAL} = $v;
|
||||
Log GetLogLevel($n,2), "FS20 $n $v";
|
||||
push(@list, $n);
|
||||
}
|
||||
return @list;
|
||||
|
||||
} else {
|
||||
# Special FHZ initialization parameter. In Multi-FHZ-Mode we receive
|
||||
# it by the second FHZ
|
||||
return "" if($dev eq "0001" && $btn eq "00" && $cde eq "00");
|
||||
|
||||
my $dev_four = hex2four($dev);
|
||||
my $btn_four = hex2four($btn);
|
||||
Log 3, "FS20 Unknown device $dev ($dev_four), " .
|
||||
"Button $btn ($btn_four) Code $cde ($v), please define it";
|
||||
return "UNDEFINED FS20: $dev/$btn/$cde";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#############################
|
||||
sub
|
||||
hex2four($)
|
||||
{
|
||||
my $v = shift;
|
||||
my $r = "";
|
||||
foreach my $x (split("", $v)) {
|
||||
$r .= sprintf("%d%d", (hex($x)/4)+1, (hex($x)%4)+1);
|
||||
}
|
||||
return $r;
|
||||
}
|
||||
|
||||
#############################
|
||||
sub
|
||||
four2hex($$)
|
||||
{
|
||||
my ($v,$len) = @_;
|
||||
my $r = 0;
|
||||
foreach my $x (split("", $v)) {
|
||||
$r = $r*4+($x-1);
|
||||
}
|
||||
return sprintf("%0*x", $len,$r);
|
||||
}
|
||||
|
||||
|
||||
1;
|
|
@ -1,533 +0,0 @@
|
|||
##############################################
|
||||
package main;
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
sub doSoftBuffer($);
|
||||
sub softBufferTimer($);
|
||||
sub getFhtMin($);
|
||||
sub getFhtBuffer($);
|
||||
|
||||
my %codes = (
|
||||
"0000.." => "actuator",
|
||||
"0100.." => "actuator1",
|
||||
"0200.." => "actuator2",
|
||||
"0300.." => "actuator3",
|
||||
"0400.." => "actuator4",
|
||||
"0500.." => "actuator5",
|
||||
"0600.." => "actuator6",
|
||||
"0700.." => "actuator7",
|
||||
"0800.." => "actuator8",
|
||||
|
||||
"140069" => "mon-from1",
|
||||
"150069" => "mon-to1",
|
||||
"160069" => "mon-from2",
|
||||
"170069" => "mon-to2",
|
||||
"180069" => "tue-from1",
|
||||
"190069" => "tue-to1",
|
||||
"1a0069" => "tue-from2",
|
||||
"1b0069" => "tue-to2",
|
||||
"1c0069" => "wed-from1",
|
||||
"1d0069" => "wed-to1",
|
||||
"1e0069" => "wed-from2",
|
||||
"1f0069" => "wed-to2",
|
||||
"200069" => "thu-from1",
|
||||
"210069" => "thu-to1",
|
||||
"220069" => "thu-from2",
|
||||
"230069" => "thu-to2",
|
||||
"240069" => "fri-from1",
|
||||
"250069" => "fri-to1",
|
||||
"260069" => "fri-from2",
|
||||
"270069" => "fri-to2",
|
||||
"280069" => "sat-from1",
|
||||
"290069" => "sat-to1",
|
||||
"2a0069" => "sat-from2",
|
||||
"2b0069" => "sat-to2",
|
||||
"2c0069" => "sun-from1",
|
||||
"2d0069" => "sun-to1",
|
||||
"2e0069" => "sun-from2",
|
||||
"2f0069" => "sun-to2",
|
||||
|
||||
"3e0069" => "mode",
|
||||
"3f0069" => "holiday1", # Not verified
|
||||
"400069" => "holiday2", # Not verified
|
||||
"410069" => "desired-temp",
|
||||
"XX0069" => "measured-temp", # sum of next. two, never really sent
|
||||
"420069" => "measured-low",
|
||||
"430069" => "measured-high",
|
||||
"440069" => "warnings",
|
||||
"450069" => "manu-temp", # No clue what it does.
|
||||
|
||||
"..0067" => "repeat1", # repeat the last data (?)
|
||||
"..0077" => "repeat2",
|
||||
|
||||
"600069" => "year",
|
||||
"610069" => "month",
|
||||
"620069" => "day",
|
||||
"630069" => "hour",
|
||||
"640069" => "minute",
|
||||
"650069" => "report1",
|
||||
"660069" => "report2",
|
||||
|
||||
"820069" => "day-temp",
|
||||
"840069" => "night-temp",
|
||||
"850069" => "lowtemp-offset", # Alarm-Temp.-Differenz
|
||||
"8a0069" => "windowopen-temp",
|
||||
);
|
||||
|
||||
my %cantset = (
|
||||
"actuators" => 1,
|
||||
"actuator1" => 1,
|
||||
"actuator2" => 1,
|
||||
"actuator3" => 1,
|
||||
"actuator4" => 1,
|
||||
"actuator5" => 1,
|
||||
"actuator6" => 1,
|
||||
"actuator7" => 1,
|
||||
"actuator8" => 1,
|
||||
"measured-temp" => 1,
|
||||
"measured-high" => 1,
|
||||
"measured-low" => 1,
|
||||
"warnings" => 1,
|
||||
"repeat1" => 1,
|
||||
"repeat2" => 1,
|
||||
);
|
||||
|
||||
|
||||
my %priority = (
|
||||
"desired-temp"=> 1,
|
||||
"mode" => 2,
|
||||
"report1" => 3,
|
||||
"report2" => 3,
|
||||
"holiday1" => 4,
|
||||
"holiday2" => 5,
|
||||
"day-temp" => 6,
|
||||
"night-temp" => 7,
|
||||
);
|
||||
|
||||
my %c2m = (0 => "auto", 1 => "manual", 2 => "holiday", 3 => "holiday_short");
|
||||
my %m2c; # Reverse c2m
|
||||
my %c2b; # command->button hash (reverse of codes)
|
||||
my %c2bset; # Setteable values
|
||||
my %defptr;
|
||||
|
||||
my $defmin = 0; # min fhtbuf free bytes before sending commands
|
||||
my $retryafter = 240; # in seconds, only when fhtsoftbuffer is active
|
||||
my $cmdcount = 0;
|
||||
|
||||
#####################################
|
||||
sub
|
||||
FHT_Initialize($)
|
||||
{
|
||||
my ($hash) = @_;
|
||||
|
||||
foreach my $k (keys %codes) {
|
||||
my $v = $codes{$k};
|
||||
$c2b{$v} = $k;
|
||||
$c2bset{$v} = substr($k, 0, 2) if(!defined($cantset{$v}));
|
||||
}
|
||||
foreach my $k (keys %c2m) {
|
||||
$m2c{$c2m{$k}} = $k;
|
||||
}
|
||||
|
||||
# 810c0426 0909a001 1111 1600
|
||||
# 810c04b3 0909a001 1111 44006900
|
||||
# 810b0402 83098301 1111 41301d
|
||||
# 81090421 c409c401 1111 00
|
||||
# 810c0d20 0909a001 3232 7e006724 (NYI)
|
||||
$hash->{Match} = "^81..(04|09|0d)..(0909a001|83098301|c409c401)..";
|
||||
$hash->{SetFn} = "FHT_Set";
|
||||
$hash->{StateFn} = "FHT_SetState";
|
||||
$hash->{DefFn} = "FHT_Define";
|
||||
$hash->{UndefFn} = "FHT_Undef";
|
||||
$hash->{ParseFn} = "FHT_Parse";
|
||||
$hash->{AttrList} = "do_not_notify:0,1 model;fht80b dummy:0,1 " .
|
||||
"showtime:0,1 loglevel:0,1,2,3,4,5,6 retrycount minfhtbuffer";
|
||||
}
|
||||
|
||||
|
||||
sub
|
||||
FHT_Set($@)
|
||||
{
|
||||
my ($hash, @a) = @_;
|
||||
my $ret = "";
|
||||
|
||||
return "\"set $a[0]\" needs at least two parameters" if(@a < 2);
|
||||
|
||||
my $name = shift(@a);
|
||||
# Backward compatibility, replace refreshvalues with report1 and report2.
|
||||
for(my $i = 0; $i < @a; $i++) {
|
||||
splice(@a,$i,1,("report1","255","report2","255"))
|
||||
if($a[$i] eq "refreshvalues");
|
||||
}
|
||||
|
||||
my $ncmd = 0;
|
||||
my $arg = "020183" . $hash->{CODE};
|
||||
my ($cmd, $allcmd, $val) = ("", "", "");
|
||||
|
||||
while(@a) {
|
||||
$cmd = shift(@a);
|
||||
|
||||
$allcmd .=" " if($allcmd);
|
||||
$allcmd .= $cmd;
|
||||
|
||||
return "Unknown argument $cmd, choose one of " . join(" ", sort keys %c2bset)
|
||||
if(!defined($c2bset{$cmd}));
|
||||
return "\"set $name\" needs a parameter"
|
||||
if(@a < 1);
|
||||
$ncmd++;
|
||||
$val = shift(@a);
|
||||
$arg .= $c2bset{$cmd};
|
||||
|
||||
if ($cmd =~ m/-temp/) {
|
||||
|
||||
return "Invalid temperature, use NN.N" if($val !~ m/^\d*\.?\d+$/);
|
||||
return "Invalid temperature, must between 5.5 and 30.5"
|
||||
if($val < 5.5 || $val > 30.5);
|
||||
my $a = int($val*2);
|
||||
$arg .= sprintf("%02x", $a);
|
||||
$ret .= sprintf("Rounded temperature to %.1f", $a/2) if($a/2 != $val);
|
||||
$val = sprintf("%.1f", $a/2);
|
||||
|
||||
} elsif($cmd =~ m/-from/ || $cmd =~ m/-to/) {
|
||||
|
||||
return "Invalid timeformat, use HH:MM"
|
||||
if($val !~ m/^([0-2]\d):([0-5]\d)/);
|
||||
my $a = ($1*6) + ($2/10);
|
||||
$arg .= sprintf("%02x", $a);
|
||||
my $nt = sprintf("%02d:%02d", $1, int($2/10)*10);
|
||||
$ret .= "Rounded $cmd to $nt" if($nt ne $val);
|
||||
$val = $nt;
|
||||
|
||||
} elsif($cmd eq "mode") {
|
||||
|
||||
return "Invalid mode, use one of " . join(" ", sort keys %m2c)
|
||||
if(!defined($m2c{$val}));
|
||||
$arg .= sprintf("%02x", $m2c{$val});
|
||||
|
||||
} elsif ($cmd eq "lowtemp-offset") {
|
||||
|
||||
return "Invalid lowtemperature-offset, must between 1 and 5"
|
||||
if($val !~ m/^[1-5]$/);
|
||||
$arg .= sprintf("%02x", $val);
|
||||
$val = "$val.0";
|
||||
|
||||
} else { # Holiday1, Holiday2
|
||||
|
||||
return "Invalid argument, must be between 1 and 255"
|
||||
if($val !~ m/^\d+$/ || $val < 0 || $val > 255);
|
||||
$arg .= sprintf("%02x", $val) if(defined($val));
|
||||
|
||||
}
|
||||
$allcmd .= " $val" if($val);
|
||||
}
|
||||
|
||||
return "Too many commands specified, an FHT only supports up to 8"
|
||||
if($ncmd > 8);
|
||||
|
||||
my $ioname = "";
|
||||
$ioname = $hash->{IODev}->{NAME} if($hash->{IODev});
|
||||
if($attr{$ioname} && $attr{$ioname}{fhtsoftbuffer}) {
|
||||
my $io = $hash->{IODev};
|
||||
my %h = (HASH => $hash, CMD => $allcmd, ARG => $arg);
|
||||
|
||||
my $prio = $priority{$cmd};
|
||||
$prio = "9" if(!$prio);
|
||||
my $key = $prio . ":" . gettimeofday() . ":" . $cmdcount++;
|
||||
|
||||
$io->{SOFTBUFFER}{$key} = \%h;
|
||||
doSoftBuffer($io);
|
||||
|
||||
} else {
|
||||
|
||||
IOWrite($hash, "04", $arg) if(!IsDummy($name));
|
||||
Log GetLogLevel($name,2), "FHT set $name $allcmd";
|
||||
|
||||
}
|
||||
|
||||
return $ret;
|
||||
}
|
||||
|
||||
|
||||
#####################################
|
||||
sub
|
||||
FHT_SetState($$$$)
|
||||
{
|
||||
my ($hash, $tim, $vt, $val) = @_;
|
||||
|
||||
return "Undefined type $vt" if(!defined($c2b{$vt}));
|
||||
return undef;
|
||||
}
|
||||
|
||||
|
||||
#####################################
|
||||
sub
|
||||
FHT_Define($$)
|
||||
{
|
||||
my ($hash, $def) = @_;
|
||||
my @a = split("[ \t][ \t]*", $def);
|
||||
|
||||
return "wrong syntax: define <name> FHT CODE" if(int(@a) != 3);
|
||||
$a[2] = lc($a[2]);
|
||||
return "Define $a[0]: wrong CODE format: specify a 4 digit hex value"
|
||||
if($a[2] !~ m/^[a-f0-9][a-f0-9][a-f0-9][a-f0-9]$/i);
|
||||
|
||||
|
||||
$hash->{CODE} = $a[2];
|
||||
$hash->{CODE} = $a[2];
|
||||
$defptr{$a[2]} = $hash;
|
||||
$attr{$a[0]}{retrycount} = 3;
|
||||
|
||||
AssignIoPort($hash);
|
||||
|
||||
Log GetLogLevel($a[0],2),"Asking the FHT device $a[0]/$a[2] to send its data";
|
||||
FHT_Set($hash, ($a[0], "report1", "255", "report2", "255"));
|
||||
|
||||
return undef;
|
||||
}
|
||||
|
||||
#####################################
|
||||
sub
|
||||
FHT_Undef($$)
|
||||
{
|
||||
my ($hash, $name) = @_;
|
||||
delete($defptr{$hash->{CODE}});
|
||||
return undef;
|
||||
}
|
||||
|
||||
#####################################
|
||||
sub
|
||||
FHT_Parse($$)
|
||||
{
|
||||
my ($hash, $msg) = @_;
|
||||
|
||||
my $dev = substr($msg, 16, 4);
|
||||
my $cde = substr($msg, 20, 6);
|
||||
my $val = substr($msg, 26, 2) if(length($msg) > 26);
|
||||
my $confirm = 0;
|
||||
|
||||
if(!defined($defptr{$dev})) {
|
||||
Log 3, "FHT Unknown device $dev, please define it";
|
||||
return "UNDEFINED FHT $dev";
|
||||
}
|
||||
|
||||
my $def = $defptr{$dev};
|
||||
my $name = $def->{NAME};
|
||||
|
||||
# Unknown, but don't want report it. Should come with c409c401
|
||||
return "" if($cde eq "00");
|
||||
|
||||
if(length($cde) < 6) {
|
||||
Log GetLogLevel($name,2), "FHT Unknown code from $name : $cde";
|
||||
$def->{CHANGED}[0] = "unknown_$cde";
|
||||
return $name;
|
||||
}
|
||||
|
||||
my $scmd = substr($cde, 0, 2);
|
||||
if(!$val || $scmd eq "65" || $scmd eq "66") {
|
||||
# This is a confirmation message. We reformat it so that
|
||||
# it looks like a real message, and let the rest parse it
|
||||
Log 4, "FHT $name confirmation: $cde";
|
||||
$val = substr($cde, 2, 2);
|
||||
$cde = $scmd . "0069";
|
||||
$confirm = 1;
|
||||
}
|
||||
|
||||
my $cmd;
|
||||
foreach my $c (keys %codes) {
|
||||
if($cde =~ m/$c/) {
|
||||
$cmd = $codes{$c};
|
||||
last;
|
||||
}
|
||||
}
|
||||
|
||||
$val = hex($val);
|
||||
|
||||
if(!$cmd) {
|
||||
Log 4, "FHT $name (Unknown: $cde => $val)";
|
||||
$def->{CHANGED}[0] = "unknown_$cde: $val";
|
||||
return $name;
|
||||
}
|
||||
|
||||
my $tn = TimeNow();
|
||||
|
||||
###########################
|
||||
# Reformat the values so they are readable.
|
||||
# The first four are confirmation messages, so they must be converted to
|
||||
# the same format as the input (for the softbuffer)
|
||||
|
||||
if($cmd =~ m/-from/ || $cmd =~ m/-to/) {
|
||||
$val = sprintf("%02d:%02d", $val/6, ($val%6)*10);
|
||||
|
||||
} elsif($cmd eq "mode") {
|
||||
$val = $c2m{$val} if(defined($c2m{$val}));
|
||||
|
||||
} elsif($cmd =~ m/.*-temp/) {
|
||||
$val = sprintf("%.1f", $val / 2)
|
||||
|
||||
} elsif($cmd eq "lowtemp-offset") {
|
||||
$val = sprintf("%d.0", $val)
|
||||
|
||||
} elsif($cmd =~ m/^actuator/) {
|
||||
|
||||
my $sval = substr($cde, 4, 2);
|
||||
my $fv = sprintf("%d%%", int(100*$val/255+0.5));
|
||||
|
||||
if($sval =~ m/.6/) { $val = "$fv" }
|
||||
elsif($sval =~ m/.8/) { $val = "offset: $fv" }
|
||||
elsif($sval =~ m/.a/) { $val = "lime-protection" }
|
||||
elsif($sval =~ m/.c/) { $val = "synctime" }
|
||||
elsif($sval =~ m/.e/) { $val = "test" }
|
||||
elsif($sval =~ m/.f/) { $val = "pair" }
|
||||
else { $val = "unknown_$sval: $fv" }
|
||||
|
||||
} elsif($cmd eq "measured-low") {
|
||||
$def->{READINGS}{$cmd}{TIME} = $tn;
|
||||
$def->{READINGS}{$cmd}{VAL} = $val;
|
||||
return "";
|
||||
|
||||
} elsif($cmd eq "measured-high") {
|
||||
$def->{READINGS}{$cmd}{TIME} = $tn;
|
||||
$def->{READINGS}{$cmd}{VAL} = $val;
|
||||
|
||||
if(defined($def->{READINGS}{"measured-low"}{VAL})) {
|
||||
|
||||
$val = $val*256 + $def->{READINGS}{"measured-low"}{VAL};
|
||||
$val /= 10;
|
||||
$val = sprintf("%.1f (Celsius)", $val);
|
||||
$cmd = "measured-temp"
|
||||
|
||||
} else {
|
||||
return "";
|
||||
}
|
||||
|
||||
} elsif($cmd eq "warnings") {
|
||||
my $nVal;
|
||||
if($val & 1) { $nVal = "Battery low"; }
|
||||
if($val & 2) { $nVal .= "; " if($nVal); $nVal .= "Temperature too low"; }
|
||||
if($val &32) { $nVal .= "; " if($nVal); $nVal .= "Window open"; }
|
||||
if($val &16) { $nVal .= "; " if($nVal); $nVal .= "Fault on window sensor"; }
|
||||
$val = $nVal? $nVal : "none";
|
||||
|
||||
}
|
||||
|
||||
$def->{READINGS}{$cmd}{TIME} = $tn;
|
||||
$def->{READINGS}{$cmd}{VAL} = $val;
|
||||
$def->{CHANGED}[0] = "$cmd: $val";
|
||||
$def->{STATE} = "$cmd: $val" if($cmd eq "measured-temp");
|
||||
|
||||
Log 4, "FHT $name $cmd: $val";
|
||||
|
||||
################################
|
||||
# Softbuffer: delete confirmed commands
|
||||
if($confirm) {
|
||||
my $found;
|
||||
my $io = $def->{IODev};
|
||||
foreach my $key (sort keys %{$io->{SOFTBUFFER}}) {
|
||||
my $h = $io->{SOFTBUFFER}{$key};
|
||||
my $hcmd = $h->{CMD};
|
||||
my $hname = $h->{HASH}->{NAME};
|
||||
Log 4, "FHT softbuffer check: $hname / $hcmd";
|
||||
if($hname eq $name && $hcmd =~ m/^$cmd $val/) {
|
||||
$found = $key;
|
||||
Log 4, "FHT softbuffer found";
|
||||
last;
|
||||
}
|
||||
}
|
||||
delete($io->{SOFTBUFFER}{$found}) if($found);
|
||||
}
|
||||
|
||||
return $name;
|
||||
}
|
||||
|
||||
|
||||
# Check the softwarebuffer and send/resend commands
|
||||
sub
|
||||
doSoftBuffer($)
|
||||
{
|
||||
my ($io) = @_;
|
||||
|
||||
my $now = gettimeofday();
|
||||
|
||||
my $count = 0;
|
||||
my $fhzbuflen = -999;
|
||||
foreach my $key (keys %{ $io->{SOFTBUFFER} }) {
|
||||
|
||||
$count++;
|
||||
my $h = $io->{SOFTBUFFER}{$key};
|
||||
my $name = $h->{HASH}->{NAME};
|
||||
|
||||
if($h->{NSENT}) {
|
||||
next if($now-$h->{SENDTIME} < $retryafter);
|
||||
my $retry = $attr{$name}{retrycount};
|
||||
if($h->{NSENT} > $retry) {
|
||||
Log GetLogLevel($name,2), "$name set $h->{CMD}: ".
|
||||
"no confirmation after $h->{NSENT} tries, giving up";
|
||||
delete($io->{SOFTBUFFER}{$key});
|
||||
next;
|
||||
}
|
||||
}
|
||||
|
||||
$fhzbuflen = getFhtBuffer($io) if($fhzbuflen == -999);
|
||||
my $arglen = length($h->{ARG})/2 - 2; # Length in bytes
|
||||
|
||||
next if($fhzbuflen < $arglen || $fhzbuflen < getFhtMin($io));
|
||||
IOWrite($h->{HASH}, "04", $h->{ARG}) if(!IsDummy($name));
|
||||
Log GetLogLevel($name,2), "FHT set $name $h->{CMD}";
|
||||
|
||||
$fhzbuflen -= $arglen;
|
||||
$h->{SENDTIME} = $now;
|
||||
$h->{NSENT}++;
|
||||
|
||||
}
|
||||
|
||||
if($count && !$io->{SOFTBUFFERTIMER}) {
|
||||
$io->{SOFTBUFFERTIMER} = 1;
|
||||
InternalTimer(gettimeofday()+30, "softBufferTimer", $io, 0);
|
||||
}
|
||||
}
|
||||
|
||||
#####################################
|
||||
# Wrapper for the InternalTimer
|
||||
sub
|
||||
softBufferTimer($)
|
||||
{
|
||||
my ($io) = @_;
|
||||
delete($io->{SOFTBUFFERTIMER});
|
||||
doSoftBuffer($io);
|
||||
}
|
||||
|
||||
#####################################
|
||||
sub
|
||||
getFhtMin($)
|
||||
{
|
||||
my ($io) = @_;
|
||||
my $ioname = $io->{NAME};
|
||||
return $attr{$ioname}{minfhtbuffer}
|
||||
if($attr{$ioname} && $attr{$ioname}{minfhtbuffer});
|
||||
return $defmin;
|
||||
}
|
||||
|
||||
#####################################
|
||||
# get the FHZ hardwarebuffer without logentry as decimal value
|
||||
sub
|
||||
getFhtBuffer($)
|
||||
{
|
||||
my ($io) = @_;
|
||||
my $count = 0;
|
||||
|
||||
return getFhtMin($io) if(IsDummy($io->{NAME}));
|
||||
|
||||
for(;;) {
|
||||
FHZ_Write($io, "04", "c90185");
|
||||
my $msg = FHZ_ReadAnswer($io, "fhtbuf");
|
||||
if(!defined($msg)) { $msg= ""; }
|
||||
Log 5, "getFhtBuffer: $count $msg";
|
||||
|
||||
return hex(substr($msg, 16, 2)) if($msg && $msg =~ m/^[0-9A-F]+$/i);
|
||||
return 0 if($count++ > 5);
|
||||
}
|
||||
}
|
||||
|
||||
1;
|
|
@ -1,221 +0,0 @@
|
|||
##############################################
|
||||
package main;
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
my %codes = (
|
||||
"0" => "HMS100TF",
|
||||
"1" => "HMS100T",
|
||||
"2" => "HMS100WD",
|
||||
"3" => "RM100-2",
|
||||
"4" => "HMS100TFK", # Depending on the onboard jumper it is 4 or 5
|
||||
"5" => "HMS100TFK",
|
||||
"6" => "HMS100MG",
|
||||
"8" => "HMS100CO",
|
||||
);
|
||||
|
||||
my %defptr;
|
||||
|
||||
|
||||
#####################################
|
||||
sub
|
||||
HMS_Initialize($)
|
||||
{
|
||||
my ($hash) = @_;
|
||||
|
||||
# 810e047e0510a001473a000000120233 HMS100TF
|
||||
# 810e04b90511a0018e63000001100000 HMS100T
|
||||
# 810e04e80212a001ec46000001000000 HMS100WD
|
||||
# 810e04d70213a001b16d000003000000 RM100-2
|
||||
# 810e047f0214a001a81f000001000000 HMS100TFK
|
||||
# 810e048f0295a0010155000001000000 HMS100TFK (jumper)
|
||||
# 810e04330216a001b4c5000001000000 HMS100MG
|
||||
# 810e04210218a00186e0000000000000 HMS100CO
|
||||
|
||||
$hash->{Match} = "^810e04....(1|5|9)[0-8]a001";
|
||||
$hash->{DefFn} = "HMS_Define";
|
||||
$hash->{UndefFn} = "HMS_Undef";
|
||||
$hash->{ParseFn} = "HMS_Parse";
|
||||
$hash->{AttrList} = "do_not_notify:0,1 showtime:0,1 model;hms100-t,hms100-tf,hms100-wd,hms100-mg,hms100-tfk,rm100-2,hms100-co loglevel:0,1,2,3,4,5,6";
|
||||
}
|
||||
|
||||
#####################################
|
||||
sub
|
||||
HMS_Define($$)
|
||||
{
|
||||
my ($hash, $def) = @_;
|
||||
my @a = split("[ \t][ \t]*", $def);
|
||||
|
||||
return "wrong syntax: define <name> HMS CODE" if(int(@a) != 3);
|
||||
$a[2] = lc($a[2]);
|
||||
return "Define $a[0]: wrong CODE format: specify a 4 digit hex value"
|
||||
if($a[2] !~ m/^[a-f0-9][a-f0-9][a-f0-9][a-f0-9]$/);
|
||||
|
||||
|
||||
$hash->{CODE} = $a[2];
|
||||
$defptr{$a[2]} = $hash;
|
||||
|
||||
return undef;
|
||||
}
|
||||
|
||||
#####################################
|
||||
sub
|
||||
HMS_Undef($$)
|
||||
{
|
||||
my ($hash, $name) = @_;
|
||||
delete($defptr{$hash->{CODE}});
|
||||
return undef;
|
||||
}
|
||||
|
||||
#####################################
|
||||
sub
|
||||
HMS_Parse($$)
|
||||
{
|
||||
my ($hash, $msg) = @_;
|
||||
|
||||
my $dev = substr($msg, 16, 4);
|
||||
my $cde = substr($msg, 11, 1);
|
||||
my $val = substr($msg, 24, 8) if(length($msg) == 32);
|
||||
|
||||
my $type = "";
|
||||
foreach my $c (keys %codes) {
|
||||
if($cde =~ m/$c/) {
|
||||
$type = $codes{$c};
|
||||
last;
|
||||
}
|
||||
}
|
||||
|
||||
# As the HMS devices change their id on each battery change, we offer
|
||||
# a wildcard too for each type: 100<device-code>,
|
||||
my $odev = $dev;
|
||||
if(!defined($defptr{$dev})) {
|
||||
Log 4, "HMS device $dev not defined, using the wildcard device 100$cde";
|
||||
$dev = "100$cde";
|
||||
}
|
||||
|
||||
if(!defined($defptr{$dev})) {
|
||||
Log 3, "Unknown HMS device $dev/$odev, please define it";
|
||||
$type = "HMS" if(!$type);
|
||||
return "UNDEFINED $type $odev";
|
||||
}
|
||||
|
||||
my $def = $defptr{$dev};
|
||||
|
||||
my (@v, @txt, @sfx);
|
||||
|
||||
if($type eq "HMS100TF") {
|
||||
|
||||
@txt = ( "temperature", "humidity", "battery");
|
||||
@sfx = ( "(Celsius)", "(%)", "");
|
||||
|
||||
# Codierung <s1><s0><t1><t0><f0><t2><f2><f1>
|
||||
my $status = hex(substr($val, 0, 1));
|
||||
$v[0] = int(substr($val, 5, 1) . substr($val, 2, 2))/10;
|
||||
$v[1] = int(substr($val, 6, 2) . substr($val, 4, 1))/10;
|
||||
$v[2] = "ok";
|
||||
if ( $status & 2 ) { $v[2] = "empty"; }
|
||||
if ( $status & 4 ) { $v[2] = "replaced"; }
|
||||
if ( $status & 8 ) { $v[0] = -$v[0]; }
|
||||
|
||||
$val = "T: $v[0] H: $v[1] Bat: $v[2]";
|
||||
|
||||
} elsif ($type eq "HMS100T") {
|
||||
|
||||
@txt = ( "temperature", "battery");
|
||||
@sfx = ( "(Celsius)", "");
|
||||
|
||||
my $status = hex(substr($val, 0, 1));
|
||||
$v[0] = int(substr($val, 5, 1) . substr($val, 2, 2))/10;
|
||||
$v[1] = "ok";
|
||||
if ( $status & 2 ) { $v[1] = "empty"; }
|
||||
if ( $status & 4 ) { $v[1] = "replaced"; }
|
||||
if ( $status & 8 ) { $v[0] = -$v[0]; }
|
||||
|
||||
$val = "T: $v[0] Bat: $v[1]";
|
||||
|
||||
} elsif ($type eq "HMS100WD") {
|
||||
|
||||
@txt = ( "water_detect", "battery");
|
||||
@sfx = ( "", "");
|
||||
|
||||
# Battery-low condition detect is not yet properly
|
||||
# implemented. As soon as my WD's batteries get low
|
||||
# I am willing to supply a patch ;-) SEP7-RIPE, 2006/05/13
|
||||
my $status = hex(substr($val, 1, 1));
|
||||
$v[1] = "ok";
|
||||
$v[0] = "off";
|
||||
if ( $status & 1 ) { $v[0] = "on"; }
|
||||
$val = "Water Detect: $v[0]";
|
||||
|
||||
} elsif ($type eq "HMS100TFK") { # By Peter P.
|
||||
|
||||
@txt = ( "switch_detect", "battery");
|
||||
@sfx = ( "", "");
|
||||
# Battery-low condition detect is not yet properly implemented.
|
||||
my $status = hex(substr($val, 1, 1));
|
||||
$v[0] = ($status ? "on" : "off");
|
||||
$v[1] = "off";
|
||||
$val = "Switch Detect: $v[0]";
|
||||
|
||||
} elsif($type eq "RM100-2") {
|
||||
|
||||
@txt = ( "smoke_detect", "battery");
|
||||
@sfx = ( "", "");
|
||||
|
||||
$v[0] = ( hex(substr($val, 1, 1)) != "0" ) ? "on" : "off";
|
||||
$v[1] = "unknown"; # Battery-low detect is _NOT_ implemented.
|
||||
$val = "smoke_detect: $v[0]";
|
||||
|
||||
} elsif ($type eq "HMS100MG") { # By Peter Stark
|
||||
|
||||
@txt = ( "gas_detect", "battery");
|
||||
@sfx = ( "", "");
|
||||
|
||||
# Battery-low condition detect is not yet properly
|
||||
# implemented.
|
||||
my $status = hex(substr($val, 1, 1));
|
||||
$v[0] = ($status != "0") ? "on" : "off";
|
||||
$v[1] = "off";
|
||||
if ($status & 1) { $v[0] = "on"; }
|
||||
$val = "Gas Detect: $v[0]";
|
||||
|
||||
} elsif ($type eq "HMS100CO") { # By PAN
|
||||
|
||||
@txt = ( "gas_detect", "battery");
|
||||
@sfx = ( "", "");
|
||||
|
||||
# Battery-low condition detect is not yet properly
|
||||
# implemented.
|
||||
my $status = hex(substr($val, 1, 1));
|
||||
$v[0] = ($status != "0") ? "on" : "off";
|
||||
$v[1] = "off";
|
||||
if ($status & 1) { $v[0] = "on"; }
|
||||
$val = "CO Detect: $v[0]";
|
||||
|
||||
} else {
|
||||
|
||||
Log 4, "HMS Device $dev (Unknown type: $type)";
|
||||
return "";
|
||||
|
||||
}
|
||||
|
||||
my $now = TimeNow();
|
||||
Log GetLogLevel($def->{NAME},4), "HMS Device $dev ($type: $val)";
|
||||
|
||||
my $max = int(@txt);
|
||||
for( my $i = 0; $i < $max; $i++) {
|
||||
$def->{READINGS}{$txt[$i]}{TIME} = $now;
|
||||
my $v = "$v[$i] $sfx[$i]";
|
||||
$def->{READINGS}{$txt[$i]}{VAL} = $v;
|
||||
$def->{CHANGED}[$i] = "$txt[$i]: $v";
|
||||
}
|
||||
$def->{READINGS}{type}{TIME} = $now;
|
||||
$def->{READINGS}{type}{VAL} = $type;
|
||||
|
||||
$def->{STATE} = $val;
|
||||
$def->{CHANGED}[$max] = $val;
|
||||
return $def->{NAME};
|
||||
}
|
||||
|
||||
1;
|
|
@ -1,252 +0,0 @@
|
|||
##############################################
|
||||
package main;
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
my %defptr;
|
||||
my $negcount = 0;
|
||||
|
||||
######################
|
||||
# Note: this is just an empty hull.
|
||||
|
||||
#####################################
|
||||
sub
|
||||
KS300_Initialize($)
|
||||
{
|
||||
my ($hash) = @_;
|
||||
|
||||
# Message is like
|
||||
# 810d04f94027a00171212730000008
|
||||
# 81 0d 04 f9 4027a00171 212730000008
|
||||
|
||||
$hash->{Match} = "^810.04..402.a001";
|
||||
$hash->{DefFn} = "KS300_Define";
|
||||
$hash->{UndefFn} = "KS300_Undef";
|
||||
$hash->{ParseFn} = "KS300_Parse";
|
||||
$hash->{AttrList} = "do_not_notify:0,1 showtime:0,1 model:ks300 loglevel:0,1";
|
||||
}
|
||||
|
||||
#####################################
|
||||
sub
|
||||
KS300_Define($$)
|
||||
{
|
||||
my ($hash, $def) = @_;
|
||||
my @a = split("[ \t][ \t]*", $def);
|
||||
|
||||
return "wrong syntax: define <name> KS300 <code> " .
|
||||
"[ml/raincounter] [wind-factor]" if(int(@a) < 3 || int(@a) > 5);
|
||||
$a[2] = lc($a[2]);
|
||||
return "Define $a[0]: wrong CODE format: specify a 4 digit hex value"
|
||||
if($a[2] !~ m/^[a-f0-9][a-f0-9][a-f0-9][a-f0-9]$/);
|
||||
|
||||
$hash->{CODE} = $a[2];
|
||||
my $rainunit = ((int(@a) > 3) ? $a[3] : 255);
|
||||
my $windunit = ((int(@a) > 4) ? $a[4] : 1.0);
|
||||
$hash->{CODE} = $a[2];
|
||||
$hash->{RAINUNIT} = $rainunit;
|
||||
$hash->{WINDUNIT} = $windunit;
|
||||
$defptr{$a[2]} = $hash;
|
||||
|
||||
return undef;
|
||||
}
|
||||
|
||||
#####################################
|
||||
sub
|
||||
KS300_Undef($$)
|
||||
{
|
||||
my ($hash, $name) = @_;
|
||||
delete($defptr{$hash->{CODE}});
|
||||
return undef;
|
||||
}
|
||||
|
||||
|
||||
#####################################
|
||||
sub
|
||||
KS300_Parse($$)
|
||||
{
|
||||
my ($hash,$msg) = @_;
|
||||
|
||||
if($msg !~ m/^810d04..4027a001/) {
|
||||
Log 4, "KS300 unknown message $msg";
|
||||
return "";
|
||||
}
|
||||
|
||||
###############################
|
||||
# 1 2
|
||||
#0123456789012345 67890123456789
|
||||
#
|
||||
#810d04f94027a001 71212730000008
|
||||
###############################
|
||||
my @a = split("", $msg);
|
||||
|
||||
##########################
|
||||
# I've seldom (1 out of 700) seen messages of length 10 and 11 with correct
|
||||
# CRC, they seem to contain partial data (e.g. temp/wind/hum but not rain)
|
||||
# They are suppressed as of now.
|
||||
if(hex($a[3]) != 13) {
|
||||
Log 4, "Strange KS400 message received, wont decode ($msg)";
|
||||
return "";
|
||||
}
|
||||
|
||||
if(int(keys %defptr)) {
|
||||
|
||||
my @arr = keys(%defptr); # No code is known yet
|
||||
my $dev = shift(@arr);
|
||||
my $def = $defptr{$dev};
|
||||
my $haverain = 0;
|
||||
|
||||
my @v;
|
||||
my @txt = ( "rain_raw", "rain", "wind", "humidity", "temperature",
|
||||
"israining", "unknown1", "unknown2", "unknown3");
|
||||
my @sfx = ( "(counter)", "(l/m2)", "(km/h)", "(%)", "(Celsius)",
|
||||
"(yes/no)", "","","");
|
||||
|
||||
# The next instr wont work for empty hashes, so we init it now
|
||||
$def->{READINGS}{$txt[0]}{VAL} = 0 if(!$def->{READINGS});
|
||||
my $r = $def->{READINGS};
|
||||
|
||||
$v[0] = hex("$a[28]$a[27]$a[26]");
|
||||
|
||||
#############################
|
||||
# My KS300 sends a (quite huge) "negative" rain, when the rain begins,
|
||||
# then the value is "normal" again. So we have to filter neg. rain out.
|
||||
# But if the KS300 is sending this value more than once, then accept it,
|
||||
# as the KS300 was probably reset
|
||||
|
||||
if($r->{rain_raw}{VAL}) {
|
||||
my ($rrv, undef) = split(" ", $r->{rain_raw}{VAL});
|
||||
$haverain = 1 if($v[0] != $rrv);
|
||||
if($v[0] < $rrv) {
|
||||
if($negcount++ < 3) {
|
||||
Log 3, "KS300 negative rain, ignoring it";
|
||||
$v[0] = $rrv;
|
||||
} else {
|
||||
Log 1, "KS300 was probably reset, accepting new rain value";
|
||||
}
|
||||
} else {
|
||||
$negcount = 0;
|
||||
}
|
||||
}
|
||||
|
||||
$v[1] = sprintf("%0.1f", $v[0] * $def->{RAINUNIT} / 1000);
|
||||
$v[2] = sprintf("%0.1f", ("$a[25]$a[24].$a[23]"+0) * $def->{WINDUNIT});
|
||||
$v[3] = "$a[22]$a[21]" + 0;
|
||||
$v[4] = "$a[20]$a[19].$a[18]" + 0; $v[4] = "-$v[4]" if($a[17] eq "7");
|
||||
$v[4] = sprintf("%0.1f", $v[4]);
|
||||
|
||||
$v[5] = ((hex($a[17]) & 0x2) || $haverain) ? "yes" : "no";
|
||||
$v[6] = $a[29];
|
||||
$v[7] = $a[16];
|
||||
$v[8] = $a[17];
|
||||
|
||||
# Negative temp
|
||||
$v[4] = -$v[4] if($v[8] & 8);
|
||||
|
||||
my $tm = TimeNow();
|
||||
|
||||
Log GetLogLevel($def->{NAME},4), "KS300 $dev: $msg";
|
||||
|
||||
my $max = int(@v);
|
||||
|
||||
# For logging/summary
|
||||
my $val = "T: $v[4] H: $v[3] W: $v[2] R: $v[1] IR: $v[5]";
|
||||
$def->{STATE} = $val;
|
||||
$def->{CHANGED}[0] = $val;
|
||||
|
||||
for(my $i = 0; $i < $max; $i++) {
|
||||
$r->{$txt[$i]}{TIME} = $tm;
|
||||
$val = "$v[$i] $sfx[$i]";
|
||||
$r->{$txt[$i]}{VAL} = $val;
|
||||
$def->{CHANGED}[$i+1] = "$txt[$i]: $val";
|
||||
}
|
||||
|
||||
###################################
|
||||
# AVG computing
|
||||
if(!$r->{cum_day}) {
|
||||
|
||||
$r->{cum_day}{VAL} = "$tm T: 0 H: 0 W: 0 R: $v[1]";
|
||||
$r->{avg_day}{VAL} = "T: $v[4] H: $v[3] W: $v[2] R: $v[1]";
|
||||
|
||||
} else {
|
||||
|
||||
my @cv = split(" ", $r->{cum_day}{VAL});
|
||||
|
||||
my @cd = split("[ :-]", $r->{cum_day}{TIME});
|
||||
my $csec = 3600*$cd[3] + 60*$cd[4] + $cd[5]; # Sec of last reading
|
||||
|
||||
my @d = split("[ :-]", $tm);
|
||||
my $sec = 3600*$d[3] + 60*$d[4] + $d[5]; # Sec now
|
||||
|
||||
my @sd = split("[ :-]", "$cv[0] $cv[1]");
|
||||
my $ssec = 3600*$sd[3] + 60*$sd[4] + $sd[5]; # Sec at start of day
|
||||
|
||||
my $difft = $sec - $csec;
|
||||
$difft += 86400 if($d[2] != $cd[2]); # Sec since last reading
|
||||
|
||||
my $t = $cv[3] + $difft * $v[4];
|
||||
my $h = $cv[5] + $difft * $v[3];
|
||||
my $w = $cv[7] + $difft * $v[2];
|
||||
my $e = $cv[9];
|
||||
|
||||
$r->{cum_day}{VAL} = "$cv[0] $cv[1] T: $t H: $h W: $w R: $e";
|
||||
|
||||
$difft = $sec - $ssec;
|
||||
$difft += 86400 if($d[2] != $sd[2]); # Sec since last reading
|
||||
|
||||
$t /= $difft; $h /= $difft; $w /= $difft; $e = $v[1] - $cv[9];
|
||||
$r->{avg_day}{VAL} =
|
||||
sprintf("T: %.1f H: %d W: %.1f R: %.1f", $t, $h, $w, $e);
|
||||
|
||||
if($d[2] != $sd[2]) { # Day changed, report it
|
||||
|
||||
$def->{CHANGED}[$max++] = "avg_day $r->{avg_day}{VAL}";
|
||||
$r->{cum_day}{VAL} = "$tm T: 0 H: 0 W: 0 R: $v[1]";
|
||||
|
||||
if(!$r->{cum_month}) { # Check the month
|
||||
|
||||
$r->{cum_month}{VAL} = "1 $r->{avg_day}{VAL}";
|
||||
$r->{avg_month}{VAL} = $r->{avg_day}{VAL};
|
||||
|
||||
} else {
|
||||
|
||||
my @cmv = split(" ", $r->{cum_month}{VAL});
|
||||
$t += $cmv[2]; $w += $cmv[4]; $h += $cmv[6];
|
||||
|
||||
$cmv[0]++;
|
||||
$r->{cum_month}{VAL} =
|
||||
sprintf("%d T: %.1f H: %d W: %.1f R: %.1f",
|
||||
$cmv[0], $t, $h, $w, $cmv[8]+$e);
|
||||
$r->{avg_month}{VAL} =
|
||||
sprintf("T: %.1f H: %d W: %.1f R: %.1f",
|
||||
$t/$cmv[0], $h/$cmv[0], $w/$cmv[0], $cmv[8]+$e);
|
||||
|
||||
if($d[1] != $sd[1]) { # Month changed, report it
|
||||
|
||||
$def->{CHANGED}[$max++] = "avg_month $r->{avg_month}{VAL}";
|
||||
$r->{cum_month}{VAL} = "0 T: 0 H: 0 W: 0 R: 0";
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
$r->{cum_month}{TIME} = $r->{avg_month}{TIME} = $tm;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
$r->{cum_day}{TIME} = $r->{avg_day}{TIME} = $tm;
|
||||
# AVG computing
|
||||
###################################
|
||||
|
||||
return $def->{NAME};
|
||||
|
||||
} else {
|
||||
|
||||
Log 4, "KS300 detected: $msg";
|
||||
|
||||
}
|
||||
|
||||
return "";
|
||||
}
|
||||
|
||||
1;
|
|
@ -1,673 +0,0 @@
|
|||
################################################################
|
||||
#
|
||||
# Copyright notice
|
||||
#
|
||||
# (c) 2007 Copyright: Martin Klerx (Martin at klerx dot de)
|
||||
# All rights reserved
|
||||
#
|
||||
# This script free software; you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation; either version 2 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# The GNU General Public License can be found at
|
||||
# http://www.gnu.org/copyleft/gpl.html.
|
||||
# A copy is found in the textfile GPL.txt and important notices to the license
|
||||
# from the author is found in LICENSE.txt distributed with these scripts.
|
||||
#
|
||||
# This script is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# This copyright notice MUST APPEAR in all copies of the script!
|
||||
#
|
||||
################################################################
|
||||
# examples:
|
||||
# define WS300Device WS300 /dev/ttyUSB1 (fixed name, must be first)
|
||||
# define ash2200-1 WS300 0
|
||||
# define ash2200-2 WS300 1
|
||||
# ...
|
||||
# define ash2200-8 WS300 7
|
||||
# define ks300 WS300 8 (always 8)
|
||||
# define ws300 WS300 9 (always 9)
|
||||
# set WS300Device <interval(5-60 min.)> <height(0-2000 m)> <rainvalume(ml)>
|
||||
################################################################
|
||||
|
||||
package main;
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
my %defptr;
|
||||
my $DeviceName="";
|
||||
my $inbuf="";
|
||||
|
||||
my $config;
|
||||
my $cmd=0x32;
|
||||
my $errcount=0;
|
||||
my $ir="no";
|
||||
my $willi=0;
|
||||
my $oldwind=0.0;
|
||||
my $polling=0;
|
||||
my $acthour=99;
|
||||
my $actday=99;
|
||||
my $actmonth=99;
|
||||
my $oldrain=0;
|
||||
my $rain_hour=0;
|
||||
my $rain_day=0;
|
||||
my $rain_month=0;
|
||||
#####################################
|
||||
sub
|
||||
WS300_Initialize($)
|
||||
{
|
||||
my ($hash) = @_;
|
||||
|
||||
# Provider
|
||||
$hash->{Clients} = ":WS300:";
|
||||
$hash->{ReadFn} = "WS300_Read";
|
||||
$hash->{WriteFn} = "WS300_Write";
|
||||
$hash->{Type} = "FHZ1000";
|
||||
$hash->{Match} = "^WS300.*";
|
||||
$hash->{SetFn} = "WS300_Set";
|
||||
$hash->{GetFn} = "WS300_Get";
|
||||
$hash->{DefFn} = "WS300_Define";
|
||||
$hash->{UndefFn} = "WS300_Undef";
|
||||
$hash->{ParseFn} = "WS300_Parse";
|
||||
$hash->{ReadFn} = "WS300_Read";
|
||||
$hash->{AttrList} = "do_not_notify:0,1 showtime:0,1 model:ws300 loglevel:0,1,2,3,4,5,6";
|
||||
}
|
||||
|
||||
###################################
|
||||
sub
|
||||
WS300_Set($@)
|
||||
{
|
||||
my ($hash, @a) = @_;
|
||||
if($hash->{NAME} eq "WS300Device")
|
||||
{
|
||||
return "wrong syntax: set WS300Device <Interval(5-60 min.)> <height(0-2000 m)> <rainvolume(ml)>" if(int(@a) < 4 || int($a[1]) < 5 || int($a[1]) > 60 || int($a[2]) > 2000);
|
||||
my $bstring = sprintf("%c%c%c%c%c%c%c%c",0xfe,0x30,(int($a[1])&0xff),((int($a[2])>>8)&0xff),(int($a[2])&0xff),((int($a[3])>>8)&0xff),(int($a[3])&0xff),0xfc);
|
||||
$hash->{PortObj}->write($bstring);
|
||||
Log 1,"WS300 synchronization started (".unpack('H*',$bstring).")";
|
||||
return "the ws300pc will now synchronize for 10 minutes";
|
||||
}
|
||||
return "No set function implemented";
|
||||
}
|
||||
|
||||
###################################
|
||||
sub
|
||||
WS300_Get(@)
|
||||
{
|
||||
my ($hash, @a) = @_;
|
||||
if($hash->{NAME} eq "WS300Device")
|
||||
{
|
||||
Log 5,"WS300_Get $a[0] $a[1]";
|
||||
WS300_Poll($hash);
|
||||
return undef;
|
||||
}
|
||||
return "No get function implemented";
|
||||
}
|
||||
|
||||
#####################################
|
||||
sub
|
||||
WS300_Define($$)
|
||||
{
|
||||
my ($hash, $def) = @_;
|
||||
my @a = split("[ \t][ \t]*", $def);
|
||||
my $po;
|
||||
if($a[0] eq "WS300Device")
|
||||
{
|
||||
$defptr{10} = $hash;
|
||||
return "wrong syntax: define WS300Device WS300 <DeviceName>" if(int(@a) < 3);
|
||||
$DeviceName = $a[2];
|
||||
$hash->{STATE} = "Initializing";
|
||||
$hash->{SENSOR} = 10;
|
||||
$hash->{READINGS}{WS300Device}{VAL} = "Initializing";
|
||||
$hash->{READINGS}{WS300Device}{TIME} = TimeNow;
|
||||
|
||||
if ($^O=~/Win/) {
|
||||
eval ("use Win32::SerialPort;");
|
||||
$po = new Win32::SerialPort ($DeviceName);
|
||||
}else{
|
||||
eval ("use Device::SerialPort;");
|
||||
$po = new Device::SerialPort ($DeviceName);
|
||||
}
|
||||
if(!$po)
|
||||
{
|
||||
$hash->{STATE} = "error opening device";
|
||||
$hash->{READINGS}{WS300Device}{VAL} = "error opening device";
|
||||
$hash->{READINGS}{WS300Device}{TIME} = TimeNow;
|
||||
Log 1,"Error opening WS300 Device $a[2]";
|
||||
return "Can't open $a[2]: $!\n";
|
||||
}
|
||||
$po->reset_error();
|
||||
$po->baudrate(19200);
|
||||
$po->databits(8);
|
||||
$po->parity('even');
|
||||
$po->stopbits(1);
|
||||
$po->handshake('none');
|
||||
$po->rts_active(1);
|
||||
$po->dtr_active(1);
|
||||
sleep(1);
|
||||
$po->rts_active(0);
|
||||
$po->write_settings;
|
||||
$hash->{PortObj} = $po;
|
||||
$hash->{DeviceName} = $a[2];
|
||||
$hash->{STATE} = "opened";
|
||||
$hash->{READINGS}{WS300Device}{VAL} = "opened";
|
||||
$hash->{READINGS}{WS300Device}{TIME} = TimeNow;
|
||||
CommandDefine(undef,"WS300Device_timer at +*00:00:05 get WS300Device data");
|
||||
Log 1,"WS300 Device $a[2] opened";
|
||||
$attr{$a[0]}{savefirst} = 1;
|
||||
return undef;
|
||||
}
|
||||
return "wrong syntax: define <name> WS300 <sensor (0-9)>\n0-7=ASH2200\n8=KS300\n9=WS300" if(int(@a) < 3);
|
||||
return "no device: define WS300Device WS300 <DeviceName> first" if($DeviceName eq "");
|
||||
return "Define $a[0]: wrong sensor number." if($a[2] !~ m/^[0-9]$/);
|
||||
$hash->{SENSOR} = $a[2];
|
||||
$defptr{$a[2]} = $hash;
|
||||
|
||||
return undef;
|
||||
}
|
||||
|
||||
#####################################
|
||||
sub
|
||||
WS300_Undef($$)
|
||||
{
|
||||
my ($hash, $name) = @_;
|
||||
return undef if(!defined($hash->{SENSOR}));
|
||||
delete($defptr{$hash->{SENSOR}});
|
||||
return undef;
|
||||
}
|
||||
|
||||
|
||||
#####################################
|
||||
sub
|
||||
WS300_Parse($$)
|
||||
{
|
||||
my ($hash, $msg) = @_;
|
||||
my $ll = GetLogLevel("WS300Device");
|
||||
$ll = 5 if($ll == 2);
|
||||
|
||||
my @c = split("", $config);
|
||||
my @cmsg = split("",unpack('H*',$config));
|
||||
my $dmsg = unpack('H*',$msg);
|
||||
my @a = split("", $dmsg);
|
||||
my $val = "";
|
||||
my $tm;
|
||||
my $h;
|
||||
my $t;
|
||||
my $b;
|
||||
my $l;
|
||||
my $value;
|
||||
my $offs=0;
|
||||
my $ref;
|
||||
my $def;
|
||||
my $zeit;
|
||||
my @txt = ( "temperature", "humidity", "wind", "rain_raw", "israining", "battery", "lost_receives", "pressure", "rain_cum", "rain_hour", "rain_day", "rain_month");
|
||||
my @sfx = ( "(Celsius)", "(%)", "(km/h)", "(counter)", "(yes/no)", " ", "(counter)", "(hPa)", "(mm)", "(mm)", "(mm)", "(mm)");
|
||||
# 1 2 3 4 5 6 7 8
|
||||
# 012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789
|
||||
# 3180800001005d4e00000000000000000000000000000000000000000000594a0634001e00f62403f1fc stored
|
||||
# aaaatttthhtttthhtttthhtttthhtttthhtttthhtttthhtttthhtttthhrrrrwwwwtttthhpppp
|
||||
# 3300544a0000000000000000000000000000000000000000000057470634002c00f32303ee32fc current
|
||||
# tttthhtttthhtttthhtttthhtttthhtttthhtttthhtttthhtttthhrrrrwwwwtttthhppppss
|
||||
# 3210000000000000001005003a0127fc config
|
||||
# 001122334455667788iihhhhmmmm
|
||||
$offs = 2 if(hex($a[0].$a[1]) == 0x33);
|
||||
$offs = 10 if(hex($a[0].$a[1]) == 0x31);
|
||||
if($offs == 0)
|
||||
{
|
||||
Log 1,"WS300 illegal data in WS300_Parse";
|
||||
return undef;
|
||||
}
|
||||
$zeit = time;
|
||||
my $wind = hex($a[58+$offs].$a[59+$offs].$a[60+$offs].$a[61+$offs]);
|
||||
$wind /= 10.0;
|
||||
if(hex($a[0].$a[1]) == 0x33)
|
||||
{
|
||||
return undef if(hex($a[74].$a[75]) == $willi && $wind == $oldwind );
|
||||
$willi = hex($a[74].$a[75]);
|
||||
$ir="no";
|
||||
$ir="yes" if(($willi&0x80));
|
||||
}
|
||||
else
|
||||
{
|
||||
$zeit -= (hex($a[6].$a[7].$a[8].$a[9])*60);
|
||||
}
|
||||
my @lt = localtime($zeit);
|
||||
$tm = sprintf("%04d-%02d-%02d %02d:%02d:%02d",$lt[5]+1900, $lt[4]+1, $lt[3], $lt[2], $lt[1], $lt[0]);
|
||||
$oldwind = $wind;
|
||||
my $press = hex($a[68+$offs].$a[69+$offs].$a[70+$offs].$a[71+$offs]);
|
||||
my $hpress = hex($cmsg[22].$cmsg[23].$cmsg[24].$cmsg[25]);
|
||||
$hpress /= 8.5;
|
||||
$press += $hpress;
|
||||
$press = sprintf("%.1f",$press);
|
||||
my $rainc = hex($a[54+$offs].$a[55+$offs].$a[56+$offs].$a[57+$offs]);
|
||||
my $rain = hex($cmsg[26].$cmsg[27].$cmsg[28].$cmsg[29]);
|
||||
$rain *= $rainc;
|
||||
$rain /= 1000;
|
||||
$rain = sprintf("%.1f",$rain);
|
||||
for(my $s=0;$s<9;$s++)
|
||||
{
|
||||
if((ord($c[$s+1])&0x10))
|
||||
{
|
||||
my $p=($s*6)+$offs;
|
||||
Log $ll,"Sensor $s vorhanden";
|
||||
if(!defined($defptr{$s}))
|
||||
{
|
||||
Log(3,"WS300 $s: undefined");
|
||||
}
|
||||
else
|
||||
{
|
||||
$def = $defptr{$s};
|
||||
$def->{READINGS}{$txt[0]}{VAL} = 0 if(!$def->{READINGS});
|
||||
$ref = $def->{READINGS};
|
||||
|
||||
$t = hex($a[$p].$a[$p+1].$a[$p+2].$a[$p+3]);
|
||||
$t -= 65535 if( $t > 32767 );
|
||||
$t /= 10.0;
|
||||
$h = hex($a[$p+4].$a[$p+5]);
|
||||
if((ord($c[$s+1])&0xe0))
|
||||
{
|
||||
$b = "Empty"
|
||||
}
|
||||
else
|
||||
{
|
||||
$b = "Ok"
|
||||
}
|
||||
$l = (ord($c[$s+1])&0x0f);
|
||||
if($s < 8)
|
||||
{
|
||||
# state
|
||||
$val = "T: $t H: $h Bat: $b LR: $l";
|
||||
$def->{STATE} = $val;
|
||||
$def->{CHANGED}[0] = $val;
|
||||
$def->{CHANGETIME}[0] = $tm;
|
||||
# temperatur
|
||||
$ref->{$txt[0]}{TIME} = $tm;
|
||||
$value = "$t $sfx[0]";
|
||||
$ref->{$txt[0]}{VAL} = $value;
|
||||
$def->{CHANGED}[1] = "$txt[0]: $value";
|
||||
$def->{CHANGETIME}[1] = $tm;
|
||||
# humidity
|
||||
$ref->{$txt[1]}{TIME} = $tm;
|
||||
$value = "$h $sfx[1]";
|
||||
$ref->{$txt[1]}{VAL} = $value;
|
||||
$def->{CHANGED}[2] = "$txt[1]: $value";
|
||||
$def->{CHANGETIME}[2] = $tm;
|
||||
# battery
|
||||
$ref->{$txt[5]}{TIME} = $tm;
|
||||
$value = "$b $sfx[5]";
|
||||
$ref->{$txt[5]}{VAL} = $value;
|
||||
$def->{CHANGED}[3] = "$txt[5]: $value";
|
||||
$def->{CHANGETIME}[3] = $tm;
|
||||
# lost receives
|
||||
$ref->{$txt[6]}{TIME} = $tm;
|
||||
$value = "$l $sfx[6]";
|
||||
$ref->{$txt[6]}{VAL} = $value;
|
||||
$def->{CHANGED}[4] = "$txt[6]: $value";
|
||||
$def->{CHANGETIME}[4] = $tm;
|
||||
|
||||
Log $ll,"WS300 $def->{NAME}: $val";
|
||||
DoTrigger($def->{NAME},undef);
|
||||
}
|
||||
else
|
||||
{
|
||||
# state
|
||||
$val = "T: $t H: $h W: $wind R: $rain IR: $ir Bat: $b LR: $l";
|
||||
$def->{STATE} = $val;
|
||||
$def->{CHANGED}[0] = $val;
|
||||
$def->{CHANGETIME}[0] = $tm;
|
||||
# temperature
|
||||
$ref->{$txt[0]}{TIME} = $tm;
|
||||
$value = "$t $sfx[0]";
|
||||
$ref->{$txt[0]}{VAL} = $value;
|
||||
$def->{CHANGED}[1] = "$txt[0]: $value";
|
||||
$def->{CHANGETIME}[1] = $tm;
|
||||
# humidity
|
||||
$ref->{$txt[1]}{TIME} = $tm;
|
||||
$value = "$h $sfx[1]";
|
||||
$ref->{$txt[1]}{VAL} = $value;
|
||||
$def->{CHANGED}[2] = "$txt[1]: $value";
|
||||
$def->{CHANGETIME}[2] = $tm;
|
||||
# wind
|
||||
$ref->{$txt[2]}{TIME} = $tm;
|
||||
$value = "$wind $sfx[2]";
|
||||
$ref->{$txt[2]}{VAL} = $value;
|
||||
$def->{CHANGED}[3] = "$txt[2]: $value";
|
||||
$def->{CHANGETIME}[3] = $tm;
|
||||
#rain counter
|
||||
$ref->{$txt[3]}{TIME} = $tm;
|
||||
$value = "$rainc $sfx[3]";
|
||||
$ref->{$txt[3]}{VAL} = $value;
|
||||
$def->{CHANGED}[4] = "$txt[3]: $value";
|
||||
$def->{CHANGETIME}[4] = $tm;
|
||||
# is raining
|
||||
$ref->{$txt[4]}{TIME} = $tm;
|
||||
$value = "$ir $sfx[4]";
|
||||
$ref->{$txt[4]}{VAL} = $value;
|
||||
$def->{CHANGED}[5] = "$txt[4]: $value";
|
||||
$def->{CHANGETIME}[5] = $tm;
|
||||
# battery
|
||||
$ref->{$txt[5]}{TIME} = $tm;
|
||||
$value = "$b $sfx[5]";
|
||||
$ref->{$txt[5]}{VAL} = $value;
|
||||
$def->{CHANGED}[6] = "$txt[5]: $value";
|
||||
$def->{CHANGETIME}[6] = $tm;
|
||||
# lost receives
|
||||
$ref->{$txt[6]}{TIME} = $tm;
|
||||
$value = "$l $sfx[6]";
|
||||
$ref->{$txt[6]}{VAL} = $value;
|
||||
$def->{CHANGED}[7] = "$txt[6]: $value";
|
||||
$def->{CHANGETIME}[7] = $tm;
|
||||
# rain cumulative
|
||||
$ref->{$txt[8]}{TIME} = $tm;
|
||||
$value = "$rain $sfx[8]";
|
||||
$ref->{$txt[8]}{VAL} = $value;
|
||||
$def->{CHANGED}[8] = "$txt[8]: $value";
|
||||
$def->{CHANGETIME}[8] = $tm;
|
||||
# statistics
|
||||
if($actday == 99)
|
||||
{
|
||||
$oldrain = $rain;
|
||||
$acthour = $ref->{acthour}{VAL} if(defined($ref->{acthour}{VAL}));
|
||||
$actday = $ref->{actday}{VAL} if(defined($ref->{actday}{VAL}));
|
||||
$actmonth = $ref->{actmonth}{VAL} if(defined($ref->{actmonth}{VAL}));
|
||||
$rain_day = $ref->{rain_day}{VAL} if(defined($ref->{rain_day}{VAL}));
|
||||
$rain_month = $ref->{rain_month}{VAL} if(defined($ref->{rain_month}{VAL}));
|
||||
$rain_hour = $ref->{rain_hour}{VAL} if(defined($ref->{rain_hour}{VAL}));
|
||||
}
|
||||
if($acthour != $lt[2])
|
||||
{
|
||||
$acthour = $lt[2];
|
||||
$rain_hour = sprintf("%.1f",$rain_hour);
|
||||
$rain_day = sprintf("%.1f",$rain_day);
|
||||
$rain_month = sprintf("%.1f",$rain_month);
|
||||
$ref->{acthour}{TIME} = $tm;
|
||||
$ref->{acthour}{VAL} = "$acthour";
|
||||
$ref->{$txt[9]}{TIME} = $tm;
|
||||
$ref->{$txt[9]}{VAL} = $rain_hour;
|
||||
$def->{CHANGED}[9] = "$txt[9]: $rain_hour $sfx[9]";
|
||||
$def->{CHANGETIME}[9] = $tm;
|
||||
$ref->{$txt[10]}{TIME} = $tm;
|
||||
$ref->{$txt[10]}{VAL} = $rain_day;
|
||||
$def->{CHANGED}[10] = "$txt[10]: $rain_day $sfx[10]";
|
||||
$def->{CHANGETIME}[10] = $tm;
|
||||
$ref->{$txt[11]}{TIME} = $tm;
|
||||
$ref->{$txt[11]}{VAL} = $rain_month;
|
||||
$def->{CHANGED}[11] = "$txt[11]: $rain_month $sfx[11]";
|
||||
$def->{CHANGETIME}[11] = $tm;
|
||||
$rain_hour=0;
|
||||
}
|
||||
if($actday != $lt[3])
|
||||
{
|
||||
$actday = $lt[3];
|
||||
$ref->{actday}{TIME} = $tm;
|
||||
$ref->{actday}{VAL} = "$actday";
|
||||
$rain_day=0;
|
||||
}
|
||||
if($actmonth != $lt[4]+1)
|
||||
{
|
||||
$actmonth = $lt[4]+1;
|
||||
$ref->{actmonth}{TIME} = $tm;
|
||||
$ref->{actmonth}{VAL} = "$actmonth";
|
||||
$rain_month=0;
|
||||
}
|
||||
if($rain != $oldrain)
|
||||
{
|
||||
$rain_hour += ($rain-$oldrain);
|
||||
$rain_hour = sprintf("%.1f",$rain_hour);
|
||||
$rain_day += ($rain-$oldrain);
|
||||
$rain_day = sprintf("%.1f",$rain_day);
|
||||
$rain_month += ($rain-$oldrain);
|
||||
$rain_month = sprintf("%.1f",$rain_month);
|
||||
$oldrain = $rain;
|
||||
|
||||
$ref->{acthour}{TIME} = $tm;
|
||||
$ref->{acthour}{VAL} = "$acthour";
|
||||
$ref->{$txt[9]}{TIME} = $tm;
|
||||
$ref->{$txt[9]}{VAL} = $rain_hour;
|
||||
$def->{CHANGED}[9] = "$txt[9]: $rain_hour $sfx[9]";
|
||||
$def->{CHANGETIME}[9] = $tm;
|
||||
$ref->{$txt[10]}{TIME} = $tm;
|
||||
$ref->{$txt[10]}{VAL} = $rain_day;
|
||||
$def->{CHANGED}[10] = "$txt[10]: $rain_day $sfx[10]";
|
||||
$def->{CHANGETIME}[10] = $tm;
|
||||
$ref->{$txt[11]}{TIME} = $tm;
|
||||
$ref->{$txt[11]}{VAL} = $rain_month;
|
||||
$def->{CHANGED}[11] = "$txt[11]: $rain_month $sfx[11]";
|
||||
$def->{CHANGETIME}[11] = $tm;
|
||||
}
|
||||
Log $ll,"WS300 $def->{NAME}: $val";
|
||||
DoTrigger($def->{NAME},undef);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if(!defined($defptr{9}))
|
||||
{
|
||||
Log(3,"WS300 9: undefined");
|
||||
}
|
||||
else
|
||||
{
|
||||
$def = $defptr{9};
|
||||
$def->{READINGS}{$txt[0]}{VAL} = 0 if(!$def->{READINGS});
|
||||
$ref = $def->{READINGS};
|
||||
|
||||
$t = hex($a[62+$offs].$a[63+$offs].$a[64+$offs].$a[65+$offs]);
|
||||
$t -= 65535 if( $t > 32767 );
|
||||
$t /= 10.0;
|
||||
$h = hex($a[66+$offs].$a[67+$offs]);
|
||||
# state
|
||||
$val = "T: $t H: $h P: $press Willi: $willi";
|
||||
$def->{STATE} = $val;
|
||||
$def->{CHANGED}[0] = $val;
|
||||
$def->{CHANGETIME}[0] = $tm;
|
||||
# temperature
|
||||
$ref->{$txt[0]}{TIME} = $tm;
|
||||
$value = "$t $sfx[0]";
|
||||
$ref->{$txt[0]}{VAL} = $value;
|
||||
$def->{CHANGED}[1] = "$txt[0]: $value";
|
||||
$def->{CHANGETIME}[1] = $tm;
|
||||
# humidity
|
||||
$ref->{$txt[1]}{TIME} = $tm;
|
||||
$value = "$h $sfx[1]";
|
||||
$ref->{$txt[1]}{VAL} = $value;
|
||||
$def->{CHANGED}[2] = "$txt[1]: $value";
|
||||
$def->{CHANGETIME}[2] = $tm;
|
||||
# pressure
|
||||
$ref->{$txt[7]}{TIME} = $tm;
|
||||
$value = "$press $sfx[7]";
|
||||
$ref->{$txt[7]}{VAL} = $value;
|
||||
$def->{CHANGED}[3] = "$txt[7]: $value";
|
||||
$def->{CHANGETIME}[3] = $tm;
|
||||
# willi
|
||||
$ref->{willi}{TIME} = $tm;
|
||||
$value = "$willi";
|
||||
$ref->{willi}{VAL} = $value;
|
||||
$def->{CHANGED}[4] = "willi: $value";
|
||||
$def->{CHANGETIME}[4] = $tm;
|
||||
|
||||
Log $ll,"WS300 $def->{NAME}: $val";
|
||||
DoTrigger($def->{NAME},undef);
|
||||
}
|
||||
return undef;
|
||||
}
|
||||
|
||||
#####################################
|
||||
sub
|
||||
WS300_Read($)
|
||||
{
|
||||
my ($hash) = @_;
|
||||
}
|
||||
#####################################
|
||||
sub
|
||||
WS300_Write($$$)
|
||||
{
|
||||
my ($hash,$fn,$msg) = @_;
|
||||
}
|
||||
|
||||
#####################################
|
||||
sub
|
||||
WS300_Poll($)
|
||||
{
|
||||
my $hash = shift;
|
||||
my $bstring=" ";
|
||||
my $count;
|
||||
my $po;
|
||||
my $inchar='';
|
||||
my $escape=0;
|
||||
my $ll = GetLogLevel("WS300Device");
|
||||
$ll = 5 if($ll == 2);
|
||||
|
||||
if(!$hash || !defined($hash->{PortObj}))
|
||||
{
|
||||
return;
|
||||
}
|
||||
return if($polling);
|
||||
$polling=1;
|
||||
NEXTPOLL:
|
||||
$inbuf = $hash->{PortObj}->input();
|
||||
$bstring = sprintf("%c%c%c",0xfe,$cmd,0xfc);
|
||||
|
||||
my $ret = $hash->{PortObj}->write($bstring);
|
||||
if($ret <= 0)
|
||||
{
|
||||
|
||||
my $devname = $hash->{DeviceName};
|
||||
Log 1, "USB device $devname disconnected, waiting to reappear";
|
||||
$hash->{PortObj}->close();
|
||||
$hash->{STATE} = "disconnected";
|
||||
$hash->{READINGS}{WS300Device}{VAL} = "disconnected";
|
||||
$hash->{READINGS}{WS300Device}{TIME} = TimeNow;
|
||||
sleep(1);
|
||||
if ($^O=~/Win/) {
|
||||
$po = new Win32::SerialPort ($devname);
|
||||
}else{
|
||||
$po = new Device::SerialPort ($devname);
|
||||
}
|
||||
if($po)
|
||||
{
|
||||
$po->reset_error();
|
||||
$po->baudrate(19200);
|
||||
$po->databits(8);
|
||||
$po->parity('even');
|
||||
$po->stopbits(1);
|
||||
$po->handshake('none');
|
||||
$po->rts_active(1);
|
||||
$po->dtr_active(1);
|
||||
sleep(1);
|
||||
$po->rts_active(0);
|
||||
$po->write_settings;
|
||||
Log 1, "USB device $devname reappeared";
|
||||
$hash->{PortObj} = $po;
|
||||
$hash->{STATE} = "opened";
|
||||
$hash->{READINGS}{WS300Device}{VAL} = "opened";
|
||||
$hash->{READINGS}{WS300Device}{TIME} = TimeNow;
|
||||
$polling=0;
|
||||
return;
|
||||
}
|
||||
}
|
||||
$inbuf = "";
|
||||
my $start=0;
|
||||
my $tout=time();
|
||||
my $rcount=0;
|
||||
my $ic=0;
|
||||
|
||||
for(;;)
|
||||
{
|
||||
($count,$inchar) = $hash->{PortObj}->read(1);
|
||||
if($count == 0)
|
||||
{
|
||||
last if($tout < time());
|
||||
}
|
||||
else
|
||||
{
|
||||
$ic = hex(unpack('H*',$inchar));
|
||||
if(!$start)
|
||||
{
|
||||
if($ic == 0xfe)
|
||||
{
|
||||
$start = 1;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if($ic == 0xf8)
|
||||
{
|
||||
$escape = 1;
|
||||
$count = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
if($escape)
|
||||
{
|
||||
$ic--;
|
||||
$inbuf .= chr($ic);
|
||||
$escape = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
$inbuf .= $inchar;
|
||||
last if($ic == 0xfc);
|
||||
}
|
||||
}
|
||||
}
|
||||
$rcount += $count;
|
||||
$tout=time();
|
||||
}
|
||||
}
|
||||
|
||||
Log($ll,"WS300/RAW: ".$rcount." ".unpack('H*',$inbuf));
|
||||
if($ic != 0xfc)
|
||||
{
|
||||
$errcount++ if($errcount < 10);
|
||||
if($errcount == 10)
|
||||
{
|
||||
$hash->{STATE} = "timeout";
|
||||
$hash->{READINGS}{WS300Device}{VAL} = "timeout";
|
||||
$hash->{READINGS}{WS300Device}{TIME} = TimeNow;
|
||||
$errcount++;
|
||||
}
|
||||
Log 1,"WS300: no data" if($rcount == 0);
|
||||
Log 1,"WS300: wrong data ".unpack('H*',$inbuf) if($rcount > 0);
|
||||
$polling=0;
|
||||
return;
|
||||
}
|
||||
if($hash->{STATE} ne "connected" && $errcount > 10)
|
||||
{
|
||||
$hash->{STATE} = "connected";
|
||||
$hash->{READINGS}{WS300Device}{VAL} = "connected";
|
||||
$hash->{READINGS}{WS300Device}{TIME} = TimeNow;
|
||||
}
|
||||
$errcount = 0;
|
||||
$ic = ord(substr($inbuf,0,1));
|
||||
if($ic == 0x32)
|
||||
{
|
||||
$config = $inbuf if($rcount == 16);
|
||||
$cmd=0x31;
|
||||
goto NEXTPOLL;
|
||||
}
|
||||
if($ic == 0x31)
|
||||
{
|
||||
if($rcount == 42)
|
||||
{
|
||||
WS300_Parse($hash, $inbuf);
|
||||
goto NEXTPOLL;
|
||||
}
|
||||
else
|
||||
{
|
||||
$cmd=0x33;
|
||||
goto NEXTPOLL;
|
||||
}
|
||||
}
|
||||
if($ic == 0x33)
|
||||
{
|
||||
WS300_Parse($hash, $inbuf) if($rcount == 39);
|
||||
$cmd=0x32;
|
||||
}
|
||||
$polling=0;
|
||||
}
|
||||
|
||||
1;
|
|
@ -1,428 +0,0 @@
|
|||
##############################################
|
||||
package main;
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
|
||||
sub EM_Write($$);
|
||||
sub EmCrc($$);
|
||||
sub EmCrcCheck($$);
|
||||
sub EmEsc($);
|
||||
sub EmGetData($$);
|
||||
sub EmMakeMsg($);
|
||||
sub EM_Set($@);
|
||||
|
||||
# Following one-byte commands are trange, as they cause a timeout:
|
||||
# 124 127 150 153 155 156
|
||||
|
||||
|
||||
#####################################
|
||||
sub
|
||||
EM_Initialize($)
|
||||
{
|
||||
my ($hash) = @_;
|
||||
|
||||
|
||||
# Provider
|
||||
$hash->{WriteFn} = "EM_Write";
|
||||
$hash->{Clients} = ":EMWZ:EMEM:EMGZ:";
|
||||
|
||||
# Consumer
|
||||
$hash->{DefFn} = "EM_Define";
|
||||
$hash->{UndefFn} = "EM_Undef";
|
||||
$hash->{GetFn} = "EM_Get";
|
||||
$hash->{SetFn} = "EM_Set";
|
||||
$hash->{AttrList}= "model:em1010pc dummy:1,0 loglevel:0,1,2,3,4,5,6";
|
||||
}
|
||||
|
||||
#####################################
|
||||
sub
|
||||
EM_Define($$)
|
||||
{
|
||||
my ($hash, $def) = @_;
|
||||
my @a = split("[ \t][ \t]*", $def);
|
||||
my $po;
|
||||
$hash->{STATE} = "Initialized";
|
||||
|
||||
delete $hash->{PortObj};
|
||||
delete $hash->{FD};
|
||||
|
||||
my $name = $a[0];
|
||||
my $dev = $a[2];
|
||||
|
||||
$attr{$name}{savefirst} = 1;
|
||||
|
||||
if($dev eq "none") {
|
||||
Log 1, "EM device is none, commands will be echoed only";
|
||||
$attr{$name}{dummy} = 1;
|
||||
return undef;
|
||||
}
|
||||
|
||||
Log 3, "EM opening device $dev";
|
||||
if ( $^O =~ /Win/) {
|
||||
eval ("use Win32::SerialPort;");
|
||||
$po = new Win32::SerialPort ($dev);
|
||||
}else{
|
||||
eval ("use Device::SerialPort;");
|
||||
$po = new Device::SerialPort ($dev);
|
||||
}
|
||||
|
||||
return "Can't open $dev: $!" if(!$po);
|
||||
Log 3, "EM opened device $dev";
|
||||
$po->close();
|
||||
|
||||
$hash->{DeviceName} = $dev;
|
||||
return undef;
|
||||
}
|
||||
|
||||
#####################################
|
||||
sub
|
||||
EM_Undef($$)
|
||||
{
|
||||
my ($hash, $arg) = @_;
|
||||
my $name = $hash->{NAME};
|
||||
|
||||
foreach my $d (sort keys %defs) {
|
||||
if(defined($defs{$d}) &&
|
||||
defined($defs{$d}{IODev}) &&
|
||||
$defs{$d}{IODev} == $hash)
|
||||
{
|
||||
Log GetLogLevel($name,2), "deleting port for $d";
|
||||
delete $defs{$d}{IODev};
|
||||
}
|
||||
}
|
||||
return undef;
|
||||
}
|
||||
|
||||
|
||||
#####################################
|
||||
sub
|
||||
EM_Set($@)
|
||||
{
|
||||
my ($hash, @a) = @_;
|
||||
my $u1 = "Usage: set <name> reset\n" .
|
||||
" set <name> time [YYYY-MM-DD HH:MM:SS]";
|
||||
|
||||
return $u1 if(int(@a) < 2);
|
||||
my $name = $hash->{DeviceName};
|
||||
|
||||
if($a[1] eq "time") {
|
||||
|
||||
if (int(@a) == 2) {
|
||||
my @lt = localtime;
|
||||
$a[2] = sprintf ("%04d-%02d-%02d", $lt[5]+1900, $lt[4]+1, $lt[3]);
|
||||
$a[3] = sprintf ("%02d:%02d:%02d", $lt[2], $lt[1], $lt[0]);
|
||||
} elsif (int(@a) != 4) {
|
||||
return $u1;
|
||||
}
|
||||
my @d = split("-", $a[2]);
|
||||
my @t = split(":", $a[3]);
|
||||
my $msg = sprintf("73%02x%02x%02x00%02x%02x%02x",
|
||||
$d[2],$d[1],$d[0]-2000+0xd0, $t[0],$t[1],$t[2]);
|
||||
my $d = EmGetData($name, $msg);
|
||||
return "Read error" if(!defined($d));
|
||||
return b($d,0);
|
||||
|
||||
} elsif($a[1] eq "reset") {
|
||||
|
||||
my $d = EmGetData($name, "4545"); # Reset
|
||||
return "Read error" if(!defined($d));
|
||||
sleep(10);
|
||||
EM_Set($hash, ($a[0], "time")); # Set the time
|
||||
sleep(1);
|
||||
$d = EmGetData($name, "67"); # "Push the button", we don't want usesr interaction
|
||||
return "Read error" if(!defined($d));
|
||||
|
||||
} else {
|
||||
|
||||
return "Unknown argument $a[1], choose one of reset,time"
|
||||
|
||||
}
|
||||
return undef;
|
||||
|
||||
}
|
||||
|
||||
#########################
|
||||
sub
|
||||
b($$)
|
||||
{
|
||||
my ($t,$p) = @_;
|
||||
return -1 if(!defined($t) || length($t) < $p);
|
||||
return ord(substr($t,$p,1));
|
||||
}
|
||||
|
||||
sub
|
||||
w($$)
|
||||
{
|
||||
my ($t,$p) = @_;
|
||||
return b($t,$p+1)*256 + b($t,$p);
|
||||
}
|
||||
|
||||
sub
|
||||
dw($$)
|
||||
{
|
||||
my ($t,$p) = @_;
|
||||
return w($t,$p+2)*65536 + w($t,$p);
|
||||
}
|
||||
|
||||
#####################################
|
||||
sub
|
||||
EM_Get($@)
|
||||
{
|
||||
my ($hash, @a) = @_;
|
||||
|
||||
return "\"get EM\" needs only one parameter" if(@a != 2);
|
||||
|
||||
my $v;
|
||||
if($a[1] eq "time") {
|
||||
|
||||
my $d = EmGetData($hash->{DeviceName}, "74");
|
||||
return "Read error" if(!defined($d));
|
||||
|
||||
$v = sprintf "%4d-%02d-%02d %02d:%02d:%02d",
|
||||
b($d,5)+2006, b($d,4), b($d,3),
|
||||
b($d,0), b($d,1), b($d,2);
|
||||
|
||||
} elsif($a[1] eq "version") {
|
||||
|
||||
my $d = EmGetData($hash->{DeviceName},"76");
|
||||
return "Read error" if(!defined($d));
|
||||
$v = sprintf "%d.%d", b($d,0), b($d,1);
|
||||
|
||||
} else {
|
||||
return "Unknown argument $a[1], choose one of time,version";
|
||||
}
|
||||
|
||||
$hash->{READINGS}{$a[1]}{VAL} = $v;
|
||||
$hash->{READINGS}{$a[1]}{TIME} = TimeNow();
|
||||
|
||||
return "$a[0] $a[1] => $v";
|
||||
}
|
||||
|
||||
#####################################
|
||||
sub
|
||||
EM_Write($$)
|
||||
{
|
||||
my ($hash,$msg) = @_;
|
||||
|
||||
return EmGetData($hash->{DeviceName}, $msg);
|
||||
}
|
||||
|
||||
#####################################
|
||||
sub
|
||||
EmCrc($$)
|
||||
{
|
||||
my ($in, $val) = @_;
|
||||
my ($crc, $bits) = (0, 8);
|
||||
my $k = (($in >> 8) ^ $val) << 8;
|
||||
while($bits--) {
|
||||
if(($crc ^ $k) & 0x8000) {
|
||||
$crc = ($crc << 1) ^ 0x8005;
|
||||
} else {
|
||||
$crc <<= 1;
|
||||
}
|
||||
$k <<= 1;
|
||||
}
|
||||
return (($in << 8) ^ $crc) & 0xffff;
|
||||
}
|
||||
|
||||
#########################
|
||||
sub
|
||||
EmEsc($)
|
||||
{
|
||||
my ($b) = @_;
|
||||
|
||||
my $out = "";
|
||||
$out .= chr(0x10) if($b==0x02 || $b==0x03 || $b==0x10);
|
||||
$out .= chr($b);
|
||||
}
|
||||
|
||||
|
||||
#####################################
|
||||
sub
|
||||
EmCrcCheck($$)
|
||||
{
|
||||
my ($otxt, $len) = @_;
|
||||
my $crc = 0x8c27;
|
||||
for(my $l = 2; $l < $len+4; $l++) {
|
||||
my $b = ord(substr($otxt,$l,1));
|
||||
$crc = EmCrc($crc, 0x10) if($b==0x02 || $b==0x03 || $b==0x10);
|
||||
$crc = EmCrc($crc, $b);
|
||||
}
|
||||
return ($crc == w($otxt, $len+4));
|
||||
}
|
||||
|
||||
#########################
|
||||
sub
|
||||
EmMakeMsg($)
|
||||
{
|
||||
my ($data) = @_;
|
||||
my $len = length($data);
|
||||
$data = chr($len&0xff) . chr(int($len/256)) . $data;
|
||||
|
||||
my $out = pack('H*', "0200");
|
||||
my $crc = 0x8c27;
|
||||
for(my $l = 0; $l < $len+2; $l++) {
|
||||
my $b = ord(substr($data,$l,1));
|
||||
$crc = EmCrc($crc, 0x10) if($b==0x02 || $b==0x03 || $b==0x10);
|
||||
$crc = EmCrc($crc, $b);
|
||||
$out .= EmEsc($b);
|
||||
}
|
||||
$out .= EmEsc($crc&0xff);
|
||||
$out .= EmEsc($crc/256);
|
||||
$out .= chr(0x03);
|
||||
return $out;
|
||||
}
|
||||
|
||||
#####################################
|
||||
# This is the only
|
||||
sub
|
||||
EmGetData($$)
|
||||
{
|
||||
my ($dev, $d) = @_;
|
||||
$d = EmMakeMsg(pack('H*', $d));
|
||||
my $serport;
|
||||
my $rm;
|
||||
return undef if(!$dev);
|
||||
#OS depends
|
||||
if ($^O=~/Win/) {
|
||||
$serport = new Win32::SerialPort ($dev);
|
||||
}else{
|
||||
$serport = new Device::SerialPort ($dev);
|
||||
}
|
||||
|
||||
if(!$serport) {
|
||||
Log 1, "EM: Can't open $dev: $!";
|
||||
return undef;
|
||||
}
|
||||
$serport->reset_error();
|
||||
$serport->baudrate(38400);
|
||||
$serport->databits(8);
|
||||
$serport->parity('none');
|
||||
$serport->stopbits(1);
|
||||
$serport->handshake('none');
|
||||
if ( $^O =~ /Win/ ) {
|
||||
unless ($serport->write_settings) {
|
||||
$rm= "EM:Can't change Device_Control_Block: $^E\n";
|
||||
goto DONE;
|
||||
}
|
||||
}
|
||||
Log 4, "EM: Sending " . unpack('H*', $d);
|
||||
|
||||
$rm = "EM: timeout reading the answer";
|
||||
for(my $rep = 0; $rep < 3; $rep++) {
|
||||
|
||||
$serport->write($d);
|
||||
|
||||
|
||||
my $retval = "";
|
||||
my $esc = 0;
|
||||
my $started = 0;
|
||||
my $complete = 0;
|
||||
my $buf;
|
||||
my $i;
|
||||
my $b;
|
||||
for(;;) {
|
||||
|
||||
if($^O =~ /Win/) {
|
||||
#select will not work on windows, replaced with status
|
||||
my ($BlockingFlags, $InBytes, $OutBytes, $ErrorFlags)=(0,0,0,0);
|
||||
for ($i=0;$i<9; $i++) {
|
||||
sleep(1); #waiiiit
|
||||
($BlockingFlags, $InBytes, $OutBytes, $ErrorFlags)=$serport->status;
|
||||
last if $InBytes>0;
|
||||
}
|
||||
Log 5,"EM: read returned $InBytes Bytes($i trys)";
|
||||
last if ($InBytes<1);
|
||||
$buf = $serport->input();
|
||||
|
||||
} else {
|
||||
my ($rout, $rin) = ('', '');
|
||||
vec($rin, $serport->FILENO, 1) = 1;
|
||||
my $nfound = select($rout=$rin, undef, undef, 1.0);
|
||||
|
||||
if($nfound < 0) {
|
||||
$rm = "EM Select error $nfound / $!";
|
||||
goto DONE;
|
||||
}
|
||||
last if($nfound == 0);
|
||||
$buf = $serport->input();
|
||||
}
|
||||
|
||||
|
||||
if(!defined($buf) || length($buf) == 0) {
|
||||
$rm = "EM EOF on $dev";
|
||||
goto DONE;
|
||||
}
|
||||
|
||||
for($i = 0; $i < length($buf); $i++) {
|
||||
$b = ord(substr($buf,$i,1));
|
||||
|
||||
if(!$started && $b != 0x02) { next; }
|
||||
$started = 1;
|
||||
if($esc) { $retval .= chr($b); $esc = 0; next; }
|
||||
if($b == 0x10) { $esc = 1; next; }
|
||||
$retval .= chr($b);
|
||||
if($b == 0x03) { $complete = 1; last; }
|
||||
}
|
||||
|
||||
if($complete) {
|
||||
my $l = length($retval);
|
||||
if($l < 8) { $rm = "EM Msg too short"; goto DONE; }
|
||||
if(b($retval,1) != 0) { $rm = "EM Bad second byte"; goto DONE; }
|
||||
if(w($retval,2) != $l-7) { $rm = "EM Length mismatch"; goto DONE; }
|
||||
if(!EmCrcCheck($retval,$l-7)) { $rm = "EM Bad CRC"; goto DONE; }
|
||||
$serport->close();
|
||||
my $data=substr($retval, 4, $l-7);
|
||||
Log 5,"EM: returned ".unpack("H*",$data);
|
||||
return $data;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
DONE:
|
||||
Log 5,$rm;
|
||||
$serport->close();
|
||||
return undef;
|
||||
}
|
||||
|
||||
|
||||
#########################
|
||||
# Interpretation is left for the "user";
|
||||
sub
|
||||
EmGetDevData($)
|
||||
{
|
||||
my ($hash) = @_;
|
||||
|
||||
my $dnr = $hash->{DEVNR};
|
||||
my $d = IOWrite($hash, sprintf("7a%02x", $dnr-1));
|
||||
|
||||
return("ERROR: No device no. $dnr present")
|
||||
if($d eq ((pack('H*',"00") x 45) . pack('H*',"FF") x 6));
|
||||
|
||||
my $nrreadings = w($d,2);
|
||||
return("ERROR: No data to read (yet?)")
|
||||
if($nrreadings == 0);
|
||||
|
||||
my $step = b($d,6);
|
||||
my $start = b($d,18)+13;
|
||||
my $end = $start + int(($nrreadings-1)/64)*$step;
|
||||
|
||||
my @ret;
|
||||
my $max;
|
||||
my $off;
|
||||
for(my $p = $start; $p <= $end; $p += $step) { # blockwise
|
||||
$d = IOWrite($hash, sprintf("52%02x%02x00000801", $p%256, int($p/256)));
|
||||
$max = (($p == $end) ? ($nrreadings%64)*4+4 : 260);
|
||||
$step = b($d, 6);
|
||||
|
||||
for($off = 8; $off <= $max; $off += 4) { # Samples in each block
|
||||
push(@ret, sprintf("%04x%04x\n", w($d,$off), w($d,$off+2)));
|
||||
}
|
||||
}
|
||||
return @ret;
|
||||
}
|
||||
|
||||
|
||||
1;
|
|
@ -1,182 +0,0 @@
|
|||
##############################################
|
||||
package main;
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
use Time::HiRes qw(gettimeofday);
|
||||
|
||||
sub EMWZ_Get($@);
|
||||
sub EMWZ_Set($@);
|
||||
sub EMWZ_Define($$);
|
||||
sub EMWZ_GetStatus($);
|
||||
|
||||
###################################
|
||||
sub
|
||||
EMWZ_Initialize($)
|
||||
{
|
||||
my ($hash) = @_;
|
||||
|
||||
$hash->{GetFn} = "EMWZ_Get";
|
||||
$hash->{SetFn} = "EMWZ_Set";
|
||||
$hash->{DefFn} = "EMWZ_Define";
|
||||
|
||||
$hash->{AttrList} = "dummy:1,0 model;EM1000WZ loglevel:0,1,2,3,4,5,6";
|
||||
}
|
||||
|
||||
|
||||
###################################
|
||||
sub
|
||||
EMWZ_GetStatus($)
|
||||
{
|
||||
my ($hash) = @_;
|
||||
|
||||
if(!$hash->{LOCAL}) {
|
||||
InternalTimer(gettimeofday()+300, "EMWZ_GetStatus", $hash, 0);
|
||||
}
|
||||
|
||||
my $dnr = $hash->{DEVNR};
|
||||
my $name = $hash->{NAME};
|
||||
|
||||
return "Empty status: dummy IO device" if(IsIoDummy($name));
|
||||
|
||||
my $d = IOWrite($hash, sprintf("7a%02x", $dnr-1));
|
||||
if(!defined($d)) {
|
||||
my $msg = "EMWZ $name read error (GetStatus 1)";
|
||||
Log GetLogLevel($name,2), $msg;
|
||||
return $msg;
|
||||
}
|
||||
|
||||
|
||||
if($d eq ((pack('H*',"00") x 45) . pack('H*',"FF") x 6)) {
|
||||
my $msg = "EMWZ no device no. $dnr present";
|
||||
Log GetLogLevel($name,2), $msg;
|
||||
return $msg;
|
||||
}
|
||||
|
||||
my $pulses=w($d,13);
|
||||
my $ec=w($d,49) / 10;
|
||||
if($ec <= 0) {
|
||||
my $msg = "EMWZ read error (GetStatus 2)";
|
||||
Log GetLogLevel($name,2), $msg;
|
||||
return $msg;
|
||||
}
|
||||
my $cur_energy = $pulses / $ec; # ec = U/kWh
|
||||
my $cur_power = $cur_energy / 5 * 60; # 5minute interval scaled to 1h
|
||||
|
||||
if($cur_power > 30) { # 20Amp x 3 Phase
|
||||
my $msg = "EMWZ Bogus reading: curr. power is reported to be $cur_power";
|
||||
Log GetLogLevel($name,2), $msg;
|
||||
return $msg;
|
||||
}
|
||||
|
||||
my %vals;
|
||||
$vals{"5min_pulses"} = $pulses;
|
||||
$vals{"energy"} = sprintf("%0.3f", $cur_energy);
|
||||
$vals{"power"} = sprintf("%.3f", $cur_power);
|
||||
$vals{"alarm_PA"} = w($d,45) . " Watt";
|
||||
$vals{"price_CF"} = sprintf("%.3f", w($d,47)/10000);
|
||||
$vals{"RperKW_EC"} = $ec;
|
||||
|
||||
my $tn = TimeNow();
|
||||
my $idx = 0;
|
||||
foreach my $k (keys %vals) {
|
||||
my $v = $vals{$k};
|
||||
$hash->{CHANGED}[$idx++] = "$k: $v";
|
||||
$hash->{READINGS}{$k}{TIME} = $tn;
|
||||
$hash->{READINGS}{$k}{VAL} = $v
|
||||
}
|
||||
|
||||
if(!$hash->{LOCAL}) {
|
||||
DoTrigger($name, undef) if($init_done);
|
||||
}
|
||||
|
||||
$hash->{STATE} = "$cur_power kW";
|
||||
Log GetLogLevel($name,4), "EMWZ $name: $cur_power kW / $vals{energy}";
|
||||
|
||||
return $hash->{STATE};
|
||||
}
|
||||
|
||||
###################################
|
||||
sub
|
||||
EMWZ_Get($@)
|
||||
{
|
||||
my ($hash, @a) = @_;
|
||||
|
||||
return "argument is missing" if(int(@a) != 2);
|
||||
|
||||
my $d = $hash->{DEVNR};
|
||||
my $msg;
|
||||
|
||||
if($a[1] ne "status") {
|
||||
return "unknown get value, valid is status";
|
||||
}
|
||||
$hash->{LOCAL} = 1;
|
||||
my $v = EMWZ_GetStatus($hash);
|
||||
delete $hash->{LOCAL};
|
||||
|
||||
return "$a[0] $a[1] => $v";
|
||||
}
|
||||
|
||||
sub
|
||||
EMWZ_Set($@)
|
||||
{
|
||||
my ($hash, @a) = @_;
|
||||
my $u = "Usage: set <name> <type> <value>, " .
|
||||
"<type> is one of price,alarm,rperkw";
|
||||
|
||||
return $u if(int(@a) != 3);
|
||||
|
||||
my $name = $hash->{NAME};
|
||||
return "" if(IsIoDummy($name));
|
||||
|
||||
my $v = $a[2];
|
||||
my $d = $hash->{DEVNR};
|
||||
my $msg;
|
||||
|
||||
if($a[1] eq "price") {
|
||||
$v *= 10000; # Make display and input the same
|
||||
$msg = sprintf("79%02x2f02%02x%02x", $d-1, $v%256, int($v/256));
|
||||
} elsif($a[1] eq "alarm") {
|
||||
$msg = sprintf("79%02x2d02%02x%02x", $d-1, $v%256, int($v/256));
|
||||
} elsif($a[1] eq "rperkw") {
|
||||
$v *= 10; # Make display and input the same
|
||||
$msg = sprintf("79%02x3102%02x%02x", $d-1, $v%256, int($v/256));
|
||||
} else {
|
||||
return $u;
|
||||
}
|
||||
|
||||
|
||||
my $ret = IOWrite($hash, $msg);
|
||||
if(!defined($ret)) {
|
||||
my $msg = "EMWZ $name read error (Set)";
|
||||
Log GetLogLevel($name,2), $msg;
|
||||
return $msg;
|
||||
}
|
||||
|
||||
if(ord(substr($ret,0,1)) != 6) {
|
||||
$ret = "EMWZ Error occured: " . unpack('H*', $ret);
|
||||
Log GetLogLevel($name,2), $ret;
|
||||
return $ret;
|
||||
}
|
||||
|
||||
return undef;
|
||||
}
|
||||
|
||||
#############################
|
||||
sub
|
||||
EMWZ_Define($$)
|
||||
{
|
||||
my ($hash, $def) = @_;
|
||||
my @a = split("[ \t][ \t]*", $def);
|
||||
|
||||
return "syntax: define <name> EMWZ devicenumber"
|
||||
if(@a != 3 || $a[2] !~ m,^[1-4]$,);
|
||||
$hash->{DEVNR} = $a[2];
|
||||
AssignIoPort($hash);
|
||||
|
||||
|
||||
EMWZ_GetStatus($hash);
|
||||
return undef;
|
||||
}
|
||||
|
||||
1;
|
|
@ -1,138 +0,0 @@
|
|||
##############################################
|
||||
package main;
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
use Time::HiRes qw(gettimeofday);
|
||||
|
||||
sub EMEM_Get($@);
|
||||
sub EMEM_Define($$);
|
||||
sub EMEM_GetStatus($);
|
||||
|
||||
###################################
|
||||
sub
|
||||
EMEM_Initialize($)
|
||||
{
|
||||
my ($hash) = @_;
|
||||
|
||||
$hash->{GetFn} = "EMEM_Get";
|
||||
$hash->{DefFn} = "EMEM_Define";
|
||||
|
||||
$hash->{AttrList} = "dummy:1,0 model;EM1000EM loglevel:0,1,2,3,4,5,6";
|
||||
}
|
||||
|
||||
###################################
|
||||
sub
|
||||
EMEM_GetStatus($)
|
||||
{
|
||||
my ($hash) = @_;
|
||||
|
||||
if(!$hash->{LOCAL}) {
|
||||
InternalTimer(gettimeofday()+300, "EMEM_GetStatus", $hash, 0);
|
||||
}
|
||||
|
||||
my $dnr = $hash->{DEVNR};
|
||||
my $name = $hash->{NAME};
|
||||
|
||||
return "Empty status: dummy IO device" if(IsIoDummy($name));
|
||||
|
||||
my $d = IOWrite($hash, sprintf("7a%02x", $dnr-1));
|
||||
if(!defined($d)) {
|
||||
my $msg = "EMEM $name read error (GetStatus 1)";
|
||||
Log GetLogLevel($name,2), $msg;
|
||||
return $msg;
|
||||
}
|
||||
|
||||
if($d eq ((pack('H*',"00") x 45) . pack('H*',"FF") x 6)) {
|
||||
my $msg = "EMEM no device no. $dnr present";
|
||||
Log GetLogLevel($name,2), $msg;
|
||||
return $msg;
|
||||
}
|
||||
|
||||
my $pulses=w($d,13);
|
||||
my $pulses_max= w($d,15);
|
||||
my $iec = 1000;
|
||||
my $cur_power = $pulses / 100;
|
||||
my $cur_power_max = $pulses_max / 100;
|
||||
|
||||
if($cur_power > 30) { # 20Amp x 3 Phase
|
||||
my $msg = "EMEM Bogus reading: curr. power is reported to be $cur_power, setting to -1";
|
||||
Log GetLogLevel($name,2), $msg;
|
||||
#return $msg;
|
||||
$cur_power = -1.0;
|
||||
}
|
||||
if($cur_power_max > 30) { # 20Amp x 3 Phase
|
||||
$cur_power_max = -1.0;
|
||||
}
|
||||
|
||||
my %vals;
|
||||
$vals{"5min_pulses"} = $pulses;
|
||||
$vals{"5min_pulses_max"} = $pulses_max;
|
||||
$vals{"energy_kWh_h"} = sprintf("%0.3f", dw($d,33) / $iec);
|
||||
$vals{"energy_kWh_d"} = sprintf("%0.3f", dw($d,37) / $iec);
|
||||
$vals{"energy_kWh_w"} = sprintf("%0.3f", dw($d,41) / $iec);
|
||||
$vals{"energy_kWh"} = sprintf("%0.3f", dw($d, 7) / $iec);
|
||||
$vals{"power_kW"} = sprintf("%.3f", $cur_power);
|
||||
$vals{"power_kW_max"} = sprintf("%.3f", $cur_power_max);
|
||||
$vals{"alarm_PA_W"} = w($d,45);
|
||||
$vals{"price_CF"} = sprintf("%.3f", w($d,47)/10000);
|
||||
|
||||
|
||||
my $tn = TimeNow();
|
||||
my $idx = 0;
|
||||
foreach my $k (keys %vals) {
|
||||
my $v = $vals{$k};
|
||||
$hash->{CHANGED}[$idx++] = "$k: $v";
|
||||
$hash->{READINGS}{$k}{TIME} = $tn;
|
||||
$hash->{READINGS}{$k}{VAL} = $v
|
||||
}
|
||||
|
||||
if(!$hash->{LOCAL}) {
|
||||
DoTrigger($name, undef) if($init_done);
|
||||
}
|
||||
|
||||
$hash->{STATE} = "$cur_power kW";
|
||||
Log GetLogLevel($name,4), "EMEM $name: $cur_power kW / $vals{energy_kWh} kWh";
|
||||
|
||||
return $hash->{STATE};
|
||||
}
|
||||
|
||||
###################################
|
||||
sub
|
||||
EMEM_Get($@)
|
||||
{
|
||||
my ($hash, @a) = @_;
|
||||
|
||||
return "argument is missing" if(int(@a) != 2);
|
||||
|
||||
my $d = $hash->{DEVNR};
|
||||
my $msg;
|
||||
|
||||
if($a[1] ne "status") {
|
||||
return "unknown get value, valid is status";
|
||||
}
|
||||
$hash->{LOCAL} = 1;
|
||||
my $v = EMEM_GetStatus($hash);
|
||||
delete $hash->{LOCAL};
|
||||
|
||||
return "$a[0] $a[1] => $v";
|
||||
}
|
||||
|
||||
#############################
|
||||
sub
|
||||
EMEM_Define($$)
|
||||
{
|
||||
my ($hash, $def) = @_;
|
||||
my @a = split("[ \t][ \t]*", $def);
|
||||
|
||||
return "syntax: define <name> EMEM devicenumber"
|
||||
if(@a != 3 || $a[2] !~ m,^[5-8]$,);
|
||||
$hash->{DEVNR} = $a[2];
|
||||
AssignIoPort($hash);
|
||||
|
||||
|
||||
EMEM_GetStatus($hash);
|
||||
return undef;
|
||||
}
|
||||
|
||||
1;
|
|
@ -1,185 +0,0 @@
|
|||
##############################################
|
||||
package main;
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
use Time::HiRes qw(gettimeofday);
|
||||
|
||||
sub EMGZ_Get($@);
|
||||
sub EMGZ_Set($@);
|
||||
sub EMGZ_Define($$);
|
||||
sub EMGZ_GetStatus($);
|
||||
|
||||
###################################
|
||||
sub
|
||||
EMGZ_Initialize($)
|
||||
{
|
||||
my ($hash) = @_;
|
||||
|
||||
$hash->{GetFn} = "EMGZ_Get";
|
||||
$hash->{SetFn} = "EMGZ_Set";
|
||||
$hash->{DefFn} = "EMGZ_Define";
|
||||
|
||||
$hash->{AttrList} = "dummy:1,0 model;EM1000GZ loglevel:0,1,2,3,4,5,6";
|
||||
}
|
||||
|
||||
|
||||
###################################
|
||||
sub
|
||||
EMGZ_GetStatus($)
|
||||
{
|
||||
my ($hash) = @_;
|
||||
|
||||
if(!$hash->{LOCAL}) {
|
||||
InternalTimer(gettimeofday()+300, "EMGZ_GetStatus", $hash, 0);
|
||||
}
|
||||
|
||||
my $dnr = $hash->{DEVNR};
|
||||
my $name = $hash->{NAME};
|
||||
|
||||
return "Empty status: dummy IO device" if(IsIoDummy($name));
|
||||
|
||||
my $d = IOWrite($hash, sprintf("7a%02x", $dnr-1));
|
||||
if(!defined($d)) {
|
||||
my $msg = "EMGZ $name read error (GetStatus 1)";
|
||||
Log GetLogLevel($name,2), $msg;
|
||||
return $msg;
|
||||
}
|
||||
|
||||
|
||||
if($d eq ((pack('H*',"00") x 45) . pack('H*',"FF") x 6)) {
|
||||
my $msg = "EMGZ no device no. $dnr present";
|
||||
Log GetLogLevel($name,2), $msg;
|
||||
return $msg;
|
||||
}
|
||||
|
||||
my $pulses=w($d,13);
|
||||
my $ec=w($d,49) / 10;
|
||||
if($ec < 0) { # war <=
|
||||
my $msg = "EMGZ read error (GetStatus 2)";
|
||||
Log GetLogLevel($name,2), $msg;
|
||||
return $msg;
|
||||
}
|
||||
|
||||
$ec = 100; # fixed value
|
||||
|
||||
my $cur_energy = $pulses / $ec; # ec = U/m^3
|
||||
my $cur_power = $cur_energy / 5 * 60; # 5minute interval scaled to 1h
|
||||
|
||||
if($cur_power > 30) { # depending on "Anschlussleistung"
|
||||
my $msg = "EMGZ Bogus reading: curr. power is reported to be $cur_power";
|
||||
Log GetLogLevel($name,2), $msg;
|
||||
return $msg;
|
||||
}
|
||||
|
||||
my %vals;
|
||||
$vals{"5min_pulses"} = $pulses;
|
||||
$vals{"act_flow_m3"} = sprintf("%0.3f", $cur_energy);
|
||||
$vals{"m3ph"} = sprintf("%.3f", $cur_power);
|
||||
$vals{"alarm_PA"} = w($d,45) . " Watt"; # nonsens
|
||||
$vals{"price_CF"} = sprintf("%.3f", w($d,47)/10000);
|
||||
$vals{"Rperm3_EC"} = $ec;
|
||||
|
||||
my $tn = TimeNow();
|
||||
my $idx = 0;
|
||||
foreach my $k (keys %vals) {
|
||||
my $v = $vals{$k};
|
||||
$hash->{CHANGED}[$idx++] = "$k: $v";
|
||||
$hash->{READINGS}{$k}{TIME} = $tn;
|
||||
$hash->{READINGS}{$k}{VAL} = $v
|
||||
}
|
||||
|
||||
if(!$hash->{LOCAL}) {
|
||||
DoTrigger($name, undef) if($init_done);
|
||||
}
|
||||
|
||||
$hash->{STATE} = "$cur_power m3ph";
|
||||
Log GetLogLevel($name,4), "EMGZ $name: $cur_power m3ph / $vals{act_flow_m3}";
|
||||
|
||||
return $hash->{STATE};
|
||||
}
|
||||
|
||||
###################################
|
||||
sub
|
||||
EMGZ_Get($@)
|
||||
{
|
||||
my ($hash, @a) = @_;
|
||||
|
||||
return "argument is missing" if(int(@a) != 2);
|
||||
|
||||
my $d = $hash->{DEVNR};
|
||||
my $msg;
|
||||
|
||||
if($a[1] ne "status") {
|
||||
return "unknown get value, valid is status";
|
||||
}
|
||||
$hash->{LOCAL} = 1;
|
||||
my $v = EMGZ_GetStatus($hash);
|
||||
delete $hash->{LOCAL};
|
||||
|
||||
return "$a[0] $a[1] => $v";
|
||||
}
|
||||
|
||||
sub
|
||||
EMGZ_Set($@)
|
||||
{
|
||||
my ($hash, @a) = @_;
|
||||
my $u = "Usage: set <name> <type> <value>, " .
|
||||
"<type> is one of price,alarm,rperkw";
|
||||
|
||||
return $u if(int(@a) != 3);
|
||||
|
||||
my $name = $hash->{NAME};
|
||||
return "" if(IsIoDummy($name));
|
||||
|
||||
my $v = $a[2];
|
||||
my $d = $hash->{DEVNR};
|
||||
my $msg;
|
||||
|
||||
if($a[1] eq "price") {
|
||||
$v *= 10000; # Make display and input the same
|
||||
$msg = sprintf("79%02x2f02%02x%02x", $d-1, $v%256, int($v/256));
|
||||
} elsif($a[1] eq "alarm") {
|
||||
$msg = sprintf("79%02x2d02%02x%02x", $d-1, $v%256, int($v/256));
|
||||
} elsif($a[1] eq "rperkw") {
|
||||
$v *= 10; # Make display and input the same
|
||||
$msg = sprintf("79%02x3102%02x%02x", $d-1, $v%256, int($v/256));
|
||||
} else {
|
||||
return $u;
|
||||
}
|
||||
|
||||
|
||||
my $ret = IOWrite($hash, $msg);
|
||||
if(!defined($ret)) {
|
||||
my $msg = "EMWZ $name read error (Set)";
|
||||
Log GetLogLevel($name,2), $msg;
|
||||
return $msg;
|
||||
}
|
||||
|
||||
if(ord(substr($ret,0,1)) != 6) {
|
||||
$ret = "EMGZ Error occured: " . unpack('H*', $ret);
|
||||
Log GetLogLevel($name,2), $ret;
|
||||
return $ret;
|
||||
}
|
||||
|
||||
return undef;
|
||||
}
|
||||
|
||||
#############################
|
||||
sub
|
||||
EMGZ_Define($$)
|
||||
{
|
||||
my ($hash, $def) = @_;
|
||||
my @a = split("[ \t][ \t]*", $def);
|
||||
|
||||
return "syntax: define <name> EMGZ devicenumber"
|
||||
if(@a != 3 || $a[2] !~ m,^[9]$,);
|
||||
$hash->{DEVNR} = $a[2];
|
||||
AssignIoPort($hash);
|
||||
|
||||
|
||||
EMGZ_GetStatus($hash);
|
||||
return undef;
|
||||
}
|
||||
|
||||
1;
|
|
@ -1,190 +0,0 @@
|
|||
##############################################
|
||||
package main;
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
use Device::SerialPort;
|
||||
|
||||
#####################################
|
||||
sub
|
||||
SCIVT_Initialize($)
|
||||
{
|
||||
my ($hash) = @_;
|
||||
|
||||
# Consumer
|
||||
$hash->{DefFn} = "SCIVT_Define";
|
||||
$hash->{GetFn} = "SCIVT_Get";
|
||||
$hash->{AttrList}= "model:SCD loglevel:0,1,2,3,4,5,6";
|
||||
}
|
||||
|
||||
#####################################
|
||||
sub
|
||||
SCIVT_Define($$)
|
||||
{
|
||||
my ($hash, $def) = @_;
|
||||
my @a = split("[ \t][ \t]*", $def);
|
||||
|
||||
return "Define the serial device as a parameter, use none for a fake device"
|
||||
if(@a != 3);
|
||||
$hash->{STATE} = "Initialized";
|
||||
|
||||
my $dev = $a[2];
|
||||
|
||||
Log 1, "SCIVT device is none, commands will be echoed only"
|
||||
if($dev eq "none");
|
||||
|
||||
if($dev ne "none") {
|
||||
Log 2, "SCIVT opening device $dev";
|
||||
my $po = new Device::SerialPort ($dev);
|
||||
return "Can't open $dev: $!" if(!$po);
|
||||
Log 2, "SCIVT opened device $dev";
|
||||
$po->close();
|
||||
}
|
||||
|
||||
$hash->{DeviceName} = $dev;
|
||||
|
||||
SCIVT_GetStatus($hash);
|
||||
return undef;
|
||||
}
|
||||
|
||||
|
||||
#####################################
|
||||
sub
|
||||
SCIVT_Get($@)
|
||||
{
|
||||
my ($hash, @a) = @_;
|
||||
|
||||
return "get for an SCIVT device needs exactly one parameter" if(@a != 2);
|
||||
|
||||
my $v;
|
||||
if($a[1] eq "data") {
|
||||
$v = SCIVT_GetLine($hash->{DeviceName});
|
||||
$v =~ s/[\r\n]//g; # Delete the NewLine
|
||||
} else {
|
||||
return "Unknown argument $a[1], must be data";
|
||||
}
|
||||
|
||||
$hash->{READINGS}{$a[1]}{VAL} = $v;
|
||||
$hash->{READINGS}{$a[1]}{TIME} = TimeNow();
|
||||
|
||||
return "$a[0] $a[1] => $v";
|
||||
}
|
||||
|
||||
#####################################
|
||||
sub
|
||||
SCIVT_GetStatus($)
|
||||
{
|
||||
my ($hash) = @_;
|
||||
|
||||
# Call us in 5 minutes again.
|
||||
InternalTimer(gettimeofday()+300, "SCIVT_GetStatus", $hash, 0);
|
||||
|
||||
my $dnr = $hash->{DEVNR};
|
||||
my $name = $hash->{NAME};
|
||||
|
||||
my %vals;
|
||||
my $result = SCIVT_GetLine($hash->{DeviceName});
|
||||
|
||||
if(!defined($result))
|
||||
{
|
||||
Log GetLogLevel($name,2), "SCIVT read error, retry";
|
||||
$result = SCIVT_GetLine($hash->{DeviceName});
|
||||
}
|
||||
|
||||
if(!defined($result))
|
||||
{
|
||||
Log GetLogLevel($name,2), "SCIVT read error, abort";
|
||||
$hash->{STATE} = "timeout";
|
||||
return $hash->{STATE};
|
||||
}
|
||||
if (length($result) < 10)
|
||||
{
|
||||
Log GetLogLevel($name,2), "SCIVT incomplete line ($result)";
|
||||
$hash->{STATE} = "incomplete";
|
||||
}
|
||||
else
|
||||
{
|
||||
$result =~ s/^.*R://;
|
||||
$result =~ s/[\r\n ]//g;
|
||||
Log GetLogLevel($name,2), "SCIVT $result (raw)";
|
||||
$result=~ s/,/./g;
|
||||
my @data = split(";", $result);
|
||||
|
||||
my @names = ("Vs", "Is", "Temp", "minV", "maxV", "minI", "maxI");
|
||||
my $tn = TimeNow();
|
||||
for(my $i = 0; $i < int(@names); $i++) {
|
||||
$hash->{CHANGED}[$i] = "$names[$i]: $data[$i]";
|
||||
$hash->{READINGS}{$names[$i]}{TIME} = $tn;
|
||||
$hash->{READINGS}{$names[$i]}{VAL} = $data[$i];
|
||||
}
|
||||
|
||||
DoTrigger($name, undef) if($init_done);
|
||||
|
||||
$result =~ s/;/ /g;
|
||||
$hash->{STATE} = "$result";
|
||||
}
|
||||
|
||||
return $hash->{STATE};
|
||||
}
|
||||
|
||||
#####################################
|
||||
sub
|
||||
SCIVT_GetLine($)
|
||||
{
|
||||
my $retry = 0;
|
||||
my ($dev) = @_;
|
||||
|
||||
return "R:13,66; 0,0;30;13,62;15,09;- 0,2; 2,8;\n"
|
||||
if($dev eq "none"); # Fake-mode
|
||||
|
||||
my $serport = new Device::SerialPort ($dev);
|
||||
if(!$serport) {
|
||||
Log 1, "SCIVT: Can't open $dev: $!";
|
||||
return undef;
|
||||
}
|
||||
$serport->reset_error();
|
||||
$serport->baudrate(1200);
|
||||
$serport->databits(8);
|
||||
$serport->parity('none');
|
||||
$serport->stopbits(1);
|
||||
$serport->handshake('none');
|
||||
|
||||
my $rm = "SCIVT timeout reading the answer";
|
||||
my $data="";
|
||||
|
||||
$serport->write('F');
|
||||
sleep(1);
|
||||
|
||||
for(;;)
|
||||
{
|
||||
my ($rout, $rin) = ('', '');
|
||||
vec($rin, $serport->FILENO, 1) = 1;
|
||||
my $nfound = select($rout=$rin, undef, undef, 3.0);
|
||||
|
||||
if($nfound < 0) {
|
||||
$rm = "SCIVT Select error $nfound / $!";
|
||||
goto DONE;
|
||||
}
|
||||
last if($nfound == 0);
|
||||
|
||||
my $buf = $serport->input();
|
||||
if(!defined($buf) || length($buf) == 0) {
|
||||
$rm = "SCIVT EOF on $dev";
|
||||
goto DONE;
|
||||
}
|
||||
|
||||
|
||||
$data .= $buf;
|
||||
if($data =~ m/[\r\n]/) { # Newline received
|
||||
$serport->close();
|
||||
return $data;
|
||||
}
|
||||
}
|
||||
|
||||
DONE:
|
||||
$serport->close();
|
||||
Log 3, "SCIVT $rm";
|
||||
return undef;
|
||||
}
|
||||
|
||||
1;
|
|
@ -1,350 +0,0 @@
|
|||
#
|
||||
#
|
||||
# 80_M232.pm
|
||||
# written by Dr. Boris Neubert 2007-11-26
|
||||
# e-mail: omega at online dot de
|
||||
#
|
||||
##############################################
|
||||
package main;
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
|
||||
sub M232Write($$);
|
||||
sub M232GetData($$);
|
||||
sub Log($$);
|
||||
use vars qw {%attr %defs};
|
||||
|
||||
#####################################
|
||||
sub
|
||||
M232_Initialize($)
|
||||
{
|
||||
my ($hash) = @_;
|
||||
|
||||
# Provider
|
||||
$hash->{WriteFn} = "M232_Write";
|
||||
$hash->{Clients} = ":M232Counter:M232Voltage:";
|
||||
|
||||
# Consumer
|
||||
$hash->{DefFn} = "M232_Define";
|
||||
$hash->{UndefFn} = "M232_Undef";
|
||||
$hash->{GetFn} = "M232_Get";
|
||||
$hash->{SetFn} = "M232_Set";
|
||||
$hash->{AttrList}= "model:m232 loglevel:0,1,2,3,4,5";
|
||||
}
|
||||
|
||||
#####################################
|
||||
sub
|
||||
M232_Define($$)
|
||||
{
|
||||
my ($hash, $def) = @_;
|
||||
my @a = split("[ \t][ \t]*", $def);
|
||||
|
||||
$hash->{STATE} = "Initialized";
|
||||
|
||||
delete $hash->{PortObj};
|
||||
delete $hash->{FD};
|
||||
|
||||
my $dev = $a[2];
|
||||
$attr{$a[0]}{savefirst} = 1;
|
||||
|
||||
if($dev eq "none") {
|
||||
Log 1, "M232 device is none, commands will be echoed only";
|
||||
return undef;
|
||||
}
|
||||
|
||||
Log 3, "M232 opening device $dev";
|
||||
my $po;
|
||||
if ($^O eq 'MSWin32') {
|
||||
eval ("use Win32::SerialPort;");
|
||||
if ($@) {
|
||||
$hash->{STATE} = "error using Modul Win32::SerialPort";
|
||||
Log 1,"Error using Device::SerialPort";
|
||||
return "Can't use Win32::SerialPort $@\n";
|
||||
}
|
||||
$po = new Win32::SerialPort ($dev, 1);
|
||||
|
||||
} else {
|
||||
eval ("use Device::SerialPort;");
|
||||
if ($@) {
|
||||
$hash->{STATE} = "error using Modul Device::SerialPort";
|
||||
Log 1,"Error using Device::SerialPort";
|
||||
return "Can't Device::SerialPort $@\n";
|
||||
}
|
||||
$po = new Device::SerialPort ($dev, 1);
|
||||
}
|
||||
if (!$po) {
|
||||
$hash->{STATE} = "error opening device";
|
||||
Log 1,"Error opening Serial Device $dev";
|
||||
return "Can't open Device $dev: $^E\n";
|
||||
}
|
||||
|
||||
Log 3, "M232 opened device $dev";
|
||||
$po->close();
|
||||
|
||||
$hash->{DeviceName} = $dev;
|
||||
return undef;
|
||||
}
|
||||
|
||||
#####################################
|
||||
sub
|
||||
M232_Undef($$)
|
||||
{
|
||||
my ($hash, $arg) = @_;
|
||||
my $name = $hash->{NAME};
|
||||
|
||||
foreach my $d (sort keys %defs) {
|
||||
if(defined($defs{$d}) &&
|
||||
defined($defs{$d}{IODev}) &&
|
||||
$defs{$d}{IODev} == $hash)
|
||||
{
|
||||
Log GetLogLevel($name,2), "deleting port for $d";
|
||||
delete $defs{$d}{IODev};
|
||||
}
|
||||
}
|
||||
return undef;
|
||||
}
|
||||
#####################################
|
||||
# M232_Ready
|
||||
# implement ReadyFn
|
||||
# only used for Win32
|
||||
#
|
||||
sub
|
||||
M232_Ready($$)
|
||||
{
|
||||
my ($hash, $dev) = @_;
|
||||
my $po=$dev||$hash->{po};
|
||||
return 0 if !$po;
|
||||
my ($BlockingFlags, $InBytes, $OutBytes, $ErrorFlags)=$po->status;
|
||||
return ($InBytes>0);
|
||||
}
|
||||
|
||||
|
||||
#####################################
|
||||
|
||||
sub
|
||||
M232_Set($@)
|
||||
{
|
||||
my ($hash, @a) = @_;
|
||||
my $u1 = "Usage: set <name> auto <value>\n" .
|
||||
"set <name> stop\n" .
|
||||
"set <name> start\n" .
|
||||
"set <name> octet <value>\n" .
|
||||
"set <name> [io0..io7] 0|1\n";
|
||||
|
||||
return $u1 if(int(@a) < 2);
|
||||
my $msg;
|
||||
my $reading= $a[1];
|
||||
my $value;
|
||||
my @legal;
|
||||
|
||||
if($reading eq "auto") {
|
||||
return $u1 if(int(@a) !=3);
|
||||
$value= $a[2];
|
||||
@legal= (0..5,"none");
|
||||
if(!grep($value eq $_, @legal)) {
|
||||
return "Illegal value $value, possible values: @legal";
|
||||
}
|
||||
if($value eq "none") { $value= 0; } else { $value+=1; }
|
||||
$msg= "M" . $value;
|
||||
}
|
||||
|
||||
elsif($reading eq "start") {
|
||||
return $u1 if(int(@a) !=2);
|
||||
$msg= "Z1";
|
||||
}
|
||||
|
||||
elsif($reading eq "stop") {
|
||||
return $u1 if(int(@a) !=2);
|
||||
$msg= "Z0";
|
||||
}
|
||||
|
||||
elsif($reading eq "octet") {
|
||||
return $u1 if(int(@a) !=3);
|
||||
$value= $a[2];
|
||||
@legal= (0..255);
|
||||
if(!grep($value eq $_, @legal)) {
|
||||
return "Illegal value $value, possible values: 0..255";
|
||||
}
|
||||
$msg= sprintf("W%02X", $value);
|
||||
}
|
||||
|
||||
elsif($reading =~ /^io[0-7]$/) {
|
||||
return $u1 if(int(@a) !=3);
|
||||
$value= $a[2];
|
||||
return $u1 unless($value eq "0" || $value eq "1");
|
||||
$msg= "D" . substr($reading,2,1) . $value;
|
||||
}
|
||||
|
||||
else { return $u1; }
|
||||
|
||||
my $d = M232GetData($hash, $msg);
|
||||
return "Read error" if(!defined($d));
|
||||
return $d;
|
||||
}
|
||||
|
||||
#####################################
|
||||
sub
|
||||
M232_Get($@)
|
||||
{
|
||||
|
||||
my ($hash, @a) = @_;
|
||||
my $u1 = "Usage: get <name> [an0..an5]\n" .
|
||||
"get <name> [io0..io7]\n" .
|
||||
"get <name> octet\n" .
|
||||
"get <name> counter";
|
||||
|
||||
return $u1 if(int(@a) != 2);
|
||||
|
||||
my $name= $a[0];
|
||||
my $reading= $a[1];
|
||||
my $msg;
|
||||
my $retval;
|
||||
my ($count,$d,$state,$iscurrent,$voltage);
|
||||
|
||||
|
||||
if($reading eq "counter") {
|
||||
$msg= "z";
|
||||
$d = M232GetData($hash, $msg);
|
||||
return "Read error" if(!defined($d));
|
||||
$count= hex $d;
|
||||
$retval= $count;
|
||||
}
|
||||
|
||||
elsif($reading =~ /^an[0-5]$/) {
|
||||
$msg= "a" . substr($reading,2,1);
|
||||
$d = M232GetData($hash, $msg);
|
||||
return "Read error" if(!defined($d));
|
||||
$voltage= (hex substr($d,0,3))*5.00/1024.0;
|
||||
$iscurrent= substr($d,3,1);
|
||||
$retval= $voltage; # . " " . $iscurrent;
|
||||
}
|
||||
|
||||
elsif($reading =~ /^io[0-7]$/) {
|
||||
$msg= "d" . substr($reading,2,1);
|
||||
$d = M232GetData($hash, $msg);
|
||||
return "Read error" if(!defined($d));
|
||||
$state= hex $d;
|
||||
$retval= $state;
|
||||
}
|
||||
|
||||
elsif($reading eq "octet") {
|
||||
$msg= "w";
|
||||
$d = M232GetData($hash, $msg);
|
||||
return "Read error" if(!defined($d));
|
||||
$state= hex $d;
|
||||
$retval= $state;
|
||||
}
|
||||
|
||||
else { return $u1; }
|
||||
|
||||
$hash->{READINGS}{$reading}{VAL}= $retval;
|
||||
$hash->{READINGS}{$reading}{TIME}= TimeNow();
|
||||
|
||||
return "$name $reading => $retval";
|
||||
|
||||
}
|
||||
|
||||
#####################################
|
||||
sub
|
||||
M232_Write($$)
|
||||
{
|
||||
my ($hash,$msg) = @_;
|
||||
|
||||
return M232GetData($hash, $msg);
|
||||
}
|
||||
|
||||
|
||||
#####################################
|
||||
sub
|
||||
M232GetData($$)
|
||||
{
|
||||
my ($hash, $data) = @_;
|
||||
my $dev=$hash->{DeviceName};
|
||||
my $MSGSTART= chr 1;
|
||||
my $MSGEND= chr 13;
|
||||
my $MSGACK= chr 6;
|
||||
my $MSGNACK= chr 21;
|
||||
my $serport;
|
||||
my $d = $MSGSTART . $data . $MSGEND;
|
||||
|
||||
if ($^O eq 'MSWin32') {
|
||||
$serport=new Win32::SerialPort ($dev, 1);
|
||||
}else{
|
||||
$serport=new Device::SerialPort ($dev, 1);
|
||||
}
|
||||
if(!$serport) {
|
||||
Log 3, "M232: Can't open $dev: $!";
|
||||
return undef;
|
||||
}
|
||||
$serport->reset_error();
|
||||
$serport->baudrate(2400);
|
||||
$serport->databits(8);
|
||||
$serport->parity('none');
|
||||
$serport->stopbits(1);
|
||||
$serport->handshake('none');
|
||||
$serport->write_settings;
|
||||
$hash->{po}=$serport;
|
||||
Log 4, "M232: Sending $d";
|
||||
|
||||
my $rm = "M232: ?";
|
||||
|
||||
$serport->lookclear;
|
||||
$serport->write($d);
|
||||
|
||||
my $retval = "";
|
||||
my $status = "";
|
||||
my $nfound=0;
|
||||
my $ret=undef;
|
||||
sleep(1);
|
||||
for(;;) {
|
||||
if ($^O eq 'MSWin32') {
|
||||
$nfound=M232_Ready($hash,undef);
|
||||
}else{
|
||||
my ($rout, $rin) = ('', '');
|
||||
vec($rin, $serport->FILENO, 1) = 1;
|
||||
$nfound = select($rin, undef, undef, 1.0); # 3 seconds timeout
|
||||
if($nfound < 0) {
|
||||
next if ($! == EAGAIN() || $! == EINTR() || $! == 0);
|
||||
$rm="M232:Select error $nfound / $!";
|
||||
last;
|
||||
}
|
||||
}
|
||||
|
||||
last if($nfound == 0);
|
||||
|
||||
my $out = $serport->read(1);
|
||||
if(!defined($out) || length($out) == 0) {
|
||||
$rm = "M232 EOF on $dev";
|
||||
last;
|
||||
}
|
||||
|
||||
if($out eq $MSGACK) {
|
||||
$rm= "M232: acknowledged";
|
||||
Log 4, "M232: return value \'" . $retval . "\'";
|
||||
$status= "ACK";
|
||||
} elsif($out eq $MSGNACK) {
|
||||
$rm= "M232: not acknowledged";
|
||||
$status= "NACK";
|
||||
$retval= undef;
|
||||
} else {
|
||||
$retval .= $out;
|
||||
}
|
||||
|
||||
if($status) {
|
||||
$ret=$retval;
|
||||
last;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
DONE:
|
||||
$serport->close();
|
||||
undef $serport;
|
||||
delete $hash->{po} if exists($hash->{po});
|
||||
Log 4, $rm;
|
||||
return $ret;
|
||||
}
|
||||
|
||||
1;
|
|
@ -1,176 +0,0 @@
|
|||
#
|
||||
#
|
||||
# 81_M232Counter.pm
|
||||
# written by Dr. Boris Neubert 2007-11-26
|
||||
# e-mail: omega at online dot de
|
||||
#
|
||||
##############################################
|
||||
package main;
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
use Time::HiRes qw(gettimeofday);
|
||||
|
||||
sub M232Counter_Get($@);
|
||||
sub M232Counter_Set($@);
|
||||
sub M232Counter_SetBasis($@);
|
||||
sub M232Counter_Define($$);
|
||||
sub M232Counter_GetStatus($);
|
||||
|
||||
###################################
|
||||
sub
|
||||
M232Counter_Initialize($)
|
||||
{
|
||||
my ($hash) = @_;
|
||||
|
||||
$hash->{GetFn} = "M232Counter_Get";
|
||||
$hash->{SetFn} = "M232Counter_Set";
|
||||
$hash->{DefFn} = "M232Counter_Define";
|
||||
|
||||
$hash->{AttrList} = "dummy:1,0 model;M232Counter loglevel:0,1,2,3,4,5";
|
||||
}
|
||||
|
||||
###################################
|
||||
sub
|
||||
M232Counter_GetStatus($)
|
||||
{
|
||||
my ($hash) = @_;
|
||||
|
||||
if(!$hash->{LOCAL}) {
|
||||
InternalTimer(gettimeofday()+60, "M232Counter_GetStatus", $hash, 1);
|
||||
}
|
||||
|
||||
my $name = $hash->{NAME};
|
||||
|
||||
my $d = IOWrite($hash, "z");
|
||||
if(!defined($d)) {
|
||||
my $msg = "M232Counter $name read error";
|
||||
Log GetLogLevel($name,2), $msg;
|
||||
return $msg;
|
||||
}
|
||||
|
||||
my $tn = TimeNow();
|
||||
if(!defined($hash->{READINGS}{basis})) {
|
||||
$hash->{READINGS}{basis}{VAL}= 0;
|
||||
$hash->{READINGS}{basis}{TIME}= $tn;
|
||||
}
|
||||
if(!defined($hash->{READINGS}{count})) {
|
||||
$hash->{READINGS}{count}{VAL}= 0;
|
||||
$hash->{READINGS}{count}{TIME}= $tn;
|
||||
}
|
||||
my $count= hex $d;
|
||||
if($count< $hash->{READINGS}{count}{VAL}) {
|
||||
$hash->{READINGS}{basis}{VAL}+= 65536;
|
||||
$hash->{READINGS}{basis}{TIME}= $tn;
|
||||
}
|
||||
my $value= ($hash->{READINGS}{basis}{VAL}+$count) * $hash->{FACTOR};
|
||||
|
||||
$hash->{READINGS}{count}{TIME} = $tn;
|
||||
$hash->{READINGS}{count}{VAL} = $count;
|
||||
$hash->{READINGS}{value}{TIME} = $tn;
|
||||
$hash->{READINGS}{value}{VAL} = $value;
|
||||
|
||||
$hash->{CHANGED}[0]= "value: $value";
|
||||
|
||||
if(!$hash->{LOCAL}) {
|
||||
DoTrigger($name, undef) if($init_done);
|
||||
}
|
||||
|
||||
$hash->{STATE} = $value;
|
||||
Log GetLogLevel($name,4), "M232Counter $name: $value $hash->{UNIT}";
|
||||
|
||||
return $hash->{STATE};
|
||||
}
|
||||
|
||||
###################################
|
||||
sub
|
||||
M232Counter_Get($@)
|
||||
{
|
||||
my ($hash, @a) = @_;
|
||||
|
||||
return "argument is missing" if(int(@a) != 2);
|
||||
|
||||
my $msg;
|
||||
|
||||
if($a[1] ne "status") {
|
||||
return "unknown get value, valid is status";
|
||||
}
|
||||
$hash->{LOCAL} = 1;
|
||||
my $v = M232Counter_GetStatus($hash);
|
||||
delete $hash->{LOCAL};
|
||||
|
||||
return "$a[0] $a[1] => $v";
|
||||
}
|
||||
|
||||
#############################
|
||||
sub
|
||||
M232Counter_Calibrate($@)
|
||||
{
|
||||
my ($hash, $value) = @_;
|
||||
my $rm= undef;
|
||||
my $name = $hash->{NAME};
|
||||
|
||||
|
||||
# adjust basis
|
||||
my $tn = TimeNow();
|
||||
$hash->{READINGS}{basis}{VAL}= $value / $hash->{FACTOR};
|
||||
$hash->{READINGS}{basis}{TIME}= $tn;
|
||||
$hash->{READINGS}{count}{VAL}= 0;
|
||||
$hash->{READINGS}{count}{TIME}= $tn;
|
||||
|
||||
# recalculate value
|
||||
$hash->{READINGS}{value}{VAL} = $value;
|
||||
$hash->{READINGS}{value}{TIME} = $tn;
|
||||
|
||||
# reset counter
|
||||
my $ret = IOWrite($hash, "Z1");
|
||||
if(!defined($ret)) {
|
||||
my $rm = "M232Counter $name read error";
|
||||
Log GetLogLevel($name,2), $rm;
|
||||
}
|
||||
|
||||
return $rm;
|
||||
}
|
||||
|
||||
#############################
|
||||
sub
|
||||
M232Counter_Set($@)
|
||||
{
|
||||
my ($hash, @a) = @_;
|
||||
my $u = "Usage: set <name> value <value>";
|
||||
|
||||
return $u if(int(@a) != 3);
|
||||
my $reading= $a[1];
|
||||
my $value = $a[2];
|
||||
return $u unless($reading eq "value");
|
||||
|
||||
my $rm= M232Counter_Calibrate($hash, $value);
|
||||
|
||||
return undef;
|
||||
}
|
||||
|
||||
|
||||
#############################
|
||||
sub
|
||||
M232Counter_Define($$)
|
||||
{
|
||||
my ($hash, $def) = @_;
|
||||
my @a = split("[ \t][ \t]*", $def);
|
||||
|
||||
return "syntax: define <name> M232Counter [unit] [multiplicator]"
|
||||
if(int(@a) < 2 && int(@a) > 4);
|
||||
|
||||
my $unit= ((int(@a) > 2) ? $a[2] : "ticks");
|
||||
my $factor= ((int(@a) > 3) ? $a[3] : 1.0);
|
||||
$hash->{UNIT}= $unit;
|
||||
$hash->{FACTOR}= $factor;
|
||||
|
||||
AssignIoPort($hash);
|
||||
|
||||
if(!$hash->{LOCAL}) {
|
||||
InternalTimer(gettimeofday()+60, "M232Counter_GetStatus", $hash, 0);
|
||||
}
|
||||
return undef;
|
||||
}
|
||||
|
||||
1;
|
|
@ -1,116 +0,0 @@
|
|||
#
|
||||
#
|
||||
# 82_M232Voltage.pm
|
||||
# written by Dr. Boris Neubert 2007-12-24
|
||||
# e-mail: omega at online dot de
|
||||
#
|
||||
##############################################
|
||||
package main;
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
use Time::HiRes qw(gettimeofday);
|
||||
|
||||
sub M232Voltage_Get($@);
|
||||
sub M232Voltage_Define($$);
|
||||
sub M232Voltage_GetStatus($);
|
||||
|
||||
###################################
|
||||
sub
|
||||
M232Voltage_Initialize($)
|
||||
{
|
||||
my ($hash) = @_;
|
||||
|
||||
$hash->{GetFn} = "M232Voltage_Get";
|
||||
$hash->{DefFn} = "M232Voltage_Define";
|
||||
|
||||
$hash->{AttrList} = "dummy:1,0 model;M232Voltage loglevel:0,1,2,3,4,5";
|
||||
}
|
||||
|
||||
###################################
|
||||
sub
|
||||
M232Voltage_GetStatus($)
|
||||
{
|
||||
my ($hash) = @_;
|
||||
|
||||
if(!$hash->{LOCAL}) {
|
||||
InternalTimer(gettimeofday()+60, "M232Voltage_GetStatus", $hash, 1);
|
||||
}
|
||||
|
||||
my $name = $hash->{NAME};
|
||||
|
||||
my $d = IOWrite($hash, "a" . $hash->{INPUT});
|
||||
if(!defined($d)) {
|
||||
my $msg = "M232Voltage $name read error";
|
||||
Log GetLogLevel($name,2), $msg;
|
||||
return $msg;
|
||||
}
|
||||
|
||||
my $tn = TimeNow();
|
||||
my $value= (hex substr($d,0,3))*5.00/1024.0 * $hash->{FACTOR};
|
||||
|
||||
$hash->{READINGS}{value}{TIME} = $tn;
|
||||
$hash->{READINGS}{value}{VAL} = $value;
|
||||
|
||||
$hash->{CHANGED}[0]= "value: $value";
|
||||
|
||||
if(!$hash->{LOCAL}) {
|
||||
DoTrigger($name, undef) if($init_done);
|
||||
}
|
||||
|
||||
$hash->{STATE} = $value;
|
||||
Log GetLogLevel($name,4), "M232Voltage $name: $value $hash->{UNIT}";
|
||||
|
||||
return $hash->{STATE};
|
||||
}
|
||||
|
||||
###################################
|
||||
sub
|
||||
M232Voltage_Get($@)
|
||||
{
|
||||
my ($hash, @a) = @_;
|
||||
|
||||
return "argument is missing" if(int(@a) != 2);
|
||||
|
||||
my $msg;
|
||||
|
||||
if($a[1] ne "status") {
|
||||
return "unknown get value, valid is status";
|
||||
}
|
||||
$hash->{LOCAL} = 1;
|
||||
my $v = M232Voltage_GetStatus($hash);
|
||||
delete $hash->{LOCAL};
|
||||
|
||||
return "$a[0] $a[1] => $v";
|
||||
}
|
||||
|
||||
#############################
|
||||
sub
|
||||
M232Voltage_Define($$)
|
||||
{
|
||||
my ($hash, $def) = @_;
|
||||
my @a = split("[ \t][ \t]*", $def);
|
||||
|
||||
return "syntax: define <name> M232Voltage an0..an5 [unit [factor]]"
|
||||
if(int(@a) < 3 && int(@a) > 5);
|
||||
|
||||
my $reading= $a[2];
|
||||
return "$reading is not an analog input, valid: an0..an5"
|
||||
if($reading !~ /^an[0-5]$/) ;
|
||||
|
||||
my $unit= ((int(@a) > 3) ? $a[3] : "volts");
|
||||
my $factor= ((int(@a) > 4) ? $a[4] : 1.0);
|
||||
|
||||
$hash->{INPUT}= substr($reading,2);
|
||||
$hash->{UNIT}= $unit;
|
||||
$hash->{FACTOR}= $factor;
|
||||
|
||||
AssignIoPort($hash);
|
||||
|
||||
if(!$hash->{LOCAL}) {
|
||||
InternalTimer(gettimeofday()+60, "M232Voltage_GetStatus", $hash, 0);
|
||||
}
|
||||
return undef;
|
||||
}
|
||||
|
||||
1;
|
|
@ -1,166 +0,0 @@
|
|||
##############################################
|
||||
package main;
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
use Device::SerialPort;
|
||||
use IO::Socket::INET;
|
||||
|
||||
my $fs10data = "";
|
||||
my $pcwsdsocket;
|
||||
|
||||
|
||||
#####################################
|
||||
sub
|
||||
FS10_Initialize($)
|
||||
{
|
||||
my ($hash) = @_;
|
||||
|
||||
# Consumer
|
||||
$hash->{DefFn} = "FS10_Define";
|
||||
$hash->{AttrList}= "model:FS10 loglevel:0,1,2,3,4,5,6";
|
||||
}
|
||||
|
||||
#####################################
|
||||
sub
|
||||
FS10_Define($$)
|
||||
{
|
||||
my ($hash, $def) = @_;
|
||||
my @a = split("[ \t][ \t]*", $def);
|
||||
|
||||
Log 3, "FS10 Define: $a[0] $a[1] $a[2] $a[3]";
|
||||
|
||||
return "Define the host and portnr as a parameter i.e. 127.0.0.1 4711"
|
||||
if(@a != 4);
|
||||
|
||||
$hash->{Timer} = 600;
|
||||
$hash->{Host} = $a[2];
|
||||
$hash->{Port} = $a[3];
|
||||
$hash->{STATE} = "Initialized";
|
||||
|
||||
my $dev = $a[2];
|
||||
Log 1, "FS10 device is none, commands will be echoed only"
|
||||
if($dev eq "none");
|
||||
|
||||
$hash->{DeviceName} = $dev;
|
||||
|
||||
FS10_GetStatus($hash);
|
||||
return undef;
|
||||
}
|
||||
|
||||
|
||||
#####################################
|
||||
sub
|
||||
FS10_GetStatus($)
|
||||
{
|
||||
my ($hash) = @_;
|
||||
my $buf;
|
||||
#my $banner;
|
||||
my $reqcmd;
|
||||
my $fs10time;
|
||||
my $dt;
|
||||
my $x;
|
||||
my $result = "";
|
||||
|
||||
Log 3, "FS10_GetStatus";
|
||||
|
||||
# Call us in 5 minutes again.
|
||||
InternalTimer(gettimeofday()+300, "FS10_GetStatus", $hash, 0);
|
||||
|
||||
my $dnr = $hash->{DEVNR};
|
||||
my $name = $hash->{NAME};
|
||||
my $host = $hash->{Host};
|
||||
my $port = $hash->{Port};
|
||||
my %vals;
|
||||
my $pcwsd ="$host:$port";
|
||||
my $pcwsdsocket = IO::Socket::INET->new( $pcwsd )
|
||||
or return "FS10 Can't bind to pcwsd" if(!$pcwsdsocket);
|
||||
|
||||
my $banner = $pcwsdsocket->getline();
|
||||
my @x = split(" ", $banner);
|
||||
my @y;
|
||||
my $fs10name;
|
||||
|
||||
for(my $i = 0; $i < 8; $i++) #Outdoor
|
||||
{
|
||||
$fs10name ="Ta$i";
|
||||
$reqcmd = "get od2temp $i\r\n";
|
||||
$pcwsdsocket->print($reqcmd);
|
||||
$buf = $pcwsdsocket->getline();
|
||||
$result = "$result $buf";
|
||||
|
||||
@x = split(" ", $buf);
|
||||
$fs10time = FmtDateTime($x[1]);
|
||||
|
||||
$hash->{CHANGED}[$i] = "Ta$i: $x[0]";
|
||||
$hash->{READINGS}{$fs10name}{TIME} = $fs10time;
|
||||
$hash->{READINGS}{$fs10name}{VAL} = $x[0];
|
||||
}
|
||||
|
||||
$fs10name="Ti";
|
||||
$reqcmd = "get idtemp 7\r\n";
|
||||
$pcwsdsocket->print($reqcmd);
|
||||
$buf = $pcwsdsocket->getline();
|
||||
@x = split(" ", $buf);
|
||||
$fs10time = FmtDateTime($x[1]);
|
||||
|
||||
$hash->{CHANGED}[8] = "Ti: $x[0]";
|
||||
$hash->{READINGS}{$fs10name}{TIME} = $fs10time;
|
||||
$hash->{READINGS}{$fs10name}{VAL} = $x[0];
|
||||
|
||||
$fs10name="Rain";
|
||||
$reqcmd = "get rain 7\r\n";
|
||||
$pcwsdsocket->print($reqcmd);
|
||||
$buf = $pcwsdsocket->getline();
|
||||
@x = split(" ", $buf);
|
||||
$fs10time = FmtDateTime($x[1]);
|
||||
|
||||
$hash->{CHANGED}[9] = "Rain: $x[0]";
|
||||
$hash->{READINGS}{$fs10name}{TIME} = $fs10time;
|
||||
$hash->{READINGS}{$fs10name}{VAL} = $x[0];
|
||||
|
||||
$fs10name="Sun";
|
||||
$reqcmd = "get bright 7\r\n";
|
||||
$pcwsdsocket->print($reqcmd);
|
||||
$buf = $pcwsdsocket->getline();
|
||||
@x = split(" ", $buf);
|
||||
$fs10time = FmtDateTime($x[1]);
|
||||
|
||||
$hash->{CHANGED}[10] = "Sun: $x[0]";
|
||||
$hash->{READINGS}{$fs10name}{TIME} = $fs10time;
|
||||
$hash->{READINGS}{$fs10name}{VAL} = $x[0];
|
||||
|
||||
$fs10name="Windspeed";
|
||||
$reqcmd = "get wspd 7\r\n";
|
||||
$pcwsdsocket->print($reqcmd);
|
||||
$buf = $pcwsdsocket->getline();
|
||||
@x = split(" ", $buf);
|
||||
$fs10time = FmtDateTime($x[1]);
|
||||
|
||||
$hash->{CHANGED}[11] = "Windspeed: $x[0]";
|
||||
$hash->{READINGS}{$fs10name}{TIME} = $fs10time;
|
||||
$hash->{READINGS}{$fs10name}{VAL} = $x[0];
|
||||
|
||||
close($pcwsdsocket);
|
||||
|
||||
$result =~ s/[\r\n]//g;
|
||||
DoTrigger($name, undef) if($init_done);
|
||||
|
||||
$hash->{STATE} = "$result";
|
||||
Log 3,"FS10 Result: $result";
|
||||
return $hash->{STATE};
|
||||
}
|
||||
|
||||
#####################################
|
||||
sub
|
||||
FS10Log($$)
|
||||
{
|
||||
my ($a1, $a2) = @_;
|
||||
|
||||
#define n31 notify fs10 {FS10Log("@", "%")}
|
||||
#define here notify action
|
||||
|
||||
Log 2,"FS10 $a1 = $a2 old: $oldvalue{$a1}{TIME}=> $oldvalue{$a1}{VAL});";
|
||||
}
|
||||
|
||||
1;
|
|
@ -1,535 +0,0 @@
|
|||
package main;
|
||||
###########################
|
||||
# 87_ws2000.pm
|
||||
# Modul for FHEM
|
||||
#
|
||||
# contributed by thomas dressler 2008
|
||||
# $Id: 87_WS2000.pm,v 1.3 2008-05-11 21:17:30 tdressler Exp $
|
||||
###########################
|
||||
use strict;
|
||||
use Switch;
|
||||
use warnings;
|
||||
|
||||
#prototypes to make komodo happy
|
||||
use vars qw{%attr %defs};
|
||||
sub Log($$);
|
||||
our $FH;
|
||||
####################################
|
||||
# WS2000_Initialize
|
||||
# Implements Initialize function
|
||||
#
|
||||
sub WS2000_Initialize($)
|
||||
{
|
||||
my ($hash) = @_;
|
||||
|
||||
# Provider
|
||||
#$hash->{WriteFn} = "ws2000_Write";
|
||||
# $hash->{Clients} = ":WS2000Rain:WS2000Wind:WS2000Indoor:WS2000Lux:WS2000Pyro:WS2000Temp:WS2000TempHum";
|
||||
|
||||
# Consumer
|
||||
$hash->{DefFn} = "WS2000_Define";
|
||||
$hash->{UndefFn} = "WS2000_Undef";
|
||||
$hash->{GetFn} = "WS2000_Get";
|
||||
$hash->{SetFn} = "WS2000_Set";
|
||||
$hash->{ReadyFn} = "WS2000_Ready";
|
||||
$hash->{ReadFn} ="WS2000_Read";
|
||||
$hash->{ListFn} ="WS2000_List";
|
||||
$hash->{AttrList}= "model:WS2000 rain altitude loglevel:0,1,2,3,4,5";
|
||||
}
|
||||
|
||||
#####################################
|
||||
# WS2000_Define
|
||||
# Implements DefFn function
|
||||
#
|
||||
sub
|
||||
WS2000_Define($$)
|
||||
{
|
||||
my ($hash, $def) = @_;
|
||||
my @a = split("[ \t][ \t]*", $def);
|
||||
delete $hash->{po};
|
||||
delete $hash->{socket};
|
||||
delete $hash->{FD};
|
||||
my $ws2000_cfg='ws2000.cfg';
|
||||
my $quiet=1;
|
||||
my $name=$hash->{NAME};
|
||||
my $PortName = $a[2];
|
||||
my $PortObj;
|
||||
$attr{$a[0]}{savefirst} = 1;
|
||||
|
||||
if($PortName eq "none") {
|
||||
Log 1, "WS2000 device is none, commands will be echoed only";
|
||||
return undef;
|
||||
}
|
||||
|
||||
Log 4, "WS2000 opening device $PortName";
|
||||
|
||||
#switch serial/socket device
|
||||
if ($PortName=~/^\/dev|^COM/) {
|
||||
#normal devices (/dev), on windows COMx
|
||||
my $OS=$^O;
|
||||
if ($OS eq 'MSWin32') {
|
||||
eval ("use Win32::SerialPort;");
|
||||
if ($@) {
|
||||
$hash->{STATE} = "error using Modul Win32::SerialPort";
|
||||
Log 1,"Error using Device::SerialPort";
|
||||
return "Can't use Win32::SerialPort $@\n";
|
||||
}
|
||||
$PortObj = new Win32::SerialPort ($PortName, $quiet);
|
||||
if (!$PortObj) {
|
||||
$hash->{STATE} = "error opening device";
|
||||
Log 1,"Error opening Serial Device $PortName";
|
||||
return "Can't open Device $PortName: $^E\n";
|
||||
}
|
||||
#$hash->{FD}=$PortObj->{_HANDLE};
|
||||
} else {
|
||||
eval ("use Device::SerialPort;");
|
||||
if ($@) {
|
||||
$hash->{STATE} = "error using Modul Device::SerialPort";
|
||||
Log 1,"Error using Device::SerialPort";
|
||||
return "Can't Device::SerialPort $@\n";
|
||||
}
|
||||
$PortObj = new Device::SerialPort ($PortName, $quiet);
|
||||
if (!$PortObj) {
|
||||
$hash->{STATE} = "error opening device";
|
||||
Log 1,"Error opening Serial Device $PortName";
|
||||
return "Can't open Device $PortName: $^E\n";
|
||||
}
|
||||
#$hash->{FD}=$PortObj->FILENO;
|
||||
}
|
||||
#Parameter 19200,8,2,Odd,None
|
||||
$PortObj->baudrate(19200);
|
||||
$PortObj->databits(8);
|
||||
$PortObj->parity("odd");
|
||||
$PortObj->stopbits(2);
|
||||
$PortObj->handshake("none");
|
||||
if (! $PortObj->write_settings) {
|
||||
undef $PortObj;
|
||||
return "Serial write Settings failed!\n";
|
||||
}
|
||||
$hash->{po}=$PortObj;
|
||||
$hash->{socket}=0;
|
||||
|
||||
}elsif($PortName=~/([\w.]+):(\d{1,5})/){
|
||||
#Sockets(hostname:port)
|
||||
my $host=$1;
|
||||
my $port=$2;
|
||||
my $xport=IO::Socket::INET->new(PeerAddr=>$host,
|
||||
PeerPort=>$port,
|
||||
timeout=>1,
|
||||
blocking=>0
|
||||
);
|
||||
if (!$xport) {
|
||||
$hash->{STATE} = "error opening device";
|
||||
Log 1,"Error opening Connection to $PortName";
|
||||
return "Can't Connect to $PortName -> $@ ( $!)\n";
|
||||
}
|
||||
$xport->autoflush(1);
|
||||
$hash->{FD}=$xport->fileno;
|
||||
$hash->{socket}=$xport;
|
||||
|
||||
|
||||
}else{
|
||||
$hash->{STATE} = "$PortName is no device and not implemented";
|
||||
Log 1,"$PortName is no device and not implemented";
|
||||
return "$PortName is no device and not implemented\n";
|
||||
}
|
||||
Log 4, "$name connected to device $PortName";
|
||||
$hash->{STATE} = "open";
|
||||
$hash->{DeviceName}=$PortName;
|
||||
return undef;
|
||||
}
|
||||
|
||||
#####################################
|
||||
# WS2000_Undef
|
||||
# implements UnDef-Function
|
||||
#
|
||||
sub
|
||||
WS2000_Undef($$)
|
||||
{
|
||||
my ($hash, $arg) = @_;
|
||||
my $name = $hash->{NAME};
|
||||
delete $hash->{FD};
|
||||
$hash->{STATE}='close';
|
||||
if ($hash->{socket}) {
|
||||
$hash->{socket}->shutdown(2);
|
||||
$hash->{socket}->close();
|
||||
}elsif ($hash->{po}) {
|
||||
$hash->{po}->close();
|
||||
}
|
||||
Log 5, "$name shutdown complete";
|
||||
return undef;
|
||||
}
|
||||
|
||||
#####################################
|
||||
# WS2000_Set
|
||||
# implement SetFn
|
||||
# currently nothing to set
|
||||
#
|
||||
sub
|
||||
WS2000_Ready($$)
|
||||
{
|
||||
my ($hash, $dev) = @_;
|
||||
my $po=$hash->{po};
|
||||
return undef if !$po;
|
||||
my ($BlockingFlags, $InBytes, $OutBytes, $ErrorFlags)=$po->status;
|
||||
return ($InBytes>0);
|
||||
}
|
||||
|
||||
#####################################
|
||||
# WS2000_Set
|
||||
# implement SetFn
|
||||
# currently nothing to set
|
||||
#
|
||||
sub
|
||||
WS2000_Set($@)
|
||||
{
|
||||
my ($hash, @a) = @_;
|
||||
|
||||
my $msg;
|
||||
my $name=$a[0];
|
||||
my $reading= $a[1];
|
||||
$msg="$name => No Set function ($reading) implemented";
|
||||
Log 1,$msg;
|
||||
return $msg;
|
||||
|
||||
}
|
||||
|
||||
#####################################
|
||||
# WS2000_Get
|
||||
# implement GetFn
|
||||
#
|
||||
sub
|
||||
WS2000_Get($@)
|
||||
{
|
||||
|
||||
my ($hash, @a) = @_;
|
||||
my $u1 = "Usage: get <name> [TH0..TH7, T0..T7, I0..I7, R0..R7, W0..W7, L0..L7, P0..P7, LAST, RAW]\n" .
|
||||
"get <name> list\n";
|
||||
|
||||
|
||||
return $u1 if(int(@a) != 2);
|
||||
|
||||
my $name= $a[0];
|
||||
my $reading= $a[1];
|
||||
my $msg;
|
||||
my $retval;
|
||||
my $time;
|
||||
my $sensor=$hash->{READINGS};
|
||||
if ($reading =~/list/i) {
|
||||
$msg='';
|
||||
foreach my $s (keys %$sensor) {
|
||||
next if !$s;
|
||||
$msg.="ID:$s, Last Update ".$sensor->{$s}{TIME}."\n";
|
||||
}
|
||||
}else {
|
||||
if(!defined($sensor->{$reading})) {
|
||||
$msg="Sensor ($reading)not defined, try 'get <n<me> list'";
|
||||
}else {
|
||||
$retval=$sensor->{$reading}{VAL};
|
||||
$time=$sensor->{$reading}{TIME};
|
||||
$retval=unpack("H*",$retval) if ($reading eq 'RAW');
|
||||
$msg= "$name $reading ($time) => $retval";
|
||||
}
|
||||
}
|
||||
return $msg;
|
||||
}
|
||||
|
||||
#####################################
|
||||
# WS2000_Write
|
||||
# currently dummy
|
||||
#
|
||||
sub
|
||||
WS2000_Write($$)
|
||||
{
|
||||
my ($hash,$msg) = @_;
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
#####################################
|
||||
# WS2000_Read
|
||||
# Implements ReadFn, called from global select
|
||||
#
|
||||
sub
|
||||
WS2000_Read($$) {
|
||||
|
||||
my ($hash) = @_;
|
||||
|
||||
my $STX=2;
|
||||
my $ETX=3;
|
||||
my $retval='';
|
||||
my $out=undef;
|
||||
my $byte;
|
||||
my $name=$hash->{NAME};
|
||||
my $xport=$hash->{socket};
|
||||
my $PortObj=$hash->{po};
|
||||
my $message=$hash->{PARTIAL}||'';
|
||||
my $status=$hash->{STEP};
|
||||
#read data(1 byte), because fhem select flagged data available
|
||||
if ($xport) {
|
||||
$xport->read($out,1);
|
||||
}elsif($PortObj) {
|
||||
$out = $PortObj->read(1);
|
||||
}
|
||||
return if(!defined($out) || length($out) == 0) ;
|
||||
Log 5, "$name => WS2000/RAW: " . unpack('H*',$out);
|
||||
|
||||
#check for frame: STX TYP W1 W2 W3 W4 W5 ETX
|
||||
$byte=ord($out);
|
||||
if($byte eq $STX) {
|
||||
#Log 4, "M232: return value \'" . $retval . "\'";
|
||||
$status= "STX";
|
||||
$message=$out;
|
||||
Log 5, "WS2000 STX received";
|
||||
} elsif($byte eq $ETX) {
|
||||
$status= "ETX";
|
||||
$message .=$out;
|
||||
Log 5, "WS2000 ETX received";
|
||||
} elsif ($status eq "STX"){
|
||||
$message .=$out;
|
||||
}
|
||||
$hash->{STEP}=$status;
|
||||
$hash->{PARTIAL}=$message;
|
||||
if($status eq "ETX") {
|
||||
WS2000_Parse($hash,$message);
|
||||
}
|
||||
}
|
||||
#####################################
|
||||
# WS2000_Parse
|
||||
# decodes complete frame
|
||||
# called directly from WS2000_Read
|
||||
sub
|
||||
WS2000_Parse($$) {
|
||||
my ($hash,$msg) = @_;
|
||||
my ($stx,$typ,$w1,$w2,$w3,$w4,$w5,$etx)=map {$_ & 0x7F} unpack("U*",$msg);
|
||||
my $tm=TimeNow();
|
||||
my $name=$hash->{NAME};
|
||||
my $factor=$attr{$name}{rain}||366;
|
||||
my $altitude=$attr{$name}{altitude}||0;
|
||||
if ($etx != 3) {
|
||||
Log 4, "$name:Frame Error!";
|
||||
return undef;
|
||||
}
|
||||
my ($sensor,$daten1,$einheit1,$daten2,$einheit2,$daten3,$einheit3,$result,$shortname,$val, $unit);
|
||||
my $group = ($typ & 0x70)/16 ;#/slash for komodo syntax checker!
|
||||
my $snr = $typ % 16;
|
||||
|
||||
|
||||
#duplicate check (repeater?)
|
||||
my $prevmsg=$hash->{READINGS}{RAW}{VAL}||'';
|
||||
my $prevtime=$hash->{READINGS}{RAW}{TIME}||0;
|
||||
if (($prevmsg eq $msg) && ((time() - $prevtime) <10)) {
|
||||
Log 4,"$name check: Duplicate detected";
|
||||
return undef;
|
||||
}
|
||||
my $rawtext="Typ:$typ,W1:$w1,W2:$w2,W3:$w3,W4:$w4,W5:$w5";
|
||||
Log 4, "$name parsing: $rawtext";
|
||||
|
||||
#break into sensor specs
|
||||
switch ( $group ){
|
||||
case 7 {
|
||||
$sensor = "Fernbedienung";
|
||||
$shortname='FB';
|
||||
$einheit1='(CODE)';
|
||||
$daten1 = $w1 * 10000 + $w2 * 1000 + $w3 * 100 + $w4 * 10 + $w5;
|
||||
$result = $shortname . " => D=" . $daten1 . $einheit1;
|
||||
}
|
||||
case 0 {
|
||||
if ($snr < 8) {
|
||||
$sensor = "Temperatursensor V1.1(" . $snr . ")";
|
||||
}else{
|
||||
$snr -= 8;
|
||||
$sensor = "Temperatursensor V1.2(" .$snr. ")";
|
||||
}
|
||||
if ($w1 >= 64) {
|
||||
$daten1 = ((255 - $w1 - $w2) / 10) * (-1);
|
||||
}else{
|
||||
$daten1 = (($w1 * 128 + $w2) / 10);
|
||||
}
|
||||
$shortname='TX'.$snr;
|
||||
$einheit1 = " C";
|
||||
$result = $shortname . " => T:" . $daten1 . $einheit1;
|
||||
|
||||
}
|
||||
case 1 {
|
||||
if ($snr <8) {
|
||||
$sensor = "Temperatursensor mit Feuchte V1.1(" . $snr . ")";
|
||||
}else{
|
||||
$snr -= 8;
|
||||
$sensor = "Temperatursensor mit Feuchte V1.2(" . $snr . ")";
|
||||
}
|
||||
if ($w1 >= 64) {
|
||||
$daten1 = ((255 - $w1 - $w2) / 10) * (-1);
|
||||
}else{
|
||||
$daten1 = (($w1 * 128 + $w2) / 10);
|
||||
}
|
||||
$shortname='TH'.$snr;
|
||||
$einheit1 = " C";
|
||||
$daten2 = $w3;
|
||||
$daten3 = 0;
|
||||
$einheit2 = " %";
|
||||
|
||||
$result = $shortname . " => T:" . $daten1 . $einheit1 . ", H:" . $daten2 .$einheit2;
|
||||
|
||||
|
||||
}
|
||||
case 2 {
|
||||
if ( $snr < 8 ) {
|
||||
$sensor = "Regensensor V1.1(" . $snr . ")";
|
||||
}else{
|
||||
$snr -= 8;
|
||||
$sensor = "Regensensor V1.2(" . $snr . ")"
|
||||
}
|
||||
$shortname='R'.$snr;
|
||||
$daten1 = ($w1 * 128 + $w2);
|
||||
$einheit1= ' Imp';
|
||||
my $prev=$hash->{READINGS}{$shortname}{VAL};
|
||||
if ($prev && $prev=~/C=(\d+)/i) {
|
||||
$prev=$1;
|
||||
}else {
|
||||
$prev=0;
|
||||
}
|
||||
my $diff=$daten1-$prev;
|
||||
$daten2= $diff * $factor/1000;
|
||||
$einheit2 = " l/m2";
|
||||
$result = $shortname
|
||||
. " => M:".$daten2. $einheit2."(". $diff . $einheit1 ." x Faktor $factor)"
|
||||
. ", C:$daten1, P:$prev" ;
|
||||
|
||||
}
|
||||
case 3 {
|
||||
if ($snr < 8) {
|
||||
$sensor = "Windsensor V1.1(" . $snr . ")";
|
||||
}else{
|
||||
$snr -= 8;
|
||||
$sensor = "Windsensor V1.2(" . $snr . ")";
|
||||
}
|
||||
switch( $w3) {
|
||||
case 0 { $daten3 = 0;}
|
||||
case 1 { $daten3 = 22.5;}
|
||||
case 2 { $daten3 = 45;}
|
||||
case 3 { $daten3 = 67.5;}
|
||||
}
|
||||
$einheit3 = " +/-";
|
||||
$daten1 = ($w1 * 128 + $w2) / 10;
|
||||
$daten2 = $w4 * 128 + $w5;
|
||||
$einheit1 = " km/h";
|
||||
$einheit2 = " Grad";
|
||||
$shortname='W'.$snr;
|
||||
my @wr=("N","NNO","NO","ONO","O","OSO","SO","SSO","S","SSW","SW","WSW","W","WNW","NW","NNW");
|
||||
my @bf=(0,0.7,5.4,11.9,19.4,38.7,49.8,61.7,74.6,88.9,102.4,117.4);
|
||||
my @bfn=("Windstille","leiser Zug","leichte Brise","schwache Brise","maessige Brise","frische Brise",
|
||||
"starker Wind","steifer Wind","stuermischer Wind","Sturm","schwerer Sturm","orkanartiger Sturm","Orkan");
|
||||
my $i=1;
|
||||
foreach (1..$#bf) {
|
||||
if ($daten1<$bf[$i]) {
|
||||
last;
|
||||
}
|
||||
$i++;
|
||||
}
|
||||
$i--;
|
||||
#windrichtung
|
||||
my $w=int($daten2/22.5+0.5);
|
||||
if ($w ==16) {$w=0;}
|
||||
$result = $shortname
|
||||
. " => S:" . $daten1 . $einheit1
|
||||
. ", BF:$i($bfn[$i])"
|
||||
. " ,R:" . $daten2 . $einheit2
|
||||
. "($wr[$w])".$einheit3. $daten3;
|
||||
|
||||
}
|
||||
case 4 {
|
||||
if ($snr < 8) {
|
||||
$sensor = "Innensensor V1.1(" . $snr . ")";
|
||||
}else{
|
||||
$snr -= 8;
|
||||
$sensor = "Innensensor V1.2(" . $snr . ")";
|
||||
}
|
||||
if ($w1 >= 64) {
|
||||
$daten1 = ((255 - $w1 - $w2) / 10) * (-1);
|
||||
}else{
|
||||
$daten1 = (($w1 * 128 + $w2) / 10);
|
||||
}
|
||||
$shortname='I'.$snr;
|
||||
$daten2 = $w3;
|
||||
$daten3 = $w4 * 128 + $w5;
|
||||
$einheit1 = " C";
|
||||
$einheit2 = " %";
|
||||
$einheit3 = " hPa";
|
||||
$result = $shortname
|
||||
. " => T:" . $daten1 . $einheit1
|
||||
. ", H:" . $daten2 . $einheit2
|
||||
. ", D:" . $daten3 . $einheit3;
|
||||
|
||||
}
|
||||
case 5 {
|
||||
$snr -= 8 if $snr>7;; #only V1.2 sensors exists
|
||||
$sensor = "Helligkeitssensor V1.2(" . $snr . ")";
|
||||
$shortname='L'.$snr;
|
||||
switch ($w3) {
|
||||
case 0 {$daten1 = 1;}
|
||||
case 1 {$daten1 = 10;}
|
||||
case 2 {$daten1 = 100;}
|
||||
case 3 {$daten1 = 1000;}
|
||||
}
|
||||
$daten1 = $daten1 * ($w1 * 128 + $w2);
|
||||
$einheit1 = "Lux";
|
||||
$result = $shortname . " => L:" . $daten1 . $einheit1;
|
||||
|
||||
}
|
||||
case 6 {
|
||||
#Sensor has been never produced, but maybe there are personal implementations
|
||||
$snr -= 8 if $snr>7;
|
||||
$sensor = "Pyranometer V1.2(" . $snr . ")";
|
||||
$shortname='P'.$snr;
|
||||
switch ($w3) {
|
||||
case 0 {$daten1 = 1;}
|
||||
case 1 {$daten1 = 10;}
|
||||
case 2 {$daten1 = 100;}
|
||||
case 3 {$daten1 = 1000;}
|
||||
}
|
||||
$daten1 = $daten1 * ($w1 * 128 + $w2);
|
||||
$einheit1 = " W/m2";
|
||||
$result = $shortname . " => P:" . $daten1 . $einheit1;
|
||||
|
||||
}
|
||||
else {
|
||||
$shortname="U";
|
||||
$sensor = "unknown";
|
||||
$daten1 = $typ;
|
||||
$result = "(Group:" . $group . "/Typ:" . $typ . ")";
|
||||
Log 1, "$name => Unknown sensor detected". $result
|
||||
}#switch else
|
||||
|
||||
}#switch
|
||||
|
||||
#store result
|
||||
Log 4, $name." result:".$result;
|
||||
$rawtext='RAW => '.$rawtext;
|
||||
$hash->{READINGS}{LAST}{VAL}=$result;
|
||||
$hash->{READINGS}{LAST}{TIME}=$tm;
|
||||
$hash->{READINGS}{RAW}{TIME}=time();
|
||||
$hash->{READINGS}{RAW}{VAL}=$msg;
|
||||
$hash->{READINGS}{$shortname}{VAL}=$result;
|
||||
$hash->{READINGS}{$shortname}{TIME}=$tm;
|
||||
$hash->{STATE}=$result;
|
||||
$hash->{CHANGED}[0] = $result;
|
||||
$hash->{CHANGETIME}[0]=$tm;
|
||||
$hash->{CHANGED}[1] = $rawtext;
|
||||
$hash->{CHANGETIME}[1]=$tm;
|
||||
#notify system
|
||||
DoTrigger($name, undef);
|
||||
return $result;
|
||||
}
|
||||
#####################################
|
||||
sub
|
||||
WS2000_List($$)
|
||||
{
|
||||
my ($hash,$msg) = @_;
|
||||
$msg=WS2000_Get($hash,$hash->{NAME},'list');
|
||||
return $msg;
|
||||
}
|
||||
|
||||
|
||||
1;
|
|
@ -1,150 +0,0 @@
|
|||
|
||||
package main;
|
||||
##############################################
|
||||
# 88_IPWE.pm
|
||||
# Modul for FHEM
|
||||
#
|
||||
# contributed by thomas dressler 2008
|
||||
# $Id: 88_IPWE.pm,v 1.1 2008-05-18 12:05:24 tdressler Exp $
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
use IO::Socket::INET;
|
||||
|
||||
use vars qw {%attr $init_done}; #make komodo happy
|
||||
sub Log($$);
|
||||
#####################################
|
||||
|
||||
sub
|
||||
IPWE_Initialize($)
|
||||
{
|
||||
my ($hash) = @_;
|
||||
# Consumer
|
||||
$hash->{DefFn} = "IPWE_Define";
|
||||
$hash->{GetFn} = "IPWE_Get";
|
||||
$hash->{AttrList}= "model:ipwe delay loglevel:0,1,2,3,4,5,6";
|
||||
}
|
||||
|
||||
#####################################
|
||||
|
||||
sub
|
||||
IPWE_Define($$)
|
||||
{
|
||||
my ($hash, $def) = @_;
|
||||
my $name=$hash->{NAME};
|
||||
my @a = split("[ \t][ \t]*", $def);
|
||||
Log 5, "IPWE Define: $a[0] $a[1] $a[2] $a[3]";
|
||||
return "Define the host as a parameter i.e. ipwe" if(@a < 3);
|
||||
|
||||
my $host = $a[2];
|
||||
my $delay=$a[3];
|
||||
$attr{$name}{delay}=$delay if $delay;
|
||||
Log 1, "ipwe device is none, commands will be echoed only" if($host eq "none");
|
||||
|
||||
my $socket = IO::Socket::INET->new(PeerAddr=>$host,
|
||||
PeerPort=>80, #http
|
||||
timeout=>2,
|
||||
blocking=>1
|
||||
);
|
||||
|
||||
if (!$socket) {
|
||||
$hash->{STATE} = "error opening device";
|
||||
Log 1,"$name: Error opening Connection to $host";
|
||||
return "Can't Connect to $host -> $@ ( $!)\n";
|
||||
}
|
||||
$socket->close;
|
||||
$hash->{Host} = $host;
|
||||
$hash->{STATE} = "Initialized";
|
||||
InternalTimer(gettimeofday()+$delay, "IPWE_GetStatus", $hash, 0);
|
||||
return undef;
|
||||
|
||||
}
|
||||
|
||||
sub IPWE_Get($@)
|
||||
{
|
||||
my ($hash, @a) = @_;
|
||||
return "argument is missing" if(int(@a) != 2);
|
||||
my $msg;
|
||||
$hash->{LOCAL} = 1;
|
||||
my $v = IPWE_GetStatus($hash);
|
||||
delete $hash->{LOCAL};
|
||||
my @data=split (/\n/, $v);
|
||||
if($a[1] eq "status") {
|
||||
$msg= "$a[0] $a[1] =>".$/."$v";
|
||||
}else {
|
||||
my ($l)= grep {/$a[1]/}@data;
|
||||
chop($l);
|
||||
$msg="$a[0] $a[1] =>$l";
|
||||
}
|
||||
$msg="$a[0]: Unknown get command $a[1]" if (!$msg);
|
||||
return $msg;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#####################################
|
||||
|
||||
sub
|
||||
IPWE_GetStatus($)
|
||||
{
|
||||
my ($hash) = @_;
|
||||
|
||||
my $buf;
|
||||
Log 5, "IPWE_GetStatus";
|
||||
my $name = $hash->{NAME};
|
||||
my $host = $hash->{Host};
|
||||
my $text='';
|
||||
my $alldata='';
|
||||
|
||||
my $delay=$attr{$name}{delay}||300;
|
||||
InternalTimer(gettimeofday()+$delay, "IPWE_GetStatus", $hash, 0);
|
||||
my $socket = IO::Socket::INET->new(PeerAddr=>$host,
|
||||
PeerPort=>80, #http
|
||||
timeout=>2,
|
||||
blocking=>1
|
||||
);
|
||||
|
||||
if (!$socket) {
|
||||
$hash->{STATE} = "error opening device";
|
||||
Log 1,"$name: Error opening Connection to $host";
|
||||
return "Can't Connect to $host -> $@ ( $!)\n";
|
||||
}
|
||||
Log 5, "$name: Connected to $host";
|
||||
|
||||
$socket->autoflush(1);
|
||||
$socket->write("GET /ipwe.cgi HTTP/1.0\r\n");
|
||||
my @lines=$socket->getlines();
|
||||
close $socket;
|
||||
Log 5,"$name: Data received";
|
||||
|
||||
my $allines=join('',@lines);
|
||||
my (@tables)= ($allines=~m#<tbody>(?:(?!<tbody>).)*</tbody>#sgi);
|
||||
my ($datatable)=grep{/Sensortyp/} @tables;
|
||||
my (@rows)=($datatable=~m#<tr>(?:(?!<tr>).)*</tr>#sgi);
|
||||
foreach my $l(@rows) {
|
||||
next if ($l=~/Sensortyp/); #headline
|
||||
my ($typ,$id,$sensor,$temp,$hum,$wind,$rain)=($l=~m#<td.*?>(.*?)<br></td>#sgi);
|
||||
next if ($typ=~/^\s+$/);
|
||||
$text= "Typ: $typ, ID: $id, Name $sensor, T: $temp H: $hum";
|
||||
if ($id == 8) {
|
||||
$text.= ",W: $wind, R: $rain";
|
||||
}
|
||||
Log 5,"$name: $text";
|
||||
if (!$hash->{local}){
|
||||
$hash->{CHANGED}[0] = $text;
|
||||
$hash->{READINGS}{$sensor}{TIME} = TimeNow();
|
||||
$hash->{READINGS}{$sensor}{VAL} = $text;;
|
||||
DoTrigger($name, undef) if($init_done);
|
||||
}
|
||||
|
||||
$alldata.="$text\n";
|
||||
}
|
||||
return $alldata;
|
||||
}
|
||||
|
||||
|
||||
1;
|
||||
|
|
@ -1,120 +0,0 @@
|
|||
##############################################
|
||||
package main;
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
#####################################
|
||||
sub
|
||||
at_Initialize($)
|
||||
{
|
||||
my ($hash) = @_;
|
||||
|
||||
$hash->{DefFn} = "at_Define";
|
||||
$hash->{TimeFn} = "at_Exec";
|
||||
$hash->{AttrFn} = "at_Attr";
|
||||
$hash->{AttrList} = "disable:0,1 skip_next:0,1";
|
||||
}
|
||||
|
||||
|
||||
#####################################
|
||||
sub
|
||||
at_Define($$)
|
||||
{
|
||||
my ($hash, $def) = @_;
|
||||
my ($name, undef, $tm, $command) = split("[ \t]+", $def, 4);
|
||||
|
||||
if(!$command) {
|
||||
if($hash->{OLDDEF}) { # Called from modify, where command is optional
|
||||
(undef, $command) = split("[ \t]+", $hash->{OLDDEF}, 2);
|
||||
$hash->{DEF} = "$tm $command";
|
||||
} else {
|
||||
return "Usage: define <name> at <timespec> <command>";
|
||||
}
|
||||
}
|
||||
return "Wrong timespec, use \"[+][*[{count}]]<time or func>\""
|
||||
if($tm !~ m/^(\+)?(\*({\d+})?)?(.*)$/);
|
||||
my ($rel, $rep, $cnt, $tspec) = ($1, $2, $3, $4);
|
||||
my ($err, $hr, $min, $sec, $fn) = GetTimeSpec($tspec);
|
||||
return $err if($err);
|
||||
|
||||
$rel = "" if(!defined($rel));
|
||||
$rep = "" if(!defined($rep));
|
||||
$cnt = "" if(!defined($cnt));
|
||||
|
||||
my $ot = time;
|
||||
my @lt = localtime($ot);
|
||||
my $nt = $ot;
|
||||
|
||||
$nt -= ($lt[2]*3600+$lt[1]*60+$lt[0]) # Midnight for absolute time
|
||||
if($rel ne "+");
|
||||
$nt += ($hr*3600+$min*60+$sec); # Plus relative time
|
||||
$nt += 86400 if($ot >= $nt);# Do it tomorrow...
|
||||
|
||||
@lt = localtime($nt);
|
||||
my $ntm = sprintf("%02d:%02d:%02d", $lt[2], $lt[1], $lt[0]);
|
||||
|
||||
if($rep) { # Setting the number of repetitions
|
||||
$cnt =~ s/[{}]//g;
|
||||
return undef if($cnt eq "0");
|
||||
$cnt = 0 if(!$cnt);
|
||||
$cnt--;
|
||||
$hash->{REP} = $cnt;
|
||||
} else {
|
||||
$hash->{VOLATILE} = 1; # Write these entries to the statefile
|
||||
}
|
||||
$hash->{NTM} = $ntm if($rel eq "+" || $fn);
|
||||
$hash->{TRIGGERTIME} = $nt;
|
||||
$nextat = $nt if(!$nextat || $nextat > $nt);
|
||||
|
||||
$hash->{STATE} = "Next: " . FmtTime($nt);
|
||||
|
||||
return undef;
|
||||
}
|
||||
|
||||
sub
|
||||
at_Exec($)
|
||||
{
|
||||
my ($name) = @_;
|
||||
my ($skip, $disable);
|
||||
|
||||
if(defined($attr{$name})) {
|
||||
$skip = 1 if(defined($attr{$name}{skip_next}));
|
||||
$disable = 1 if(defined($attr{$name}{disable}));
|
||||
}
|
||||
|
||||
delete $attr{$name}{skip_next} if($skip);
|
||||
my (undef, $command) = split("[ \t]+", $defs{$name}{DEF}, 2);
|
||||
$command = SemicolonEscape($command);
|
||||
AnalyzeCommandChain(undef, $command) if(!$skip && !$disable);
|
||||
|
||||
my $count = $defs{$name}{REP};
|
||||
my $def = $defs{$name}{DEF};
|
||||
delete $defs{$name};
|
||||
|
||||
if($count) {
|
||||
$def =~ s/{\d+}/{$count}/ if($def =~ m/^\+?\*{/); # Replace the count }
|
||||
CommandDefine(undef, "$name at $def"); # Recompute the next TRIGGERTIME
|
||||
}
|
||||
}
|
||||
|
||||
sub
|
||||
at_Attr(@)
|
||||
{
|
||||
my @a = @_;
|
||||
my $do = 0;
|
||||
|
||||
if($a[0] eq "set" && $a[2] eq "disable") {
|
||||
$do = (!defined($a[3]) || $a[3]) ? 1 : 2;
|
||||
}
|
||||
$do = 2 if($a[0] eq "del" && (!$a[2] || $a[2] eq "disable"));
|
||||
return if(!$do);
|
||||
|
||||
$defs{$a[1]}{STATE} = ($do == 1 ?
|
||||
"disabled" :
|
||||
"Next: " . FmtTime($defs{$a[1]}{TRIGGERTIME}));
|
||||
|
||||
return undef;
|
||||
}
|
||||
|
||||
1;
|
|
@ -1,103 +0,0 @@
|
|||
##############################################
|
||||
package main;
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
#####################################
|
||||
sub
|
||||
notify_Initialize($)
|
||||
{
|
||||
my ($hash) = @_;
|
||||
|
||||
$hash->{DefFn} = "notify_Define";
|
||||
$hash->{NotifyFn} = "notify_Exec";
|
||||
$hash->{AttrFn} = "notify_Attr";
|
||||
$hash->{AttrList} = "disable:0,1";
|
||||
}
|
||||
|
||||
|
||||
#####################################
|
||||
sub
|
||||
notify_Define($$)
|
||||
{
|
||||
my ($hash, $def) = @_;
|
||||
my ($type, $name, $re, $command) = split("[ \t]+", $def, 4);
|
||||
|
||||
if(!$command) {
|
||||
if($hash->{OLDDEF}) { # Called from modify, where command is optional
|
||||
(undef, $command) = split("[ \t]+", $hash->{OLDDEF}, 2);
|
||||
$hash->{DEF} = "$re $command";
|
||||
} else {
|
||||
return "Usage: define <name> notify <regexp> <command>";
|
||||
}
|
||||
}
|
||||
|
||||
# Checking for misleading regexps
|
||||
eval { "Hallo" =~ m/^$re$/ };
|
||||
return "Bad regexp: $@" if($@);
|
||||
$hash->{REGEXP} = $re;
|
||||
$hash->{STATE} = "active";
|
||||
|
||||
return undef;
|
||||
}
|
||||
|
||||
#####################################
|
||||
sub
|
||||
notify_Exec($$)
|
||||
{
|
||||
my ($ntfy, $dev) = @_;
|
||||
|
||||
my $ln = $ntfy->{NAME};
|
||||
return "" if($attr{$ln} && $attr{$ln}{disable});
|
||||
|
||||
my $n = $dev->{NAME};
|
||||
my $re = $ntfy->{REGEXP};
|
||||
my $max = int(@{$dev->{CHANGED}});
|
||||
my $t = $dev->{TYPE};
|
||||
|
||||
my $ret = "";
|
||||
for (my $i = 0; $i < $max; $i++) {
|
||||
my $s = $dev->{CHANGED}[$i];
|
||||
$s = "" if(!defined($s));
|
||||
if($n =~ m/^$re$/ || "$n:$s" =~ m/^$re$/) {
|
||||
my (undef, $exec) = split("[ \t]+", $ntfy->{DEF}, 2);
|
||||
$exec = SemicolonEscape($exec);
|
||||
|
||||
$exec =~ s/%%/____/g;
|
||||
my $extsyntax= 0;
|
||||
$extsyntax+= ($exec =~ s/%TYPE/$t/g);
|
||||
$extsyntax+= ($exec =~ s/%NAME/$n/g);
|
||||
$extsyntax+= ($exec =~ s/%EVENT/$s/g);
|
||||
if(!$extsyntax) {
|
||||
$exec =~ s/%/$s/g;
|
||||
}
|
||||
$exec =~ s/____/%/g;
|
||||
|
||||
$exec =~ s/@@/____/g;
|
||||
$exec =~ s/@/$n/g;
|
||||
$exec =~ s/____/@/g;
|
||||
|
||||
my $r = AnalyzeCommandChain(undef, $exec);
|
||||
$ret .= " $r" if($r);
|
||||
}
|
||||
}
|
||||
return $ret;
|
||||
}
|
||||
|
||||
sub
|
||||
notify_Attr(@)
|
||||
{
|
||||
my @a = @_;
|
||||
my $do = 0;
|
||||
|
||||
if($a[0] eq "set" && $a[2] eq "disable") {
|
||||
$do = (!defined($a[3]) || $a[3]) ? 1 : 2;
|
||||
}
|
||||
$do = 2 if($a[0] eq "del" && (!$a[2] || $a[2] eq "disable"));
|
||||
return if(!$do);
|
||||
|
||||
$defs{$a[1]}{STATE} = ($do == 1 ? "disabled" : "active");
|
||||
return undef;
|
||||
}
|
||||
1;
|
|
@ -1,355 +0,0 @@
|
|||
##############################################
|
||||
package main;
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
use IO::File;
|
||||
|
||||
sub seekTo($$$$);
|
||||
|
||||
#####################################
|
||||
sub
|
||||
FileLog_Initialize($)
|
||||
{
|
||||
my ($hash) = @_;
|
||||
|
||||
$hash->{DefFn} = "FileLog_Define";
|
||||
$hash->{SetFn} = "FileLog_Set";
|
||||
$hash->{GetFn} = "FileLog_Get";
|
||||
$hash->{UndefFn} = "FileLog_Undef";
|
||||
$hash->{NotifyFn} = "FileLog_Log";
|
||||
$hash->{AttrFn} = "FileLog_Attr";
|
||||
# logtype is used by the frontend
|
||||
$hash->{AttrList} = "disable:0,1 logtype nrarchive archivedir archivecmd";
|
||||
}
|
||||
|
||||
|
||||
#####################################
|
||||
sub
|
||||
FileLog_Define($@)
|
||||
{
|
||||
my ($hash, $def) = @_;
|
||||
my @a = split("[ \t][ \t]*", $def);
|
||||
my $fh;
|
||||
|
||||
return "wrong syntax: define <name> FileLog filename regexp" if(int(@a) != 4);
|
||||
|
||||
eval { "Hallo" =~ m/^$a[3]$/ };
|
||||
return "Bad regexp: $@" if($@);
|
||||
|
||||
my @t = localtime;
|
||||
my $f = ResolveDateWildcards($a[2], @t);
|
||||
$fh = new IO::File ">>$f";
|
||||
return "Can't open $f" if(!defined($fh));
|
||||
|
||||
$hash->{FH} = $fh;
|
||||
$hash->{REGEXP} = $a[3];
|
||||
$hash->{logfile} = $a[2];
|
||||
$hash->{currentlogfile} = $f;
|
||||
$hash->{STATE} = "active";
|
||||
|
||||
return undef;
|
||||
}
|
||||
|
||||
#####################################
|
||||
sub
|
||||
FileLog_Undef($$)
|
||||
{
|
||||
my ($hash, $name) = @_;
|
||||
close($hash->{FH});
|
||||
return undef;
|
||||
}
|
||||
|
||||
#####################################
|
||||
sub
|
||||
FileLog_Log($$)
|
||||
{
|
||||
# Log is my entry, Dev is the entry of the changed device
|
||||
my ($log, $dev) = @_;
|
||||
|
||||
my $ln = $log->{NAME};
|
||||
return if($attr{$ln} && $attr{$ln}{disable});
|
||||
|
||||
my $n = $dev->{NAME};
|
||||
my $re = $log->{REGEXP};
|
||||
my $max = int(@{$dev->{CHANGED}});
|
||||
for (my $i = 0; $i < $max; $i++) {
|
||||
my $s = $dev->{CHANGED}[$i];
|
||||
$s = "" if(!defined($s));
|
||||
if($n =~ m/^$re$/ || "$n:$s" =~ m/^$re$/) {
|
||||
my $t = TimeNow();
|
||||
$t = $dev->{CHANGETIME}[$i] if(defined($dev->{CHANGETIME}[$i]));
|
||||
$t =~ s/ /_/; # Makes it easier to parse with gnuplot
|
||||
|
||||
my $fh = $log->{FH};
|
||||
my @t = localtime;
|
||||
my $cn = ResolveDateWildcards($log->{logfile}, @t);
|
||||
|
||||
if($cn ne $log->{currentlogfile}) { # New logfile
|
||||
$fh->close();
|
||||
HandleArchiving($log);
|
||||
$fh = new IO::File ">>$cn";
|
||||
if(!defined($fh)) {
|
||||
Log(0, "Can't open $cn");
|
||||
return;
|
||||
}
|
||||
$log->{currentlogfile} = $cn;
|
||||
$log->{FH} = $fh;
|
||||
}
|
||||
|
||||
print $fh "$t $n $s\n";
|
||||
$fh->flush;
|
||||
$fh->sync if !($^O eq 'MSWin32'); #not implemented in Windows
|
||||
}
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
###################################
|
||||
sub
|
||||
FileLog_Attr(@)
|
||||
{
|
||||
my @a = @_;
|
||||
my $do = 0;
|
||||
|
||||
if($a[0] eq "set" && $a[2] eq "disable") {
|
||||
$do = (!defined($a[3]) || $a[3]) ? 1 : 2;
|
||||
}
|
||||
$do = 2 if($a[0] eq "del" && (!$a[2] || $a[2] eq "disable"));
|
||||
return if(!$do);
|
||||
|
||||
$defs{$a[1]}{STATE} = ($do == 1 ? "disabled" : "active");
|
||||
|
||||
return undef;
|
||||
}
|
||||
|
||||
###################################
|
||||
sub
|
||||
FileLog_Set($@)
|
||||
{
|
||||
my ($hash, @a) = @_;
|
||||
|
||||
return "no set argument specified" if(int(@a) != 2);
|
||||
return "Unknown argument $a[1], choose one of reopen"
|
||||
if($a[1] ne "reopen");
|
||||
|
||||
my $fh = $hash->{FH};
|
||||
my $cn = $hash->{currentlogfile};
|
||||
$fh->close();
|
||||
$fh = new IO::File ">>$cn";
|
||||
return "Can't open $cn" if(!defined($fh));
|
||||
$hash->{FH} = $fh;
|
||||
return undef;
|
||||
}
|
||||
|
||||
###################################
|
||||
# We use this function to be able to scroll/zoom in the plots created from the
|
||||
# logfile. When outfile is specified, it is used with gnuplot post-processing,
|
||||
# when outfile is "-" it is used to create SVG graphics
|
||||
#
|
||||
# Up till now following functions are impemented:
|
||||
# - int (to cut off % from a number, as for the actuator)
|
||||
# - delta-h / delta-d to get rain/h and rain/d values from continuous data.
|
||||
|
||||
sub
|
||||
FileLog_Get($@)
|
||||
{
|
||||
my ($hash, @a) = @_;
|
||||
|
||||
return "Usage: get $a[0] <infile> <outfile> <from> <to> <column_spec>...\n".
|
||||
" where column_spec is <col>:<regexp>:<default>:<fn>\n" .
|
||||
" see the FileLogGrep entries in he .gplot files\n" .
|
||||
" <infile> is without direcory, - means the current file\n" .
|
||||
" <outfile> is a prefix, - means stdout\n"
|
||||
if(int(@a) < 5);
|
||||
|
||||
shift @a;
|
||||
my $inf = shift @a;
|
||||
my $outf = shift @a;
|
||||
my $from = shift @a;
|
||||
my $to = shift @a; # Now @a contains the list of column_specs
|
||||
|
||||
if($inf eq "-") {
|
||||
$inf = $hash->{currentlogfile};
|
||||
} else {
|
||||
my $linf = "$1/$inf" if($hash->{currentlogfile} =~ m,^(.*)/[^/]*$,);
|
||||
if(!-f $linf) {
|
||||
$linf = $attr{$hash->{NAME}}{archivedir} . "/" . $inf;
|
||||
return "Error: File-not-found" if(!-f $linf);
|
||||
}
|
||||
$inf = $linf;
|
||||
}
|
||||
my $ifh = new IO::File $inf;
|
||||
seekTo($inf, $ifh, $hash, $from);
|
||||
|
||||
#############
|
||||
# Digest the input.
|
||||
# last1: first delta value after d/h change
|
||||
# last2: last delta value recorded (for the very last entry)
|
||||
# last3: last delta timestamp (d or h)
|
||||
my (@d, @fname);
|
||||
for(my $i = 0; $i < int(@a); $i++) {
|
||||
my @fld = split(":", $a[$i], 4);
|
||||
|
||||
my %h;
|
||||
if($outf ne "-") {
|
||||
$fname[$i] = "$outf.$i";
|
||||
$h{fh} = new IO::File "> $fname[$i]";
|
||||
}
|
||||
$h{re} = $fld[1];
|
||||
$h{df} = defined($fld[2]) ? $fld[2] : "";
|
||||
$h{fn} = $fld[3];
|
||||
$h{didx} = 10 if($fld[3] && $fld[3] eq "delta-d");
|
||||
$h{didx} = 13 if($fld[3] && $fld[3] eq "delta-h");
|
||||
|
||||
if($fld[0] =~ m/"(.*)"/) {
|
||||
$h{col} = $1;
|
||||
$h{isfix} = 1;
|
||||
} else {
|
||||
$h{col} = $fld[0]-1;
|
||||
}
|
||||
$h{ret} = "";
|
||||
$d[$i] = \%h;
|
||||
}
|
||||
|
||||
my %lastdate;
|
||||
while(my $l = <$ifh>) {
|
||||
last if($l gt $to);
|
||||
my @fld = split("[ \r\n]+", $l);
|
||||
for my $i (0..int(@a)-1) { # Process each req. field
|
||||
my $h = $d[$i];
|
||||
my $re = $h->{re};
|
||||
next if($re && $l !~ m/$re/);
|
||||
|
||||
my $col = $h->{col};
|
||||
my $line = "";
|
||||
|
||||
if($h->{isfix}) { # Fixed text
|
||||
$line = "$fld[0] $col";
|
||||
|
||||
} elsif(!$h->{fn}) { # The column
|
||||
$line = "$fld[0] $fld[$col]";
|
||||
|
||||
} elsif($h->{didx}) { # delta-h or delta-d
|
||||
|
||||
my $hd = $h->{didx};
|
||||
my $ld = substr($fld[0],0,$hd);
|
||||
if(!defined($h->{last1}) || $h->{last3} ne $ld) {
|
||||
if(defined($h->{last1})) {
|
||||
my @lda = split("[_:]", $lastdate{$hd});
|
||||
my $ts = "12:00:00"; # middle timestamp
|
||||
$ts = "$lda[1]:30:00" if($hd == 13);
|
||||
my $v = $fld[$col]-$h->{last1};
|
||||
$v = 0 if($v < 0); # Skip negative delta
|
||||
$line = sprintf("%s_%s %0.1f", $lda[0],$ts, $v);
|
||||
}
|
||||
$h->{last1} = $fld[$col];
|
||||
$h->{last3} = $ld;
|
||||
}
|
||||
$h->{last2} = $fld[$col];
|
||||
$lastdate{$hd} = $fld[0];
|
||||
|
||||
} elsif($h->{fn} eq "int") { # int function
|
||||
my $val = $fld[$col];
|
||||
$line = "$fld[0] $1" if($val =~ m/^([0-9]+).*/);
|
||||
|
||||
} else {
|
||||
$line = "$fld[0] " . eval($h->{fn});
|
||||
}
|
||||
|
||||
next if(!$line);
|
||||
|
||||
$h->{count}++;
|
||||
$line .= "\n";
|
||||
if($outf eq "-") {
|
||||
$h->{ret} .= $line;
|
||||
} else {
|
||||
my $fh = $h->{fh};
|
||||
print $fh $line;
|
||||
}
|
||||
}
|
||||
}
|
||||
$ifh->close();
|
||||
|
||||
my $ret = "";
|
||||
for(my $i = 0; $i < int(@a); $i++) {
|
||||
my $h = $d[$i];
|
||||
my $hd = $h->{didx};
|
||||
if($hd && $lastdate{$hd}) {
|
||||
my $val = defined($h->{last1}) ? $h->{last2}-$h->{last1} : 0;
|
||||
|
||||
my @lda = split("[_:]", $lastdate{$hd});
|
||||
my $ts = "12:00:00"; # middle timestamp
|
||||
$ts = "$lda[1]:30:00" if($hd == 13);
|
||||
my $line = sprintf("%s_%s %0.1f\n", $lda[0],$ts, $h->{last2}-$h->{last1});
|
||||
|
||||
if($outf eq "-") {
|
||||
$h->{ret} .= $line;
|
||||
$h->{count}++;
|
||||
} else {
|
||||
my $fh = $h->{fh};
|
||||
print $fh $line;
|
||||
$h->{count}++;
|
||||
}
|
||||
}
|
||||
if($outf eq "-") {
|
||||
$h->{ret} .= "$from $h->{df}\n" if(!$h->{count} && $h->{df} ne "");
|
||||
$ret .= $h->{ret} if($h->{ret});
|
||||
$ret .= "#$a[$i]\n";
|
||||
} else {
|
||||
my $fh = $h->{fh};
|
||||
#Log 0, "FLg: $i: >$h->{count}, $h->{df}<";
|
||||
if(!$h->{count} && $h->{df} ne "") {
|
||||
print $fh "$from $h->{df}\n";
|
||||
}
|
||||
$fh->close();
|
||||
}
|
||||
}
|
||||
|
||||
return ($outf eq "-") ? $ret : join(" ", @fname);
|
||||
}
|
||||
|
||||
###################################
|
||||
sub
|
||||
seekTo($$$$)
|
||||
{
|
||||
my ($fname, $fh, $hash, $ts) = @_;
|
||||
|
||||
# If its cached
|
||||
if($hash->{pos} && $hash->{pos}{"$fname:$ts"}) {
|
||||
$fh->seek($hash->{pos}{"$fname:$ts"}, 0);
|
||||
return;
|
||||
}
|
||||
|
||||
$fh->seek(0, 2); # Go to the end
|
||||
my $upper = $fh->tell;
|
||||
|
||||
my ($lower, $next, $last) = (0, $upper/2, 0);
|
||||
while() { # Binary search
|
||||
$fh->seek($next, 0);
|
||||
my $data = <$fh>;
|
||||
if($data !~ m/^20\d\d-\d\d-\d\d_\d\d:\d\d:\d\d /) {
|
||||
$next = $fh->tell;
|
||||
$data = <$fh>;
|
||||
if(!$data) {
|
||||
$last = $next;
|
||||
last;
|
||||
}
|
||||
}
|
||||
if($next eq $last) {
|
||||
$fh->seek($next, 0);
|
||||
last;
|
||||
}
|
||||
|
||||
$last = $next;
|
||||
if(!$data || $data lt $ts) {
|
||||
($lower, $next) = ($next, ($next+$upper)/2);
|
||||
} else {
|
||||
($upper, $next) = ($next, ($lower+$next)/2);
|
||||
}
|
||||
}
|
||||
$hash->{pos}{"$fname:$ts"} = $last;
|
||||
|
||||
}
|
||||
|
||||
1;
|
|
@ -1,47 +0,0 @@
|
|||
##############################################
|
||||
package main;
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
sub
|
||||
dummy_Initialize($)
|
||||
{
|
||||
my ($hash) = @_;
|
||||
|
||||
$hash->{SetFn} = "dummy_Set";
|
||||
$hash->{DefFn} = "dummy_Define";
|
||||
}
|
||||
|
||||
###################################
|
||||
sub
|
||||
dummy_Set($@)
|
||||
{
|
||||
my ($hash, @a) = @_;
|
||||
|
||||
return "no set value specified" if(int(@a) != 2);
|
||||
return "Unknown argument $a[1], choose one of *" if($a[1] eq "?");
|
||||
|
||||
|
||||
my $v = $a[1];
|
||||
|
||||
Log GetLogLevel($a[0],2), "dummy set $v";
|
||||
|
||||
$hash->{CHANGED}[0] = $v;
|
||||
$hash->{STATE} = $v;
|
||||
$hash->{READINGS}{state}{TIME} = TimeNow();
|
||||
$hash->{READINGS}{state}{VAL} = $v;
|
||||
return undef;
|
||||
}
|
||||
|
||||
sub
|
||||
dummy_Define($$)
|
||||
{
|
||||
my ($hash, $def) = @_;
|
||||
my @a = split("[ \t][ \t]*", $def);
|
||||
|
||||
return "Wrong syntax: use define <name> dummy" if(int(@a) != 2);
|
||||
return undef;
|
||||
}
|
||||
|
||||
1;
|
|
@ -1,333 +0,0 @@
|
|||
##############################################
|
||||
# - Please call sunrise_coord before using this module, else you'll get times
|
||||
# for frankfurt am main (germany). See the "at" entry in commandref.html
|
||||
#
|
||||
# This code is derived from DateTime::Event::Sunrise, version 0.0501.
|
||||
# Simplified and removed further package # dependency (DateTime,
|
||||
# Params::Validate, etc). For comments see the original code.
|
||||
#
|
||||
|
||||
package main;
|
||||
use strict;
|
||||
use warnings;
|
||||
use Math::Trig;
|
||||
|
||||
sub sr($$$$);
|
||||
sub sunrise_rel(@);
|
||||
sub sunset_rel(@);
|
||||
sub sunrise_abs(@);
|
||||
sub sunset_abs(@);
|
||||
sub isday();
|
||||
sub sunrise_coord($$$);
|
||||
sub SUNRISE_Initialize($);
|
||||
|
||||
# See perldoc DateTime::Event::Sunrise for details
|
||||
my $long = "8.686";
|
||||
my $lat = "50.112";
|
||||
my $tz = ""; # will be overwritten
|
||||
my $altit = "-6"; # Civil twilight
|
||||
my $RADEG = ( 180 / 3.1415926 );
|
||||
my $DEGRAD = ( 3.1415926 / 180 );
|
||||
my $INV360 = ( 1.0 / 360.0 );
|
||||
|
||||
|
||||
sub
|
||||
SUNRISE_EL_Initialize($)
|
||||
{
|
||||
my ($hash) = @_;
|
||||
}
|
||||
|
||||
##########################
|
||||
# Compute:
|
||||
# rise: 1: event is sunrise (else sunset)
|
||||
# isrel: 1: _relative_ times until the next event (else absolute for today)
|
||||
# seconds: second offset to event
|
||||
# daycheck: if set, then return 1 if the sun is visible, 0 else
|
||||
sub
|
||||
sr($$$$)
|
||||
{
|
||||
my ($rise, $seconds, $isrel, $daycheck) = @_;
|
||||
my $needrise = ($rise || $daycheck) ? 1 : 0;
|
||||
my $needset = (!$rise || $daycheck) ? 1 : 0;
|
||||
|
||||
my $nt = time;
|
||||
my @lt = localtime($nt);
|
||||
my $gmtoff = _calctz($nt,@lt); # in hour
|
||||
my ($rt,$st) = _sr($needrise,$needset, $lt[5]+1900,$lt[4]+1,$lt[3], $gmtoff);
|
||||
|
||||
my $nh = $lt[2] + $lt[1]/60 + $lt[0]/3600;
|
||||
if($daycheck) {
|
||||
return 0 if($nh < $rt || $nh > $st);
|
||||
return 1;
|
||||
}
|
||||
|
||||
$seconds = 0 if(!$seconds);
|
||||
my $sst = ($rise ? $rt : $st);
|
||||
if(!$isrel) {
|
||||
$sst += ($seconds/3600);
|
||||
return h2hms_fmt($sst);
|
||||
}
|
||||
|
||||
$sst += ($seconds/3600);
|
||||
|
||||
my $diff = 0;
|
||||
if(int(($nh-$sst)*3600) >= 0) {
|
||||
$nt += 86400; # Tommorow
|
||||
$diff = 24;
|
||||
@lt = localtime($nt);
|
||||
$gmtoff = _calctz($nt,@lt); # in hour
|
||||
|
||||
($rt,$st) = _sr($needrise,$needset, $lt[5]+1900,$lt[4]+1,$lt[3], $gmtoff);
|
||||
|
||||
$sst = ($rise ? $rt : $st);
|
||||
$sst += ($seconds/3600);
|
||||
}
|
||||
|
||||
$diff = $diff + $sst - $nh;
|
||||
return h2hms_fmt($diff);
|
||||
}
|
||||
|
||||
sub
|
||||
_sr($$$$$$)
|
||||
{
|
||||
my ($needrise, $needset, $y, $m, $dy, $offset) = @_;
|
||||
|
||||
my $d = _days_since_2000_Jan_0($y,$m,$dy) + 0.5 - $long / 360.0;
|
||||
my ( $tmp_rise_1, $tmp_set_1 ) =
|
||||
_sunrise_sunset( $d, $long, $lat, $altit, 15.04107 );
|
||||
|
||||
my ($tmp_rise_2, $tmp_rise_3) = (0,0);
|
||||
|
||||
if($needrise) {
|
||||
$tmp_rise_2 = 9; $tmp_rise_3 = 0;
|
||||
until ( _equal( $tmp_rise_2, $tmp_rise_3, 8 ) ) {
|
||||
|
||||
my $d_sunrise_1 = $d + $tmp_rise_1 / 24.0;
|
||||
( $tmp_rise_2, undef ) =
|
||||
_sunrise_sunset( $d_sunrise_1, $long,
|
||||
$lat, $altit, 15.04107 );
|
||||
$tmp_rise_1 = $tmp_rise_3;
|
||||
my $d_sunrise_2 = $d + $tmp_rise_2 / 24.0;
|
||||
( $tmp_rise_3, undef ) =
|
||||
_sunrise_sunset( $d_sunrise_2, $long,
|
||||
$lat, $altit, 15.04107 );
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
my ($tmp_set_2, $tmp_set_3) = (0,0);
|
||||
if($needset) {
|
||||
$tmp_set_2 = 9; $tmp_set_3 = 0;
|
||||
until ( _equal( $tmp_set_2, $tmp_set_3, 8 ) ) {
|
||||
|
||||
my $d_sunset_1 = $d + $tmp_set_1 / 24.0;
|
||||
( undef, $tmp_set_2 ) =
|
||||
_sunrise_sunset( $d_sunset_1, $long,
|
||||
$lat, $altit, 15.04107 );
|
||||
$tmp_set_1 = $tmp_set_3;
|
||||
my $d_sunset_2 = $d + $tmp_set_2 / 24.0;
|
||||
( undef, $tmp_set_3 ) =
|
||||
_sunrise_sunset( $d_sunset_2, $long,
|
||||
$lat, $altit, 15.04107 );
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
return $tmp_rise_3+$offset, $tmp_set_3+$offset;
|
||||
}
|
||||
|
||||
|
||||
|
||||
sub
|
||||
_sunrise_sunset($$$$$)
|
||||
{
|
||||
my ( $d, $lon, $lat, $altit, $h ) = @_;
|
||||
|
||||
my $sidtime = _revolution( _GMST0($d) + 180.0 + $lon );
|
||||
|
||||
my ( $sRA, $sdec ) = _sun_RA_dec($d);
|
||||
my $tsouth = 12.0 - _rev180( $sidtime - $sRA ) / $h;
|
||||
my $sradius = 0.2666 / $sRA;
|
||||
|
||||
$altit -= $sradius;
|
||||
|
||||
# Compute the diurnal arc that the Sun traverses to reach
|
||||
# the specified altitude altit:
|
||||
|
||||
my $cost =
|
||||
( sind($altit) - sind($lat) * sind($sdec) ) /
|
||||
( cosd($lat) * cosd($sdec) );
|
||||
|
||||
my $t;
|
||||
if ( $cost >= 1.0 ) {
|
||||
$t = 0.0; # Sun always below altit
|
||||
}
|
||||
elsif ( $cost <= -1.0 ) {
|
||||
$t = 12.0; # Sun always above altit
|
||||
}
|
||||
else {
|
||||
$t = acosd($cost) / 15.0; # The diurnal arc, hours
|
||||
}
|
||||
|
||||
# Store rise and set times - in hours UT
|
||||
|
||||
my $hour_rise_ut = $tsouth - $t;
|
||||
my $hour_set_ut = $tsouth + $t;
|
||||
return ( $hour_rise_ut, $hour_set_ut );
|
||||
|
||||
}
|
||||
|
||||
sub
|
||||
_GMST0($)
|
||||
{
|
||||
my ($d) = @_;
|
||||
|
||||
my $sidtim0 =
|
||||
_revolution( ( 180.0 + 356.0470 + 282.9404 ) +
|
||||
( 0.9856002585 + 4.70935E-5 ) * $d );
|
||||
return $sidtim0;
|
||||
|
||||
}
|
||||
|
||||
sub
|
||||
_sunpos($)
|
||||
{
|
||||
my ($d) = @_;
|
||||
|
||||
my $Mean_anomaly_of_sun = _revolution( 356.0470 + 0.9856002585 * $d );
|
||||
my $Mean_longitude_of_perihelion = 282.9404 + 4.70935E-5 * $d;
|
||||
my $Eccentricity_of_Earth_orbit = 0.016709 - 1.151E-9 * $d;
|
||||
|
||||
# Compute true longitude and radius vector
|
||||
my $Eccentric_anomaly =
|
||||
$Mean_anomaly_of_sun + $Eccentricity_of_Earth_orbit * $RADEG *
|
||||
sind($Mean_anomaly_of_sun) *
|
||||
( 1.0 + $Eccentricity_of_Earth_orbit * cosd($Mean_anomaly_of_sun) );
|
||||
|
||||
my $x = cosd($Eccentric_anomaly) - $Eccentricity_of_Earth_orbit;
|
||||
|
||||
my $y =
|
||||
sqrt( 1.0 - $Eccentricity_of_Earth_orbit * $Eccentricity_of_Earth_orbit )
|
||||
* sind($Eccentric_anomaly);
|
||||
|
||||
my $Solar_distance = sqrt( $x * $x + $y * $y ); # Solar distance
|
||||
my $True_anomaly = atan2d( $y, $x ); # True anomaly
|
||||
|
||||
my $True_solar_longitude =
|
||||
$True_anomaly + $Mean_longitude_of_perihelion; # True solar longitude
|
||||
|
||||
if ( $True_solar_longitude >= 360.0 ) {
|
||||
$True_solar_longitude -= 360.0; # Make it 0..360 degrees
|
||||
}
|
||||
|
||||
return ( $Solar_distance, $True_solar_longitude );
|
||||
}
|
||||
|
||||
sub
|
||||
_sun_RA_dec($)
|
||||
{
|
||||
my ($d) = @_;
|
||||
|
||||
my ( $r, $lon ) = _sunpos($d);
|
||||
|
||||
my $x = $r * cosd($lon);
|
||||
my $y = $r * sind($lon);
|
||||
|
||||
my $obl_ecl = 23.4393 - 3.563E-7 * $d;
|
||||
|
||||
my $z = $y * sind($obl_ecl);
|
||||
$y = $y * cosd($obl_ecl);
|
||||
|
||||
my $RA = atan2d( $y, $x );
|
||||
my $dec = atan2d( $z, sqrt( $x * $x + $y * $y ) );
|
||||
|
||||
return ( $RA, $dec );
|
||||
}
|
||||
|
||||
sub
|
||||
_days_since_2000_Jan_0($$$)
|
||||
{
|
||||
my ($y, $m, $d) = @_;
|
||||
my @mn = (31,28,31,30,31,30,31,31,30,31,30,31);
|
||||
|
||||
my $ms = 0;
|
||||
for(my $i = 0; $i < $m-1; $i++) {
|
||||
$ms += $mn[$i];
|
||||
}
|
||||
my $x = ($y-2000)*365.25 + $ms + $d;
|
||||
$x++ if($m > 2 && ($y%4) == 0);
|
||||
return int($x);
|
||||
}
|
||||
|
||||
sub sind($) { sin( ( $_[0] ) * $DEGRAD ); }
|
||||
sub cosd($) { cos( ( $_[0] ) * $DEGRAD ); }
|
||||
sub tand($) { tan( ( $_[0] ) * $DEGRAD ); }
|
||||
sub atand($) { ( $RADEG * atan( $_[0] ) ); }
|
||||
sub asind($) { ( $RADEG * asin( $_[0] ) ); }
|
||||
sub acosd($) { ( $RADEG * acos( $_[0] ) ); }
|
||||
sub atan2d($$) { ( $RADEG * atan2( $_[0], $_[1] ) ); }
|
||||
|
||||
sub
|
||||
_revolution($)
|
||||
{
|
||||
my $x = $_[0];
|
||||
return ( $x - 360.0 * int( $x * $INV360 ) );
|
||||
}
|
||||
|
||||
sub
|
||||
_rev180($)
|
||||
{
|
||||
my ($x) = @_;
|
||||
return ( $x - 360.0 * int( $x * $INV360 + 0.5 ) );
|
||||
}
|
||||
|
||||
sub
|
||||
_equal($$$)
|
||||
{
|
||||
my ( $A, $B, $dp ) = @_;
|
||||
return sprintf( "%.${dp}g", $A ) eq sprintf( "%.${dp}g", $B );
|
||||
}
|
||||
|
||||
sub
|
||||
_calctz($@)
|
||||
{
|
||||
my ($nt,@lt) = @_;
|
||||
|
||||
my $off = $lt[2]*3600+$lt[1]*60+$lt[0];
|
||||
$off = 12*3600-$off;
|
||||
$nt += $off; # This is noon, localtime
|
||||
|
||||
my @gt = gmtime($nt);
|
||||
|
||||
return (12-$gt[2]);
|
||||
}
|
||||
|
||||
|
||||
sub
|
||||
h2hms($)
|
||||
{
|
||||
my ($in) = @_;
|
||||
my ($h,$m,$s);
|
||||
$h = int($in);
|
||||
$m = int(60*($in-$h));
|
||||
$s = int(3600*($in-$h)-60*$m);
|
||||
return ($h, $m, $s);
|
||||
}
|
||||
|
||||
sub
|
||||
h2hms_fmt($)
|
||||
{
|
||||
my ($in) = @_;
|
||||
my ($h,$m,$s) = h2hms($in);
|
||||
return sprintf("%02d:%02d:%02d", $h, $m, $s);
|
||||
}
|
||||
|
||||
|
||||
sub sunrise_rel(@) { return sr(1, shift, 1, 0) }
|
||||
sub sunset_rel(@) { return sr(0, shift, 1, 0) }
|
||||
sub sunrise_abs(@) { return sr(1, shift, 0, 0) }
|
||||
sub sunset_abs(@) { return sr(0, shift, 0, 0) }
|
||||
sub isday() { return sr(1, 0, 0, 1) }
|
||||
sub sunrise_coord($$$) { ($long, $lat, $tz) = @_; return undef; }
|
||||
|
||||
1;
|
|
@ -1,20 +0,0 @@
|
|||
package main;
|
||||
use strict;
|
||||
use warnings;
|
||||
use POSIX;
|
||||
|
||||
sub
|
||||
Utils_Initialize($$)
|
||||
{
|
||||
my ($hash) = @_;
|
||||
}
|
||||
|
||||
sub
|
||||
time_str2num($)
|
||||
{
|
||||
my ($str) = @_;
|
||||
my @a = split("[- :]", $str);
|
||||
return mktime($a[5],$a[4],$a[3],$a[2],$a[1]-1,$a[0]-1900,0,0,-1);
|
||||
}
|
||||
|
||||
1;
|
307
fhem/HISTORY
307
fhem/HISTORY
|
@ -1,307 +0,0 @@
|
|||
- Rudi, Thu Feb 1 13:27:15 MET 2007
|
||||
Created the file HISTORY and the file README.DEV
|
||||
|
||||
- Pest, Thu Feb 1 20:45 MET 2007
|
||||
Added description for attribute ,
|
||||
|
||||
- Rudi, Sun Feb 11 18:56:05 MET 2007
|
||||
- showtime added for pgm2 (useful for FS20 piri display)
|
||||
- defattr command added, it makes easier to assign room, type, etc for a group
|
||||
of devices.
|
||||
- em1010.pl added to the contrib directory. It seems that we are able
|
||||
to read out the EM1010PC. Not verified with multiple devices.
|
||||
|
||||
- Pest, Thu Feb 11 23:35 MET 2007
|
||||
- Added doc/linux.html (multiple USDB devices, udev links)
|
||||
- Linked fhem.html and commandref.html to linux.html
|
||||
|
||||
- Martin Haas, Fri Feb 23 10:18 MET 2007
|
||||
- ARM-Section (NSLU2) added to doc/linux.html
|
||||
|
||||
- Pest, Sat Feb 24 18:30 MET 2007
|
||||
- doc/linux.html: Module build re-written.
|
||||
|
||||
- Rudi, Sun Mar 4 11:18:10 MET 2007
|
||||
Reorganization. Goal: making attribute adding/deleting more uniform
|
||||
(,
|
||||
possible (i.e. saving the configfile, list of possible devices etc).
|
||||
|
||||
Internal changes:
|
||||
- %logmods,%devmods moved to %modules. Makes things more uniform
|
||||
- %logs merged into %defs
|
||||
- local state info (%readings) changed to global ($defs{$d}{READINGS})
|
||||
-> No need for the listfn function in each module
|
||||
-> User written scripts can more easily analyze device states
|
||||
|
||||
User visible changes:
|
||||
- at/notify ,
|
||||
modules. Now it is possible
|
||||
- to have a further ,
|
||||
(notify & filelog use the same interface)
|
||||
- to have more than one notify for the same event
|
||||
- to delete at commands without strange escapes.
|
||||
The delete syntax changed (no more def/at/ntfy needed)
|
||||
- at/notify can have attributes
|
||||
Drawback: each at and notify must have a name, which is strange first.
|
||||
- logfile/modpath/pidfile/port/verbose ,
|
||||
Dumping and extending these attributes is easier, no special handling
|
||||
required in the web-frontend.
|
||||
- savefile renamed to ,
|
||||
- configfile global attribute added.
|
||||
- save command added, it writes the statefile and then the configfile.
|
||||
- delattr added to delete single attributes
|
||||
- list/xmllist format changed, they contain more information.
|
||||
- ,
|
||||
in the same format. This data is contained in the xmllist.
|
||||
- disable attribute for at/notify/filelog
|
||||
- rename added
|
||||
|
||||
- Rudi, Tue Mar 27 20:43:15 MEST 2007
|
||||
fhemweb.pl (webpgm2) changes:
|
||||
- adopted to the new syntax
|
||||
- better commandline support (return <pre> formatted)
|
||||
- FileLog attribute logtype added, and 4 logtypes (== gnuplot files)
|
||||
defined: fs20, fht, ks300_1, ks300_2
|
||||
- links in the commandref.html file added
|
||||
- device dependent attribute and set support
|
||||
|
||||
- Pest, Sun Apr 08 17:55:15 MEST 2007
|
||||
em1010.pl:
|
||||
- Make difference between sensors 1..4 and 5..
|
||||
- Checked values for sensor 5 (cur.energy + cur.power) - ok
|
||||
- Checked values for sensor 5 cur.energy is ok, cur.power still off.
|
||||
Correction factor needs to be determined.
|
||||
- setTime: Without argument, now the current time of the PC is used.
|
||||
- setRperKW: Factor of 10 required, 75 U/kWh -> 750.
|
||||
|
||||
- Pest, Tue Apr 10 20:31:22 MEST 2007
|
||||
em1010.pl:
|
||||
- Introduced new double-word function (dw)
|
||||
- getDevStatus: energy values kWh/h, kWh/d, total.
|
||||
|
||||
- Rudi Sat Apr 14 10:34:36 MEST 2007
|
||||
final documentations, release 4.0. Tagged as FHEM_4_0
|
||||
|
||||
- Pest, Sat Apr 14 14:21:00 MEST 2007
|
||||
- doc: linux.html (private udev-rules, not 50-..., ATTRS)
|
||||
|
||||
- Pest, Sun Apr 15 14:54:30 MEST 2007
|
||||
- doc: fhem.pl and commandref.html (notifyon -> notify, correction of examples)
|
||||
|
||||
- Rudi, Tue Apr 24 08:10:43 MEST 2007
|
||||
- feature: modify command added. It helps change e.g. only the time component
|
||||
for an at command, without deleting and creating it again and then
|
||||
reapplying all the attributes.
|
||||
- feature: the ,
|
||||
instead. The - is used to separate ranges in the set command.
|
||||
|
||||
- Rudi, Sun May 27 12:51:52 MEST 2007
|
||||
- Archiving FileLogs. Added fhemweb.pl (pgm2) code, to show logs from the
|
||||
archive directory. See the attributes archivedir/archivecmd.
|
||||
- Added EM1010PC suppoort (right now only with EM1000WZ). Support added
|
||||
for displaying logs in the fhemweb.pl (webfrontends/pgm2)
|
||||
|
||||
- Pest, Mon May 28 19:39:22 MEST 2007
|
||||
- Added 62_EMEM.pm to support EM1000-EM devices.
|
||||
- doc: Update of commandref.htm (typos and EMEM).
|
||||
|
||||
- Pest, Mon May 29 00:07:00 MEST 2007
|
||||
- check-in changes of 60_EM.pm to make EMEM work.
|
||||
|
||||
- Mon Jun 4 08:23:43 MEST 2007
|
||||
- Small changes for EM logging
|
||||
|
||||
- Pest Jun 10, 23:16:23 MEST 2007
|
||||
- Set wrong values in 62_EMEM to -1
|
||||
|
||||
- Pest Jun 12, 21:33:00 MEST 2007
|
||||
- in 62_EMEM.pm: added energy_today and energy_total
|
||||
|
||||
- Pest Jun 18, 20:06:23 MEST 2007
|
||||
- in 62_EMEM.pm: Power units removed from value content added to name.
|
||||
|
||||
- Rudi Sun Aug 5 10:59:51 MEST 2007
|
||||
- WS300 Loglevel changed for KS300 device (from 2 to GetLogLevel or 5)
|
||||
- First version of the FritzBox port:
|
||||
- Perl binary/ftdi_sio module
|
||||
- EM: added setTime, reset
|
||||
- docs/fritzbox.html. Note: The fb_fhem_0.1.tar.gz won't be part of CVS
|
||||
as it contains largee binaries (swapfile, perl mipsel executable, etc).
|
||||
|
||||
- Rudi Mon Aug 6 20:15:00 MEST 2007
|
||||
- archiving added to the main logs.
|
||||
NOTE: The FileLog filename (INT attribute) is now also called logfile.
|
||||
|
||||
- Rudi Wed Aug 29 08:28:34 MEST 2007
|
||||
- archive attributes clarified in the doc
|
||||
|
||||
- Rudi Mon Sep 3 15:47:59 MEST 2007
|
||||
- 99_Sunrise_EL.pm checked in. Replaces 99_Sunrise.pm, and does not need
|
||||
any Date module.
|
||||
|
||||
- Rudi Sun Sep 9 08:43:03 MEST 2007
|
||||
- mode holiday_short added + documentation. Not tested.
|
||||
any Date module.
|
||||
|
||||
- Rudi Wed Oct 3 18:21:36 MEST 2007
|
||||
- weblinks added. Used by webpgm2 to display more than one plot at once
|
||||
- webpgm2 output reformatted. Using CSS to divide the screen area in 3
|
||||
parts: command line, room-list and rest
|
||||
|
||||
- Dirk Wed Oct 7 12:45:09 MEST 2007
|
||||
- FHT lime-protection code discovered
|
||||
|
||||
- Dirk Wed Oct 18 23:28:00 MEST 2007
|
||||
- Softwarebuffer for FHT devices with queuing unsent commands and
|
||||
repeating commands by transmission failure
|
||||
- FHT low temperatur warning and setting for lowtemp-offset
|
||||
- Change naming for state into warnings
|
||||
Tagged as dirkh_20071019_0
|
||||
|
||||
- Martin Fri Dec 21 13:39:17 CET 2007
|
||||
- voip2fhem added (contrib/)
|
||||
|
||||
- Peter Sun Dec 23 19:59:00 MEST 2007
|
||||
- linux.html: Introduction refinement.
|
||||
|
||||
- Rudi Sat Dec 29 16:27:14 MET 2007
|
||||
- delattr renamed to deleteattr, as del should complete to delete and not to
|
||||
delattr
|
||||
- defattr renamed to setdefaultattr (same as before for def)
|
||||
- devicespec introduced:
|
||||
it may contain a list of devices, a range of devices, or multiple devices
|
||||
identified by regexp. Following commands take a devicespec as argument:
|
||||
attr, deleteattr, delete, get, list, set, setstate, trigger
|
||||
|
||||
- Boris Sat Dec 29 16:56:00 CET 2007
|
||||
- %NAME, %EVENT, %TYPE parameters in notify definition, commandref.html update
|
||||
|
||||
- Boris Sun Dec 30 22:35:00 CET 2007
|
||||
- added dblog/93_DbLog.pm and samples in contrib directory, commandref.html
|
||||
update
|
||||
|
||||
- Rudi Mon Dec 31 15:37:19 MET 2007
|
||||
- feature: webfrontend/pgm2 converted to a FHEM module
|
||||
No more need for a webserver for basic WEB administration. For HTTPS or
|
||||
password you still need apache or the like.
|
||||
One step closer for complete fhem on the FritzBox.
|
||||
|
||||
- Boris Sun Jan 06 13:35:00 CET 2008
|
||||
- bugfix: 62_EMEM.pm: changed reading energy_total_kWh to energy_kWh_w,
|
||||
added energy_kWh (formerly energy_total_kWh)
|
||||
- changed em1010.pl accordingly, added em1000em doc for getDevStatus reply
|
||||
from device
|
||||
- minor changes in fhem.html
|
||||
|
||||
- Rudi Tue Jan 8 21:13:08 MET 2008
|
||||
- feature: attr global allowfrom <ip-adresses/hostnames>
|
||||
If set, only connects from these addresses are allowed. This is to
|
||||
"simulate" a little bit of security.
|
||||
|
||||
- Rudi Sat Jan 19 18:04:12 MET 2008
|
||||
- FHT: multiple commands
|
||||
Up to 8 commands in one set, these are transmitted at once to the FHT
|
||||
- softbuffer changes
|
||||
minfhtbuffer attribute, as otherwise nearly everything will be sent to
|
||||
the FHT buffer, so ordering won't take effect.
|
||||
- cmd rename
|
||||
report1,report2. refreshvalues changed to report1 and report2. refreshvalues
|
||||
won't be advertized but still replaced with "report1 255 report2 255"
|
||||
- extensive documentation update for the FHT
|
||||
- lime-protection changed, as it is an actuator subcommand. Further actuator
|
||||
commands added.
|
||||
|
||||
- Rudi Sun Jan 27 18:12:42 MET 2008
|
||||
- em1010PC: sending a "67" after a reset skips the manual interaction:
|
||||
automatic reset is now possible.
|
||||
|
||||
- Peter S. Sat Feb 16 22:22:21 MET 2008
|
||||
- linux.html: Note on kernel 2.6.24.2 (includes our changes)
|
||||
|
||||
- Peter S. Wed Mar 19 08:24:00 MET 2008
|
||||
- 00_FHZ.pm: DoTriger -> DoTrigger
|
||||
|
||||
- Rudi Fri May 9 20:00:00 MEST 2008
|
||||
- feature: FHEM modules may live on a filesystem with "ignorant" casing (FAT)
|
||||
If you install FHEM on a USB-Stick (e.g. for the FritzBox) it may happen
|
||||
that the filename casing is different from the function names inside the
|
||||
file.
|
||||
-> Fhem won't find the <module>_Initialize function. Fixed by searching all
|
||||
function-names for a match with "ignore-case"
|
||||
- feature: FileLog function "set reopen" impemented. In case you want to
|
||||
delete some wrong entries from a current logfile, you must tell fhem to
|
||||
reopen the file again
|
||||
- feature: multiline commands are supported through the command line
|
||||
Up till now multiline commands were supported only by "include". Now they
|
||||
are supprted from the (tcp/ip) connection too, so they can be used by the
|
||||
web frontends.
|
||||
- feature: pgm2 installation changes, multiple instances, external css
|
||||
pgm2 (FHEMWEB) is now a "real" fhem module:
|
||||
- the configuration takes place via attributes
|
||||
- the css file is external, and each FHEMWEB instance can use its own set
|
||||
- the default location for pictures, gnuplot scripts and css is the FHEM
|
||||
module directory
|
||||
- multiline support for notify and at scripts.
|
||||
- feature: FileLog "set reopen" for manual tweaking of logfiles.
|
||||
- feature: multiline commands are supported through the command line
|
||||
- feature: pgm2 installation changes, multiple instances, external css
|
||||
|
||||
-tdressler Sa May 10 23:00:00 MEST 2008
|
||||
- feature:add WS2000 Support new modul 87_ws2000.pm and standalone
|
||||
reader/server ws2000_reader.pl
|
||||
- doc: modified fhem.html/commandref.html reflectiing ws2000 device and
|
||||
added windows support (tagged:before tdressler_20080510_1, after
|
||||
tdressler_20080510_2)
|
||||
|
||||
-tdressler So May 11 19:30:00 MEST 2008
|
||||
- feature: add ReadyFn to fhem.pl in main loop to have an alternative for
|
||||
select, which is not working on windows (thomas 11.05)
|
||||
- feature: set timeout to 0.2s, if HandleTimeout returns undef=forever
|
||||
(tagged tdressler_20080511_1/2)
|
||||
- bugfix : WS2000:fixed serial port access on windows by replacing FD with
|
||||
ReadyFn
|
||||
- bugfix : FileLog: dont use FH->sync on windows (not implemented there)
|
||||
- feature: EM, WS300, FHZ:Add Switch for Device::SerialPort and
|
||||
Win32::SerialPort to get it running in Windows (sorry, untestet)
|
||||
|
||||
-tdressler So May 11 23:30:00 MEST 2008
|
||||
- bugfix: FileLog undefined $data in FileLog_Get
|
||||
- feature: fhem.pl check modules for compiletime errors and do not initialize
|
||||
them if any
|
||||
- bugfix: EM, WS300, FHZ scope of portobj variable
|
||||
|
||||
-tdressler Mo May 12 14:00:00 MEST 2008
|
||||
- bugfix: FHZ with windows, use there ReadyFn if windows; small cosmetic
|
||||
changes
|
||||
- doc: add hint to virtual com port driver, modification for FHZ to use
|
||||
default FTDI driver
|
||||
|
||||
-tdressler Mo May 12 19:00:00 MEST 2008
|
||||
- feature : add windows support to M232
|
||||
|
||||
-tdressler So May 18 13:30:00 MEST 2008
|
||||
- feature : add ELV IPWE1 support
|
||||
|
||||
- Peter S. Mon Jun 02 00:39 MET 2008
|
||||
- linux.html: openSUSE 11 contains our changes.
|
||||
|
||||
- Thu Jun 12 07:15:03 MEST 2008
|
||||
- feature: FileLog get to read logfiles / webpgm2: gnuplot-scroll mode to
|
||||
navigate/zoom in logfiles
|
||||
webpgm2 uses the FileLog get to grep data for a given data range from a
|
||||
logfile. Using this grep scrolling to a different date range / zooming
|
||||
to another resolution (day/week/month/year) can be implemented.
|
||||
The logfiles should be large, as scrolling across logfiles is not
|
||||
implemented. To speed up the grep, a binary search with seek is used, and
|
||||
seek positions are cached.
|
||||
|
||||
- Thu Jul 11 07:15:03 MEST 2008
|
||||
- feature: 99_SVG.pm for webpgm2: generates SVG from the logfile.
|
||||
Generating SVG is configurable, the "old" gnuplot mode is still there.
|
||||
Downside of the SVG: the browser must support SVG (Firefox/Opera does,
|
||||
I.E. with the Adobe plugin), and the browsesr consumes more memory.
|
||||
Upside: no gnuplot needed on the server, faster(?), less data to transfer
|
||||
for daily data.
|
||||
Tested with Firefox 3.0.
|
||||
Todo: Test with IE+Adobe Plugin/Opera.
|
||||
- feature: HOWTO for webpgm2 (first chapter)
|
|
@ -1,33 +0,0 @@
|
|||
BINDIR=/usr/local/bin
|
||||
MODDIR=/usr/local/lib
|
||||
|
||||
VERS=4.3
|
||||
DATE=2008-07-12
|
||||
DIR=fhem-$(VERS)
|
||||
|
||||
all:
|
||||
@echo Nothing to do for all.
|
||||
@echo To install, check the Makefile, and then \'make install\'
|
||||
|
||||
install:
|
||||
cp fhem.pl $(BINDIR)
|
||||
cp -rp FHEM $(MODDIR)
|
||||
perl -pi -e 's,modpath .,modpath $(MODDIR),' examples/*
|
||||
|
||||
install-pgm2:
|
||||
cp fhem.pl $(BINDIR)
|
||||
cp -rp FHEM $(MODDIR)
|
||||
cp -rp webfrontend/pgm2/* $(MODDIR)
|
||||
perl -pi -e 's,modpath .,modpath $(MODDIR),' examples/*
|
||||
|
||||
dist:
|
||||
@echo Version is $(VERS), Date is $(DATE)
|
||||
mkdir .f
|
||||
cp -rp * .f
|
||||
find .f -name \*.orig -print | xargs rm -f
|
||||
find .f -type f -print |\
|
||||
xargs perl -pi -e 's/=VERS=/$(VERS)/g;s/=DATE=/$(DATE)/g'
|
||||
mv .f fhem-$(VERS)
|
||||
tar cf - fhem-$(VERS) | gzip > fhem-$(VERS).tar.gz
|
||||
mv fhem-$(VERS)/docs/*.html .
|
||||
rm -rf fhem-$(VERS)
|
|
@ -1,65 +0,0 @@
|
|||
The source of this project is hosted on Berlios, if you wish you can get
|
||||
the latest version with the following commands:
|
||||
cvs -d:pserver:anonymous@cvs.fhem.berlios.de:/cvsroot/fhem login
|
||||
cvs -z3 -d:pserver:anonymous@cvs.fhem.berlios.de:/cvsroot/fhem co fhem
|
||||
|
||||
If you wish to contribute to the project, then
|
||||
- create a berlios account
|
||||
- send an email to the project manager to add you as developer to the project
|
||||
(right know this is r dot koenig at koeniglich dot de)
|
||||
- check out the source with
|
||||
% cvs -z3 -d<berlios-uid>@cvs.berlios.de:/cvsroot/fhem co fhem
|
||||
- if it is already checked out, it makes sense to do an update before
|
||||
implementing your changes:
|
||||
% cvs update
|
||||
- make your changes
|
||||
- test if it is working (Really !!!)
|
||||
- make an entry in the CHANGED file, giving your changes a "title".
|
||||
- describe your changes in the file HISTORY, and dont forget to mention your
|
||||
name and the date of change
|
||||
- it makes sense to do a "cvs diff" before checking in the stuff with
|
||||
cvs commit
|
||||
- if you do complex/nontrivial changes affecting more than one file, then
|
||||
please tag the whole software before and after the change with:
|
||||
- before: % cvs tag <berlios-uid>_<date_as_YYYYMMDD>_0
|
||||
- after: % cvs tag <berlios-uid>_<date_as_YYYYMMDD>_1
|
||||
You can increase the counter for bugfixing. Dont forget to mention the
|
||||
tagname in the HISTORY file. Tagging helps to remove more complex changes or
|
||||
to merge them in other releases/branches.
|
||||
|
||||
|
||||
Some useful CVS commands/flags for the beginner:
|
||||
|
||||
|
||||
# Get the newest stuff from the server and merge it into your changes.
|
||||
# Watch out for lines beginning with C (collisions), edit them immediately
|
||||
# after check out, and look for ====
|
||||
# Without -d new directories won't be checked out
|
||||
cvs update -d .
|
||||
|
||||
# Before checking in, make sure you changed only what you intended:
|
||||
cvs diff filename
|
||||
|
||||
# Add new file. "-kb" adds binary files. Forgetting -kb will cause
|
||||
# problems if somebody is checking out on a different OS (windows)
|
||||
# Note: it is complicated to rename files in CVS, so think twice about
|
||||
# filenames before adding them. e.g. do not use version names in them.
|
||||
cvs add [-kb] filename
|
||||
|
||||
# Look at the change history
|
||||
cvs log <filename>
|
||||
|
||||
# Commit changes. Set the EDITOR environment variable to use your editor.
|
||||
cvs commit .
|
||||
|
||||
# Check which files were changed. Type ^C when it asks you to really release it.
|
||||
# (is there a more elegant way?)
|
||||
cvs release .
|
||||
|
||||
# We recommend to set some options in our ~/.cvsrc file:
|
||||
cvs -q
|
||||
update -d
|
||||
# The 'cvs -q' option will suppress some output e.g. during update
|
||||
# only the updated and unknown files etc. are displayed (not every
|
||||
# folder etc.).
|
||||
# The 'update -d' will automatically create folders as required.
|
|
@ -1,97 +0,0 @@
|
|||
##############################################
|
||||
# Example for logging KS300 data into a DB.
|
||||
#
|
||||
# Prerequisites:
|
||||
# - The DBI and the DBD::<dbtype> modules must be installed.
|
||||
# - a Database is created/configured
|
||||
# - a db table: create table FHZLOG (TIMESTAMP varchar(20), TEMP varchar(5),
|
||||
# HUM varchar(3), WIND varchar(4), RAIN varchar(8));
|
||||
# - Change the content of the dbconn variable below
|
||||
# - extend your FHEM config file with
|
||||
# notify .*H:.* {DbLog("@","%")}
|
||||
# - copy this file into the <modpath>/FHEM and restart fhem.pl
|
||||
#
|
||||
# If you want to change this setup, your starting point is the DbLog function
|
||||
|
||||
my $dbconn = "Oracle:DBNAME:user:password";
|
||||
|
||||
package main;
|
||||
use strict;
|
||||
use warnings;
|
||||
use DBI;
|
||||
|
||||
my $dbh;
|
||||
|
||||
sub DbDo($);
|
||||
sub DbConnect();
|
||||
|
||||
|
||||
################################################################
|
||||
sub
|
||||
DbLog_Initialize($)
|
||||
{
|
||||
my ($hash) = @_;
|
||||
|
||||
# Lets connect here, so we see the error at startup
|
||||
DbConnect();
|
||||
}
|
||||
|
||||
################################################################
|
||||
sub
|
||||
DbLog($$)
|
||||
{
|
||||
my ($a1, $a2) = @_;
|
||||
|
||||
# a2 is like "T: 21.2 H: 37 W: 0.0 R: 0.0 IR: no"
|
||||
my @a = split(" ", $a2);
|
||||
my $tm = TimeNow();
|
||||
|
||||
DbDo("insert into FHZLOG (TIMESTAMP, TEMP, HUM, WIND, RAIN) values " .
|
||||
"('$tm', '$a[1]', '$a[3]', '$a[5]', '$a[7]')");
|
||||
}
|
||||
|
||||
|
||||
################################################################
|
||||
sub
|
||||
DbConnect()
|
||||
{
|
||||
return 1 if($dbh);
|
||||
Log 5, "Connecting to database $dbconn";
|
||||
my @a = split(":", $dbconn);
|
||||
$dbh = DBI->connect("dbi:$a[0]:$a[1]", $a[2], $a[3]);
|
||||
if(!$dbh) {
|
||||
Log 1, "Can't connect to $a[1]: $DBI::errstr";
|
||||
return 0;
|
||||
}
|
||||
Log 5, "Connection to db $a[1] established";
|
||||
return 1;
|
||||
}
|
||||
|
||||
################################################################
|
||||
sub
|
||||
DbDo($)
|
||||
{
|
||||
my $str = shift;
|
||||
|
||||
return 0 if(!DbConnect());
|
||||
Log 5, "Executing $str";
|
||||
my $sth = $dbh->do($str);
|
||||
if(!$sth) {
|
||||
Log 2, "DB: " . $DBI::errstr;
|
||||
$dbh->disconnect;
|
||||
$dbh = 0;
|
||||
return 0 if(!DbConnect());
|
||||
#retry
|
||||
$sth = $dbh->do($str);
|
||||
if($sth)
|
||||
{
|
||||
Log 2, "Retry ok: $str";
|
||||
return 1;
|
||||
}
|
||||
#
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
1;
|
|
@ -1,149 +0,0 @@
|
|||
#############################################
|
||||
# Low Budget ALARM System
|
||||
##############################################
|
||||
# ATTENTION! This is more a toy than a professional alarm system!
|
||||
# You must know what you do!
|
||||
##############################################
|
||||
#
|
||||
# Concept:
|
||||
# 1x Signal Light (FS20 allight) to show the status (activated/deactivated)
|
||||
# 2x Sirene (in/out) (FS20 alsir1 alsir2 )
|
||||
# 2x PIRI-2 (FS20 piriu pirio)
|
||||
# 1x Sender (FS20 alsw) to activate/deactivate the system.
|
||||
# Tip: use the KeyMatic CAC with pin code or
|
||||
# optional a normal sender (FS20 alsw2)
|
||||
#
|
||||
# Add something like the following lines to the configuration file :
|
||||
# notifyon alsw {MyAlsw()}
|
||||
# notifyon alsw2 {MyAlswNoPin()}
|
||||
# notifyon piriu {MyAlarm()}
|
||||
# notifyon pirio {MyAlarm()}
|
||||
# and put this file in the <modpath>/FHZ1000 directory.
|
||||
#
|
||||
# Martin Haas
|
||||
##############################################
|
||||
|
||||
|
||||
package main;
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
sub
|
||||
ALARM_Initialize($$)
|
||||
{
|
||||
my ($hash) = @_;
|
||||
}
|
||||
|
||||
|
||||
##############################################
|
||||
# Switching Alarm System on or off
|
||||
sub
|
||||
MyAlsw()
|
||||
{
|
||||
my $ON="set allight on; setstate alsw on";
|
||||
my $OFF="set allight off; set alsir1 off; set alsir2 off; setstate alsw off";
|
||||
|
||||
if ( -e "/var/tmp/alertsystem")
|
||||
{
|
||||
unlink "/var/tmp/alertsystem";
|
||||
#Paranoia
|
||||
for (my $i = 0; $i < 2; $i++ )
|
||||
{
|
||||
fhem "$OFF";
|
||||
};
|
||||
Log 2, "alarm system is OFF";
|
||||
} else {
|
||||
system "touch /var/tmp/alertsystem";
|
||||
#Paranoia
|
||||
for (my $i = 0; $i < 2; $i++ )
|
||||
{
|
||||
fhem "$ON"
|
||||
}
|
||||
Log 2, "alarm system is ON";
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
##############################################
|
||||
# If you have no Keymatic then use this workaround:
|
||||
# After 4x pushing a fs20-button within some seconds it will activate/deactivate the alarm system.
|
||||
sub
|
||||
MyAlswNoPin()
|
||||
{
|
||||
|
||||
my $timedout=5;
|
||||
|
||||
## first time
|
||||
if ( ! -e "/var/tmp/alontest1")
|
||||
{
|
||||
for (my $i = 1; $i < 4; $i++ )
|
||||
{
|
||||
system "touch -t 200601010101 /var/tmp/alontest$i";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
## test 4 times
|
||||
my $now= `date +%s`;
|
||||
for (my $i = 1; $i < 4; $i++ )
|
||||
{
|
||||
my $tagx=`date -r /var/tmp/alontest$i +%s`;
|
||||
my $testx=$now-$tagx;
|
||||
|
||||
if ( $testx > $timedout )
|
||||
{
|
||||
system "touch /var/tmp/alontest$i";
|
||||
die "test$i: more than $timedout sec";
|
||||
}
|
||||
}
|
||||
system "touch -t 200601010101 /var/tmp/alontest*";
|
||||
Log 2, "ok, let's switch the alarm system...";
|
||||
|
||||
#if you only allow to activate (and not deactivate) with this script:
|
||||
# if ( -e "/var/tmp/alertsystem") { die "deactivating alarm system not allowed"};
|
||||
|
||||
MyAlsw();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
##############################################
|
||||
# ALARM! Do what you want!
|
||||
sub
|
||||
MyAlarm()
|
||||
{
|
||||
|
||||
#alarm-system activated??
|
||||
if ( -e "/var/tmp/alertsystem")
|
||||
{
|
||||
|
||||
my $timer=180; # time until the sirene will be quiet
|
||||
my $ON1="set alsir1 on-for-timer $timer";
|
||||
my $ON2="set alsir2 on-for-timer $timer";
|
||||
|
||||
|
||||
#Paranoia
|
||||
for (my $i = 0; $i < 2; $i++ )
|
||||
{
|
||||
fhem "$ON1";
|
||||
fhem "$ON2";
|
||||
}
|
||||
Log 2, "ALARM! #################" ;
|
||||
|
||||
|
||||
# have fun
|
||||
my @lights=("stuwz1", "stuwz2", "nachto", "nachtu", "stoliba" ,"stlileo");
|
||||
my @rollos=("rolu4", "rolu5", "roloadi", "rololeo", "roloco", "rolowz", "rolunik1", "rolunik2");
|
||||
|
||||
foreach my $light (@lights) {
|
||||
fhem "set $light on"
|
||||
}
|
||||
|
||||
foreach my $rollo (@rollos) {
|
||||
fhem "set $rollo on"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
1;
|
|
@ -1,50 +0,0 @@
|
|||
##############################################
|
||||
# Example perl functions. Put this file into the FHEM directory.
|
||||
#
|
||||
# # Activate 2 rollades at once with one button, open them to
|
||||
# # a different degree.
|
||||
# define ntfy_1 notifyon btn3 {MyFunc("@", "%")}
|
||||
#
|
||||
# # Swith the heater off if all FHT actuators are closed,
|
||||
# # and on if at least one is open
|
||||
# define at_1 at +*00:05 { fhem "set heater " . (sumactuator()?"on":"off") };
|
||||
|
||||
package main;
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
sub
|
||||
PRIV_Initialize($$)
|
||||
{
|
||||
my ($hash, $init) = @_;
|
||||
}
|
||||
|
||||
sub
|
||||
sumactuator()
|
||||
{
|
||||
my $sum = 0;
|
||||
foreach my $d (keys %defs) {
|
||||
next if($defs{$d}{TYPE} ne "FHT");
|
||||
my ($act, undef) = split(" ", $defs{$d}{READINGS}{"actuator"}{VAL});
|
||||
$act =~ s/%//;
|
||||
$sum += $act;
|
||||
}
|
||||
return $sum;
|
||||
}
|
||||
|
||||
sub
|
||||
MyFunc($$)
|
||||
{
|
||||
my ($a1, $a2) = @_;
|
||||
|
||||
Log 2, "Device $a1 was set to $a2 (type: $defs{$a1}{TYPE})";
|
||||
if($a2 eq "on") {
|
||||
fhem "set roll1 on-for-timer 10";
|
||||
fhem "set roll2 on-for-timer 16";
|
||||
} else {
|
||||
fhem "set roll1 off";
|
||||
fhem "set roll2 off";
|
||||
}
|
||||
}
|
||||
|
||||
1;
|
|
@ -1,88 +0,0 @@
|
|||
##############################################
|
||||
# - Be aware: Installing the DateTime modules might be tedious, one way is:
|
||||
# perl -MCPAN -e shell
|
||||
# cpan> install DateTime::Event::Sunrise
|
||||
# - Please call sunrise_coord before using this module, else you'll get times
|
||||
# for frankfurt am main (germany). See the "at" entry in commandref.html
|
||||
|
||||
package main;
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
use DateTime;
|
||||
use DateTime::Event::Sunrise;
|
||||
|
||||
sub sr($$$$);
|
||||
sub sunrise_rel(@);
|
||||
sub sunset_rel(@);
|
||||
sub sunrise_abs(@);
|
||||
sub sunset_abs(@);
|
||||
sub isday();
|
||||
sub sunrise_coord($$$);
|
||||
sub SUNRISE_Initialize($);
|
||||
|
||||
# See perldoc DateTime::Event::Sunrise for details
|
||||
my $long = "8.686";
|
||||
my $lat = "50.112";
|
||||
my $tz = "Europe/Berlin";
|
||||
|
||||
sub
|
||||
SUNRISE_Initialize($)
|
||||
{
|
||||
my ($hash) = @_;
|
||||
}
|
||||
|
||||
|
||||
##########################
|
||||
# Compute:
|
||||
# rise: 1: event is sunrise (else sunset)
|
||||
# isrel: 1: _relative_ times until the next event (else absolute for today)
|
||||
# seconds: second offset to event
|
||||
# daycheck: if set, then return 1 if the sun is visible, 0 else
|
||||
sub
|
||||
sr($$$$)
|
||||
{
|
||||
my ($rise, $seconds, $isrel, $daycheck) = @_;
|
||||
|
||||
my $sunrise = DateTime::Event::Sunrise ->new(
|
||||
longitude => $long,
|
||||
latitude => $lat,
|
||||
altitude => '-6', # Civil twilight
|
||||
iteration => '3');
|
||||
my $now = DateTime->now(time_zone => $tz);
|
||||
my $stm = ($rise ? $sunrise->sunrise_datetime( $now ) :
|
||||
$sunrise->sunset_datetime( $now ));
|
||||
|
||||
if($daycheck) {
|
||||
return 0 if(DateTime->compare($now, $stm) < 0);
|
||||
$stm = $sunrise->sunset_datetime( $now );
|
||||
return 0 if(DateTime->compare($now, $stm) > 0);
|
||||
return 1;
|
||||
}
|
||||
|
||||
if(!$isrel) {
|
||||
$stm = $stm->add(seconds => $seconds) if($seconds);
|
||||
return $stm->hms();
|
||||
}
|
||||
|
||||
$stm = $stm->add(seconds => $seconds) if($seconds);
|
||||
|
||||
if(DateTime->compare($now, $stm) >= 0) {
|
||||
my $tom = DateTime->now(time_zone => $tz)->add(days => 1);
|
||||
$stm = ($rise ? $sunrise->sunrise_datetime( $tom ) :
|
||||
$sunrise->sunset_datetime( $tom ));
|
||||
$stm = $stm->add(seconds => $seconds) if($seconds);
|
||||
}
|
||||
|
||||
my $diff = $stm->epoch - $now->epoch;
|
||||
return sprintf("%02d:%02d:%02d", $diff/3600, ($diff/60)%60, $diff%60);
|
||||
}
|
||||
|
||||
sub sunrise_rel(@) { return sr(1, shift, 1, 0) }
|
||||
sub sunset_rel(@) { return sr(0, shift, 1, 0) }
|
||||
sub sunrise_abs(@) { return sr(1, shift, 0, 0) }
|
||||
sub sunset_abs(@) { return sr(0, shift, 0, 0) }
|
||||
sub isday() { return sr(1, 0, 0, 1) }
|
||||
sub sunrise_coord($$$) { ($long, $lat, $tz) = @_; return undef; }
|
||||
|
||||
1;
|
|
@ -1,48 +0,0 @@
|
|||
- 70_SCIVT.pm
|
||||
Support for an SCD series solar controler device. Details see
|
||||
http://english.ivt-hirschau.de/content.php?parent_id=CAT_64&doc_id=DOC_118
|
||||
- 80_M232.pm/81_M232Counter.pm
|
||||
Support for the M232 device from ELV by Boris.
|
||||
- 86_FS10.pm
|
||||
Support for FS10. Read README.FS10, you have to install pcwsd first.
|
||||
- 91_DbLog.pm
|
||||
Example to log data in a (DBI supported) database (MySQL, Oracle, etc)
|
||||
see dblog for a full-featured database log
|
||||
- 99_ALARM.pm
|
||||
Example for a Low Budget ALARM System by Martin
|
||||
- 99_SUNRISE.pm
|
||||
The original Sunrise/Sunset support. Uses DateTime::Event::Sunrise. Uses the
|
||||
99_SUNRISE_EL.pm module instead.
|
||||
- 99_SUNRISE_EL.pm
|
||||
Support foor computins sunrise/sunset times.
|
||||
- 99_Utils.pm
|
||||
skeleton for self-written perl funtions.
|
||||
- 99_dummy.pm
|
||||
Used for programming
|
||||
- 99_weblink.pm
|
||||
Used by fhemweb2.pl
|
||||
- checkmsg.pl
|
||||
Check header/function/crc of an FS20 hex message
|
||||
- crc.pl
|
||||
Computing CRC16 in perl
|
||||
- em1010.pl / em1010.gnuplot
|
||||
Standalone EM1010PC reader program and a gnuplot file to plot em1010 data
|
||||
- init-scripts
|
||||
RC scripts to be put into /etc/init.d and then symlinked to /etc/rc3.d or
|
||||
similar.
|
||||
- four2hex
|
||||
Convert housecode from ELV notation (4) to fhem.pl notation (hex)
|
||||
- fs20_holidays.sh
|
||||
STefan's "presence simulator" for holidays
|
||||
- garden.pl
|
||||
Garden irrigation regulator with weather dependency (KS300 temp + rain)
|
||||
- ks300avg.pl
|
||||
Computing daily/monthly avarage values from a KS300 log
|
||||
- rolwzo_not_off.sh
|
||||
Martin's "don't lock me out" program: look at the comment
|
||||
- rrd
|
||||
Peter's RRD support. See the HOWTO
|
||||
- serial.pm
|
||||
Serial line analyzer
|
||||
- dblog
|
||||
Support for a full-featured database log by Boris. See the README.
|
|
@ -1,26 +0,0 @@
|
|||
die("Usage: checkmsg HEX-FHZ-MESSAGE\n") if(int(@ARGV) != 1);
|
||||
my $msg = $ARGV[0];
|
||||
|
||||
die("Bad prefix (not 0x81)\n") if($msg !~ m/^81/);
|
||||
print("Prefix is ok (0x81)\n");
|
||||
|
||||
my $l = hex(substr($msg, 2, 2));
|
||||
my $rl = length($msg)/2-2;
|
||||
die("Bad length $rl (should be $l)\n") if($rl != $l);
|
||||
print("Length is ok ($l)\n");
|
||||
|
||||
my @data;
|
||||
for(my $i = 8; $i < length($msg); $i += 2) {
|
||||
push(@data, ord(pack('H*', substr($msg, $i, 2))));
|
||||
}
|
||||
|
||||
my $rcrc = 0;
|
||||
map { $rcrc += $_; } @data;
|
||||
$rcrc &= 0xFF;
|
||||
|
||||
my $crc = hex(substr($msg, 6, 2));
|
||||
my $str = sprintf("Bad CRC 0x%02x (should be 0x%02x)\n", $crc, $rcrc);
|
||||
die($str) if($crc ne $rcrc);
|
||||
printf("CRC is ok (0x%02x)\n", $crc);
|
||||
|
||||
exit(0);
|
|
@ -1,33 +0,0 @@
|
|||
die("Usage: crc HEX-MESSAGE\n") if(int(@ARGV) != 2);
|
||||
my $msg = $ARGV[0];
|
||||
$msg =~ s/ //g;
|
||||
|
||||
my $des = $ARGV[1];
|
||||
$des =~ s/ //g;
|
||||
|
||||
# FFFF: 77 72 statt 2c 7f
|
||||
# FFFF: 5C AC statt DC D9
|
||||
|
||||
|
||||
#for(my $ic = 0; $ic < 65536; $ic++) {
|
||||
for(my $ic = 0; $ic < 2; $ic++) {
|
||||
my $crc = ($ic == 0?0:0xffffffff);
|
||||
for(my $i = 0; $i < length($msg); $i += 2) {
|
||||
my $n = ord(pack('H*', substr($msg, $i, 2)));
|
||||
|
||||
my $od = $n;
|
||||
for my $b (0..7) {
|
||||
my $crcbit = ($crc & 0x80000000) ? 1 : 0;
|
||||
my $databit = ($n & 0x80) ? 1 : 0;
|
||||
$crc <<= 1;
|
||||
$n <<= 1;
|
||||
$crc ^= 0x04C11DB7 if($crcbit != $databit);
|
||||
# printf("%3d.%d %02x CRC %x ($crcbit $databit)\n", $i/2, $b, $n, $crc);
|
||||
}
|
||||
# printf("%3d %02x CRC %02x %02x\n", $i/2, $od, ($crc&0xff00)>>8, $crc&0xff);
|
||||
}
|
||||
# print "$ic\n" if($ic % 10000 == 0);
|
||||
printf("%02x %02x\n",($crc&0xff00)>>8,$crc&0xff);
|
||||
print "got $ic\n"
|
||||
if(sprintf("%02x%02x",($crc&0xff00)>>8,$crc&0xff) eq $des);
|
||||
}
|
|
@ -1,324 +0,0 @@
|
|||
##############################################
|
||||
#
|
||||
# 93_DbLog.pm
|
||||
# written by Dr. Boris Neubert 2007-12-30
|
||||
# e-mail: omega at online dot de
|
||||
#
|
||||
##############################################
|
||||
|
||||
package main;
|
||||
use strict;
|
||||
use warnings;
|
||||
use DBI;
|
||||
|
||||
sub DbLog($$$);
|
||||
|
||||
|
||||
################################################################
|
||||
sub
|
||||
DbLog_Initialize($)
|
||||
{
|
||||
my ($hash) = @_;
|
||||
|
||||
$hash->{DefFn} = "DbLog_Define";
|
||||
$hash->{UndefFn} = "DbLog_Undef";
|
||||
$hash->{NotifyFn} = "DbLog_Log";
|
||||
$hash->{AttrFn} = "DbLog_Attr";
|
||||
$hash->{AttrList} = "disable:0,1";
|
||||
}
|
||||
|
||||
#####################################
|
||||
sub
|
||||
DbLog_Define($@)
|
||||
{
|
||||
my ($hash, $def) = @_;
|
||||
my @a = split("[ \t][ \t]*", $def);
|
||||
|
||||
return "wrong syntax: define <name> DbLog configuration regexp"
|
||||
if(int(@a) != 4);
|
||||
|
||||
my $regexp = $a[3];
|
||||
|
||||
eval { "Hallo" =~ m/^$regexp$/ };
|
||||
return "Bad regexp: $@" if($@);
|
||||
$hash->{REGEXP} = $regexp;
|
||||
|
||||
$hash->{configuration}= $a[2];
|
||||
|
||||
return "Can't connect to database." if(!DbLog_Connect($hash));
|
||||
|
||||
$hash->{STATE} = "active";
|
||||
|
||||
return undef;
|
||||
}
|
||||
|
||||
#####################################
|
||||
sub
|
||||
DbLog_Undef($$)
|
||||
{
|
||||
my ($hash, $name) = @_;
|
||||
my $dbh= $hash->{DBH};
|
||||
$dbh->disconnect() if(defined($dbh));
|
||||
return undef;
|
||||
}
|
||||
|
||||
################################################################
|
||||
sub
|
||||
DbLog_Attr(@)
|
||||
{
|
||||
my @a = @_;
|
||||
my $do = 0;
|
||||
|
||||
if($a[0] eq "set" && $a[2] eq "disable") {
|
||||
$do = (!defined($a[3]) || $a[3]) ? 1 : 2;
|
||||
}
|
||||
$do = 2 if($a[0] eq "del" && (!$a[2] || $a[2] eq "disable"));
|
||||
return if(!$do);
|
||||
|
||||
$defs{$a[1]}{STATE} = ($do == 1 ? "disabled" : "active");
|
||||
|
||||
return undef;
|
||||
}
|
||||
|
||||
################################################################
|
||||
sub
|
||||
DbLog_ParseEvent($$)
|
||||
{
|
||||
my ($type, $event)= @_;
|
||||
my @result;
|
||||
|
||||
# split the event into reading and argument
|
||||
# "day-temp: 22.0 (Celsius)" -> "day-temp", "22.0 (Celsius)"
|
||||
my @parts= split(/: /,$event);
|
||||
my $reading= $parts[0]; if(!defined($reading)) { $reading= ""; }
|
||||
my $arg= $parts[1];
|
||||
|
||||
# the interpretation of the argument depends on the device type
|
||||
|
||||
#default
|
||||
my $value= $arg; if(!defined($value)) { $value= ""; }
|
||||
my $unit= "";
|
||||
|
||||
|
||||
# EMEM, M232Counter, M232Voltage return plain numbers
|
||||
if(($type eq "M232Voltage") ||
|
||||
($type eq "M232Counter") ||
|
||||
($type eq "EMEM")) {
|
||||
}
|
||||
# FS20
|
||||
elsif($type eq "FS20") {
|
||||
@parts= split(/ /,$value);
|
||||
my $reading= $parts[0]; if(!defined($reading)) { $reading= ""; }
|
||||
if($#parts>=1) {
|
||||
$value= join(" ", shift @parts);
|
||||
if($reading =~ m(^dim*%$)) {
|
||||
$value= substr($reading,3,length($reading)-4);
|
||||
$reading= "dim";
|
||||
$unit= "%";
|
||||
}
|
||||
else {
|
||||
$value= "";
|
||||
}
|
||||
}
|
||||
}
|
||||
# FHT
|
||||
elsif($type eq "FHT") {
|
||||
if($reading =~ m(-from[12]\ ) || $reading =~ m(-to[12]\ )) {
|
||||
@parts= split(/ /,$event);
|
||||
$reading= $parts[0];
|
||||
$value= $parts[1];
|
||||
$unit= "";
|
||||
}
|
||||
if($reading =~ m(-temp)) { $value=~ s/ \(Celsius\)//; $unit= "°C"; }
|
||||
if($reading =~ m(temp-offset)) { $value=~ s/ \(Celsius\)//; $unit= "°C"; }
|
||||
if($reading =~ m(^actuator[0-9]*)) {
|
||||
if($value eq "lime-protection") {
|
||||
$reading= "actuator-lime-protection";
|
||||
undef $value;
|
||||
}
|
||||
elsif($value =~ m(^offset:)) {
|
||||
$reading= "actuator-offset";
|
||||
@parts= split(/: /,$value);
|
||||
$value= $parts[1];
|
||||
if(defined $value) {
|
||||
$value=~ s/%//; $value= $value*1.; $unit= "%";
|
||||
}
|
||||
}
|
||||
elsif($value =~ m(^unknown_)) {
|
||||
@parts= split(/: /,$value);
|
||||
$reading= "actuator-" . $parts[0];
|
||||
$value= $parts[1];
|
||||
if(defined $value) {
|
||||
$value=~ s/%//; $value= $value*1.; $unit= "%";
|
||||
}
|
||||
}
|
||||
elsif($value eq "synctime") {
|
||||
$reading= "actuator-synctime";
|
||||
undef $value;
|
||||
}
|
||||
elsif($value eq "test") {
|
||||
$reading= "actuator-test";
|
||||
undef $value;
|
||||
}
|
||||
elsif($value eq "pair") {
|
||||
$reading= "actuator-pair";
|
||||
undef $value;
|
||||
}
|
||||
else {
|
||||
$value=~ s/%//; $value= $value*1.; $unit= "%";
|
||||
}
|
||||
}
|
||||
}
|
||||
# KS300
|
||||
elsif($type eq "KS300") {
|
||||
if($event =~ m(T:.*)) { $reading= "data"; $value= $event; }
|
||||
if($event =~ m(avg_day)) { $reading= "data"; $value= $event; }
|
||||
if($event =~ m(avg_month)) { $reading= "data"; $value= $event; }
|
||||
if($reading eq "temperature") { $value=~ s/ \(Celsius\)//; $unit= "°C"; }
|
||||
if($reading eq "wind") { $value=~ s/ \(km\/h\)//; $unit= "km/h"; }
|
||||
if($reading eq "rain") { $value=~ s/ \(l\/m2\)//; $unit= "l/m2"; }
|
||||
if($reading eq "rain_raw") { $value=~ s/ \(counter\)//; $unit= ""; }
|
||||
if($reading eq "humidity") { $value=~ s/ \(\%\)//; $unit= "%"; }
|
||||
if($reading eq "israining") {
|
||||
$value=~ s/ \(yes\/no\)//;
|
||||
$value=~ s/no/0/;
|
||||
$value=~ s/yes/1/;
|
||||
}
|
||||
}
|
||||
# HMS
|
||||
elsif($type eq "HMS") {
|
||||
if($event =~ m(T:.*)) { $reading= "data"; $value= $event; }
|
||||
if($reading eq "temperature") { $value=~ s/ \(Celsius\)//; $unit= "°C"; }
|
||||
if($reading eq "humidity") { $value=~ s/ \(\%\)//; $unit= "%"; }
|
||||
if($reading eq "battery") {
|
||||
$value=~ s/ok/1/;
|
||||
$value=~ s/replaced/1/;
|
||||
$value=~ s/empty/0/;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@result= ($reading,$value,$unit);
|
||||
return @result;
|
||||
}
|
||||
|
||||
|
||||
################################################################
|
||||
sub
|
||||
DbLog_Log($$)
|
||||
{
|
||||
# Log is my entry, Dev is the entry of the changed device
|
||||
my ($log, $dev) = @_;
|
||||
|
||||
# name and type required for parsing
|
||||
my $n= $dev->{NAME};
|
||||
my $t= $dev->{TYPE};
|
||||
|
||||
# timestamp in SQL format YYYY-MM-DD hh:mm:ss
|
||||
#my ($sec,$min,$hr,$day,$mon,$yr,$wday,$yday,$isdst)= localtime(time);
|
||||
#my $ts= sprintf("%04d-%02d-%02d %02d:%02d:%02d", $yr+1900,$mon+1,$day,$hr,$min,$sec);
|
||||
|
||||
my $re = $log->{REGEXP};
|
||||
my $max = int(@{$dev->{CHANGED}});
|
||||
for (my $i = 0; $i < $max; $i++) {
|
||||
my $s = $dev->{CHANGED}[$i];
|
||||
$s = "" if(!defined($s));
|
||||
if($n =~ m/^$re$/ || "$n:$s" =~ m/^$re$/) {
|
||||
my $ts = TimeNow();
|
||||
$ts = $dev->{CHANGETIME}[$i] if(defined($dev->{CHANGETIME}[$i]));
|
||||
# $ts is in SQL format YYYY-MM-DD hh:mm:ss
|
||||
|
||||
my @r= DbLog_ParseEvent($t, $s);
|
||||
my $reading= $r[0];
|
||||
my $value= $r[1];
|
||||
my $unit= $r[2];
|
||||
if(!defined $reading) { $reading= ""; }
|
||||
if(!defined $value) { $value= ""; }
|
||||
if(!defined $unit) { $unit= ""; }
|
||||
|
||||
|
||||
my $is= "(TIMESTAMP, DEVICE, TYPE, EVENT, READING, VALUE, UNIT) VALUES " .
|
||||
"('$ts', '$n', '$t', '$s', '$reading', '$value', '$unit')";
|
||||
DbLog_ExecSQL($log, "INSERT INTO history" . $is);
|
||||
DbLog_ExecSQL($log, "DELETE FROM current WHERE (DEVICE='$n') AND (READING='$reading')");
|
||||
DbLog_ExecSQL($log, "INSERT INTO current" . $is);
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
return "";
|
||||
}
|
||||
|
||||
|
||||
################################################################
|
||||
sub
|
||||
DbLog_Connect($)
|
||||
{
|
||||
my ($hash)= @_;
|
||||
|
||||
my $configfilename= $hash->{configuration};
|
||||
if(!open(CONFIG, $configfilename)) {
|
||||
Log 1, "Cannot open database configuration file $configfilename.";
|
||||
return 0; }
|
||||
my @config=<CONFIG>;
|
||||
close(CONFIG);
|
||||
|
||||
my %dbconfig;
|
||||
eval join("", @config);
|
||||
|
||||
my $dbconn= $dbconfig{connection};
|
||||
my $dbuser= $dbconfig{user};
|
||||
my $dbpassword= $dbconfig{password};
|
||||
|
||||
Log 3, "Connecting to database $dbconn with user $dbuser";
|
||||
my $dbh = DBI->connect_cached("dbi:$dbconn", $dbuser, $dbpassword);
|
||||
if(!$dbh) {
|
||||
Log 1, "Can't connect to $dbconn: $DBI::errstr";
|
||||
return 0;
|
||||
}
|
||||
Log 3, "Connection to db $dbconn established";
|
||||
$hash->{DBH}= $dbh;
|
||||
return 1;
|
||||
}
|
||||
|
||||
################################################################
|
||||
sub
|
||||
DbLog_ExecSQL1($$)
|
||||
{
|
||||
my ($dbh,$sql)= @_;
|
||||
|
||||
my $sth = $dbh->do($sql);
|
||||
if(!$sth) {
|
||||
Log 2, "DBLog error: " . $DBI::errstr;
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
sub
|
||||
DbLog_ExecSQL($$)
|
||||
{
|
||||
my ($hash,$sql)= @_;
|
||||
|
||||
Log 5, "Executing $sql";
|
||||
my $dbh= $hash->{DBH};
|
||||
if(!DbLog_ExecSQL1($dbh,$sql)) {
|
||||
#retry
|
||||
$dbh->disconnect();
|
||||
if(!DbLog_Connect($hash)) {
|
||||
Log 2, "DBLog reconnect failed.";
|
||||
return 0;
|
||||
}
|
||||
$dbh= $hash->{DBH};
|
||||
if(!DbLog_ExecSQL1($dbh,$sql)) {
|
||||
Log 2, "DBLog retry failed.";
|
||||
return 0;
|
||||
}
|
||||
Log 2, "DBLog retry ok.";
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
################################################################
|
||||
1;
|
|
@ -1,13 +0,0 @@
|
|||
For usage instruction see commandref.html, section define
|
||||
2007-12-30bn
|
||||
|
||||
- 93_DbLog.pm
|
||||
copy this file into <modpath>/FHEM
|
||||
- db.conf
|
||||
sample database configuration file
|
||||
- fhemdb_create.sql
|
||||
sample sql command to create a mysql database for logging purposes
|
||||
- fhemdb_get.pl
|
||||
sample perl script for retrieving the current (latest) data from
|
||||
the logging database
|
||||
|
|
@ -1,11 +0,0 @@
|
|||
#
|
||||
# database configuration file
|
||||
#
|
||||
#
|
||||
#
|
||||
%dbconfig= (
|
||||
connection => "mysql:database=fhem;host=db;port=3306",
|
||||
user => "fhemuser",
|
||||
password => "fhempassword",
|
||||
);
|
||||
|
|
@ -1,7 +0,0 @@
|
|||
CREATE DATABASE `fhem` DEFAULT CHARACTER SET utf8 COLLATE utf8_bin;
|
||||
CREATE USER 'fhemuser'@'%' IDENTIFIED BY 'fhempassword';
|
||||
CREATE TABLE history (TIMESTAMP TIMESTAMP, DEVICE varchar(32), TYPE varchar(32), EVENT varchar(64), READING varchar(32), VALUE varchar(32), UNIT varchar(32));
|
||||
CREATE TABLE current (TIMESTAMP TIMESTAMP, DEVICE varchar(32), TYPE varchar(32), EVENT varchar(64), READING varchar(32), VALUE varchar(32), UNIT varchar(32));
|
||||
GRANT SELECT, INSERT, DELETE ON `fhem` .* TO 'fhemuser'@'%';
|
||||
|
||||
|
|
@ -1,93 +0,0 @@
|
|||
#!/usr/bin/perl
|
||||
#
|
||||
################################################################
|
||||
#
|
||||
# Copyright notice
|
||||
#
|
||||
# (c) 2007 Copyright: Dr. Boris Neubert (omega at online dot de)
|
||||
# All rights reserved
|
||||
#
|
||||
# This script free software; you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation; either version 2 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# The GNU General Public License can be found at
|
||||
# http://www.gnu.org/copyleft/gpl.html.
|
||||
# A copy is found in the textfile GPL.txt and important notices to the license
|
||||
# from the author is found in LICENSE.txt distributed with these scripts.
|
||||
#
|
||||
# This script is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# This copyright notice MUST APPEAR in all copies of the script!
|
||||
#
|
||||
################################################################
|
||||
|
||||
|
||||
#
|
||||
# this script returns the current reading for a device stored in
|
||||
# the fhem logging database
|
||||
#
|
||||
|
||||
# Usage:
|
||||
# fhemdb_get.pl <device> <reading> [<reading> ...]
|
||||
# Example:
|
||||
# fhemdb_get.pl ext.ks300 temperature humidity
|
||||
#
|
||||
#
|
||||
|
||||
#
|
||||
# global configuration
|
||||
#
|
||||
my $dbconn = "mysql:database=fhem;host=db;port=3306";
|
||||
my $dbuser = "fhemuser";
|
||||
my $dbpassword = "fhempassword";
|
||||
|
||||
#
|
||||
# nothing to change below this line
|
||||
#
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
use DBI;
|
||||
|
||||
(@ARGV>=2) || die "Usage: fhemdb_get.pl <device> <reading> [<reading> ... ]";
|
||||
|
||||
my $device= $ARGV[0];
|
||||
my @readings=@ARGV; shift @readings;
|
||||
my $set= join(",", map({"\'" . $_ . "\'"} @readings));
|
||||
|
||||
my $dbh= DBI->connect_cached("dbi:$dbconn", $dbuser, $dbpassword) ||
|
||||
die "Cannot connect to $dbconn: $DBI::errstr";
|
||||
my $stm= "SELECT READING, VALUE FROM current WHERE
|
||||
(DEVICE='$device') AND
|
||||
(READING IN ($set))";
|
||||
my $sth= $dbh->prepare($stm) ||
|
||||
die "Cannot prepare statement $stm: $DBI::errstr";
|
||||
my $rc= $sth->execute() ||
|
||||
die "Cannot execute statement $stm: $DBI::errstr";
|
||||
|
||||
my %rs;
|
||||
my $reading;
|
||||
my $value;
|
||||
while( ($reading,$value)= $sth->fetchrow_array) {
|
||||
$rs{$reading}= $value;
|
||||
}
|
||||
foreach $reading (@readings) {
|
||||
$value= $rs{$reading};
|
||||
$value= "NULL" if(!defined($value));
|
||||
print "$reading:$value ";
|
||||
}
|
||||
print "\n";
|
||||
die $sth->errstr if $sth->err;
|
||||
$dbh->disconnect();
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
@ -1,474 +0,0 @@
|
|||
#!/usr/bin/perl
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
use Device::SerialPort;
|
||||
|
||||
sub b($$);
|
||||
sub w($$);
|
||||
sub docrc($$);
|
||||
sub checkcrc($$);
|
||||
sub getData($);
|
||||
sub makemsg($);
|
||||
sub maketime($);
|
||||
|
||||
my %cmd = (
|
||||
"getVersion" => 1,
|
||||
"getTime" => 1,
|
||||
"getDevStatus" => 1,
|
||||
"getDevPage" => 1,
|
||||
"getDevData" => 1,
|
||||
"setPrice" => 1,
|
||||
"setAlarm" => 1,
|
||||
"setRperKW" => 1,
|
||||
"get62" => 1,
|
||||
"setTime" => 1,
|
||||
"reset" => 1,
|
||||
);
|
||||
|
||||
|
||||
if(@ARGV < 2) {
|
||||
printf("Usage: perl em1010.pl serial-device command args\n");
|
||||
exit(1);
|
||||
}
|
||||
my $ser = $ARGV[0];
|
||||
|
||||
my $fd;
|
||||
|
||||
#####################
|
||||
# Open serial port
|
||||
my $serport = new Device::SerialPort ($ser);
|
||||
die "Can't open $ser: $!\n" if(!$serport);
|
||||
$serport->reset_error();
|
||||
$serport->baudrate(38400);
|
||||
$serport->databits(8);
|
||||
$serport->parity('none');
|
||||
$serport->stopbits(1);
|
||||
$serport->handshake('none');
|
||||
|
||||
my $cmd = $ARGV[1];
|
||||
if(!defined($cmd{$cmd})) {
|
||||
printf("Unknown command $cmd, use one of " . join(" ",sort keys %cmd) . "\n");
|
||||
exit(0);
|
||||
}
|
||||
|
||||
###########################
|
||||
no strict "refs";
|
||||
&{$cmd }();
|
||||
use strict "refs";
|
||||
exit(0);
|
||||
|
||||
#########################
|
||||
sub
|
||||
maketime($)
|
||||
{
|
||||
my @l = localtime(shift);
|
||||
return sprintf("%04d-%02d-%02d_%02d:%02d:00",
|
||||
1900+$l[5],$l[4]+1,$l[3],$l[2],$l[1]-$l[1]%5);
|
||||
}
|
||||
|
||||
#########################
|
||||
sub
|
||||
b($$)
|
||||
{
|
||||
my ($t,$p) = @_;
|
||||
return ord(substr($t,$p,1));
|
||||
}
|
||||
|
||||
#########################
|
||||
sub
|
||||
w($$)
|
||||
{
|
||||
my ($t,$p) = @_;
|
||||
return b($t,$p+1)*256 + b($t,$p);
|
||||
}
|
||||
|
||||
#########################
|
||||
sub
|
||||
dw($$)
|
||||
{
|
||||
my ($t,$p) = @_;
|
||||
return w($t,$p+2)*65536 + w($t,$p);
|
||||
}
|
||||
|
||||
#########################
|
||||
sub
|
||||
docrc($$)
|
||||
{
|
||||
my ($in, $val) = @_;
|
||||
my ($crc, $bits) = (0, 8);
|
||||
my $k = (($in >> 8) ^ $val) << 8;
|
||||
while($bits--) {
|
||||
if(($crc ^ $k) & 0x8000) {
|
||||
$crc = ($crc << 1) ^ 0x8005;
|
||||
} else {
|
||||
$crc <<= 1;
|
||||
}
|
||||
$k <<= 1;
|
||||
}
|
||||
return (($in << 8) ^ $crc) & 0xffff;
|
||||
}
|
||||
|
||||
#########################
|
||||
sub
|
||||
checkcrc($$)
|
||||
{
|
||||
my ($otxt, $len) = @_;
|
||||
my $crc = 0x8c27;
|
||||
for(my $l = 2; $l < $len+4; $l++) {
|
||||
my $b = ord(substr($otxt,$l,1));
|
||||
$crc = docrc($crc, 0x10) if($b==0x02 || $b==0x03 || $b==0x10);
|
||||
$crc = docrc($crc, $b);
|
||||
}
|
||||
return ($crc == w($otxt, $len+4));
|
||||
}
|
||||
|
||||
#########################
|
||||
sub
|
||||
esc($)
|
||||
{
|
||||
my ($b) = @_;
|
||||
|
||||
my $out = "";
|
||||
$out .= chr(0x10) if($b==0x02 || $b==0x03 || $b==0x10);
|
||||
$out .= chr($b);
|
||||
}
|
||||
|
||||
#########################
|
||||
sub
|
||||
makemsg($)
|
||||
{
|
||||
my ($data) = @_;
|
||||
my $len = length($data);
|
||||
$data = chr($len&0xff) . chr(int($len/256)) . $data;
|
||||
|
||||
my $out = pack('H*', "0200");
|
||||
my $crc = 0x8c27;
|
||||
for(my $l = 0; $l < $len+2; $l++) {
|
||||
my $b = ord(substr($data,$l,1));
|
||||
$crc = docrc($crc, 0x10) if($b==0x02 || $b==0x03 || $b==0x10);
|
||||
$crc = docrc($crc, $b);
|
||||
$out .= esc($b);
|
||||
}
|
||||
$out .= esc($crc&0xff);
|
||||
$out .= esc($crc/256);
|
||||
$out .= chr(0x03);
|
||||
return $out;
|
||||
}
|
||||
|
||||
|
||||
#########################
|
||||
sub
|
||||
getData($)
|
||||
{
|
||||
my ($d) = @_;
|
||||
$d = makemsg(pack('H*', $d));
|
||||
#print "Sending: " . unpack('H*', $d) . "\n";
|
||||
|
||||
for(my $rep = 0; $rep < 3; $rep++) {
|
||||
|
||||
#printf "write (try nr $rep)\n";
|
||||
$serport->write($d);
|
||||
|
||||
my $retval = "";
|
||||
my $esc = 0;
|
||||
my $started = 0;
|
||||
my $complete = 0;
|
||||
for(;;) {
|
||||
my ($rout, $rin) = ('', '');
|
||||
vec($rin, $serport->FILENO, 1) = 1;
|
||||
my $nfound = select($rout=$rin, undef, undef, 1.0);
|
||||
|
||||
die("Select error $nfound / $!\n") if($nfound < 0);
|
||||
last if($nfound == 0);
|
||||
|
||||
my $buf = $serport->input();
|
||||
die "EOF on $ser\n" if(!defined($buf) || length($buf) == 0);
|
||||
|
||||
for(my $i = 0; $i < length($buf); $i++) {
|
||||
my $b = ord(substr($buf,$i,1));
|
||||
|
||||
if(!$started && $b != 0x02) { next; }
|
||||
$started = 1;
|
||||
if($esc) { $retval .= chr($b); $esc = 0; next; }
|
||||
if($b == 0x10) { $esc = 1; next; }
|
||||
$retval .= chr($b);
|
||||
if($b == 0x03) { $complete = 1; last; }
|
||||
}
|
||||
if($complete) {
|
||||
my $l = length($retval);
|
||||
if($l < 8) { printf("Msg too short\n"); last; }
|
||||
if(b($retval,1) != 0) { printf("Bad second byte\n"); last; }
|
||||
if(w($retval,2) != $l-7) { printf("Length mismatch\n"); last; }
|
||||
if(!checkcrc($retval,$l-7)) { printf("Bad CRC\n"); last; }
|
||||
return substr($retval, 4, $l-7);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
printf "Timeout reading the answer\n";
|
||||
exit(1);
|
||||
}
|
||||
#########################
|
||||
sub
|
||||
hexdump($)
|
||||
{
|
||||
my ($d) = @_;
|
||||
for(my $i = 0; $i < length($d); $i += 16) {
|
||||
my $h = unpack("H*", substr($d, $i, 16));
|
||||
$h =~ s/(....)/$1 /g;
|
||||
printf "RAW %-40s\n", $h;
|
||||
}
|
||||
}
|
||||
|
||||
#########################
|
||||
sub
|
||||
getVersion()
|
||||
{
|
||||
my $d = getData("76");
|
||||
printf "%d.%d\n", b($d,0), b($d,1);
|
||||
}
|
||||
|
||||
#########################
|
||||
sub
|
||||
getTime()
|
||||
{
|
||||
my $d = getData("74");
|
||||
printf("%4d-%02d-%02d %02d:%02d:%02d\n",
|
||||
b($d,5)+2006, b($d,4), b($d,3),
|
||||
b($d,0), b($d,1), b($d,2));
|
||||
}
|
||||
|
||||
#########################
|
||||
sub
|
||||
getDevStatus()
|
||||
{
|
||||
die "Usage: getDevStatus devicenumber (1-12)\n" if(@ARGV != 3);
|
||||
my $d = getData(sprintf("7a%02x",$ARGV[2]-1));
|
||||
|
||||
if($d eq ((pack('H*',"00") x 45) . pack('H*',"FF") x 6)) {
|
||||
printf(" No device no. $ARGV[2] present\n");
|
||||
return;
|
||||
}
|
||||
my $pulses=w($d,13);
|
||||
my $pulses_max=w($d,15);
|
||||
my $ec=w($d,49) / 10;
|
||||
my $cur_energy=0;
|
||||
my $cur_power=0;
|
||||
my $cur_power_max=0;
|
||||
my $sum_h_energy=0;
|
||||
my $sum_d_energy=0;
|
||||
my $sum_w_energy=0;
|
||||
my $total_energy=0;
|
||||
my $iec=0;
|
||||
|
||||
printf(" Readings (off 2): %d\n", w($d,2));
|
||||
printf(" Nr devs (off 6): %d\n", b($d,6));
|
||||
printf(" puls/5min (off 13): %d\n", $pulses);
|
||||
printf(" puls.max/5min (off 15): %d\n", $pulses_max);
|
||||
#printf(" Startblk (off 18): %d\n", b($d,18)+13);
|
||||
#for (my $lauf = 19; $lauf < 45; $lauf += 2) {
|
||||
# printf(" t wert (off $lauf): %d\n", w($d,$lauf));
|
||||
#}
|
||||
# The data must interpreted depending on the sensor type.
|
||||
# Currently we use the EC value to quess the sensor type.
|
||||
if ($ec eq 0) {
|
||||
# Sensor 5..
|
||||
$iec = 1000;
|
||||
$cur_power = $pulses / 100;
|
||||
$cur_power_max = $pulses_max / 100;
|
||||
} else {
|
||||
# Sensor 1..4
|
||||
$iec = $ec;
|
||||
$cur_energy = $pulses / $ec; # ec = U/kWh
|
||||
$cur_power = $cur_energy / 5 * 60; # 5minute interval scaled to 1h
|
||||
printf(" cur.energy(off ): %.3f kWh\n", $cur_energy);
|
||||
}
|
||||
$sum_h_energy= dw($d,33) / $iec; # 33= pulses this hour
|
||||
$sum_d_energy= dw($d,37) / $iec; # 37= pulses today
|
||||
$sum_w_energy= dw($d,41) / $iec; # 41= pulses this week
|
||||
$total_energy= dw($d, 7) / $iec; # 7= pulses total
|
||||
printf(" cur.power ( ): %.3f kW\n", $cur_power);
|
||||
printf(" cur.power max ( ): %.3f kW\n", $cur_power_max);
|
||||
printf(" energy h (off 33): %.3f kWh (h)\n", $sum_h_energy);
|
||||
printf(" energy d (off 37): %.3f kWh (d)\n", $sum_d_energy);
|
||||
printf(" energy w (off 41): %.3f kWh (w)\n", $sum_w_energy);
|
||||
printf(" total energy (off 7): %.3f kWh (total)\n", $total_energy);
|
||||
printf(" Alarm PA (off 45): %d W\n", w($d,45));
|
||||
printf(" Price CF (off 47): %0.2f EUR/kWh\n", w($d,47)/10000);
|
||||
printf(" R/kW EC (off 49): %d\n", $ec);
|
||||
hexdump($d);
|
||||
}
|
||||
|
||||
#########################
|
||||
sub
|
||||
getDevPage()
|
||||
{
|
||||
die "Usage: getDevPage pagenumber [length] (default length is 264)\n"
|
||||
if(@ARGV < 3);
|
||||
my $l = (@ARGV > 3 ? $ARGV[3] : 264);
|
||||
my $d = getData(sprintf("52%02x%02x0000%02x%02x",
|
||||
$ARGV[2]%256, int($ARGV[2]/256), $l%256, int($l/256)));
|
||||
hexdump($d);
|
||||
}
|
||||
|
||||
#########################
|
||||
sub
|
||||
getDevData()
|
||||
{
|
||||
my $smooth = 1; # Set this to 0 to get the "real" values
|
||||
|
||||
die "Usage: getDevData devicenumber (1-12)\n" if(@ARGV != 3);
|
||||
my $d = getData(sprintf("7a%02x",$ARGV[2]-1));
|
||||
|
||||
if($d eq ((pack('H*',"00") x 45) . pack('H*',"FF") x 6)) {
|
||||
printf(" No device no. $ARGV[2] present\n");
|
||||
return;
|
||||
}
|
||||
|
||||
my $nrreadings = w($d,2);
|
||||
if($nrreadings == 0) {
|
||||
printf("No data to read (yet?)\n");
|
||||
exit(0);
|
||||
}
|
||||
my $step = b($d,6);
|
||||
my $start = b($d,18)+13;
|
||||
my $end = $start + int(($nrreadings-1)/64)*$step;
|
||||
my $div = w($d,49)/10;
|
||||
if ($div eq 0) {
|
||||
$div = 1;
|
||||
}
|
||||
|
||||
#printf("Total $nrreadings, $start - $end, Nr $step\n");
|
||||
|
||||
my $tm = time()-(($nrreadings-1)*300);
|
||||
my $backlog = 0;
|
||||
for(my $p = $start; $p <= $end; $p += $step) {
|
||||
#printf("Get page $p\n");
|
||||
|
||||
$d = getData(sprintf("52%02x%02x00000801", $p%256, int($p/256)));
|
||||
|
||||
#hexdump($d);
|
||||
|
||||
my $max = (($p == $end) ? ($nrreadings%64)*4+4 : 260);
|
||||
my $step = b($d, 6);
|
||||
|
||||
for(my $off = 8; $off <= $max; $off += 4) {
|
||||
$backlog++;
|
||||
if($smooth && (w($d,$off+2) == 0xffff)) { # "smoothing"
|
||||
next;
|
||||
} else {
|
||||
my $v = w($d,$off)*12/$div/$backlog;
|
||||
my $f1 = b($d,$off+2);
|
||||
my $f2 = b($d,$off+3);
|
||||
my $f3 = w($d,$off+2);
|
||||
|
||||
while($backlog--) {
|
||||
printf("%s %0.3f kWh (%d %d %d)\n", maketime($tm), $v,
|
||||
($backlog?-1:$f1), ($backlog?-1:$f2), ($backlog?-1:$f3));
|
||||
$tm += 300;
|
||||
}
|
||||
$backlog = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
sub
|
||||
setPrice()
|
||||
{
|
||||
die "Usage: setPrice device value_in_cent\n"
|
||||
if(@ARGV != 4);
|
||||
my $d = $ARGV[2];
|
||||
my $v = $ARGV[3];
|
||||
|
||||
$d = getData(sprintf("79%02x2f02%02x%02x", $d-1, $v%256, int($v/256)));
|
||||
if(b($d,0) == 6) {
|
||||
print("OK");
|
||||
} else {
|
||||
print("Error occured");
|
||||
hexdump($d);
|
||||
}
|
||||
}
|
||||
|
||||
sub
|
||||
setAlarm()
|
||||
{
|
||||
die "Usage: setAlarm device value_in_kWh\n"
|
||||
if(@ARGV != 4);
|
||||
my $d = $ARGV[2];
|
||||
my $v = $ARGV[3];
|
||||
|
||||
$d = getData(sprintf("79%02x2d02%02x%02x", $d-1, $v%256, int($v/256)));
|
||||
if(b($d,0) == 6) {
|
||||
print("OK");
|
||||
} else {
|
||||
print("Error occured");
|
||||
hexdump($d);
|
||||
}
|
||||
}
|
||||
|
||||
sub
|
||||
setRperKW()
|
||||
{
|
||||
die "Usage: setRperKW device rotations_per_KW\n"
|
||||
if(@ARGV != 4);
|
||||
my $d = $ARGV[2];
|
||||
my $v = $ARGV[3];
|
||||
|
||||
$v = $v * 10;
|
||||
$d = getData(sprintf("79%02x3102%02x%02x", $d-1, $v%256, int($v/256)));
|
||||
if(b($d,0) == 6) {
|
||||
print("OK");
|
||||
} else {
|
||||
print("Error occured");
|
||||
hexdump($d);
|
||||
}
|
||||
}
|
||||
|
||||
sub
|
||||
reset()
|
||||
{
|
||||
my $d = getData("4545");
|
||||
hexdump($d);
|
||||
}
|
||||
|
||||
sub
|
||||
get62()
|
||||
{
|
||||
my $d = getData("62");
|
||||
hexdump($d);
|
||||
}
|
||||
|
||||
sub
|
||||
setTime()
|
||||
{
|
||||
my $a2 = '';
|
||||
my $a3 = '';
|
||||
|
||||
if (@ARGV == 2) {
|
||||
my @lt = localtime;
|
||||
$a2 = sprintf ("%04d-%02d-%02d", $lt[5]+1900, $lt[4]+1, $lt[3]);
|
||||
$a3 = sprintf ("%02d:%02d:%02d", $lt[2], $lt[1], $lt[0]);
|
||||
} else {
|
||||
die "Usage: setTime [time] (as YYYY-MM-DD HH:MM:SS, localtime if empty)\n"
|
||||
if(@ARGV != 4);
|
||||
$a2 = $ARGV[2];
|
||||
$a3 = $ARGV[3];
|
||||
}
|
||||
my @d = split("-", $a2);
|
||||
my @t = split(":", $a3);
|
||||
|
||||
my $s = sprintf("73%02x%02x%02x00%02x%02x%02x",
|
||||
$d[2],$d[1],$d[0]-2000+0xd0,
|
||||
$t[0],$t[1],$t[2]);
|
||||
print("-> $s\n");
|
||||
|
||||
my $d = getData($s);
|
||||
if(b($d,0) == 6) {
|
||||
print("OK");
|
||||
} else {
|
||||
print("Error occured");
|
||||
hexdump($d);
|
||||
}
|
||||
}
|
|
@ -1,34 +0,0 @@
|
|||
############################
|
||||
# Display the measured temperature and actuator data logged
|
||||
# as described in the 04_log config file.
|
||||
# Copy your logfile to fht.log and then call
|
||||
# gnuplot fht.gnuplot
|
||||
# (i.e. this file)
|
||||
# Note: The webfrontend pgm2 and pgm3 does this for you.
|
||||
# More examples can be found in the webfrontend/pgm2 directory.
|
||||
|
||||
|
||||
###########################
|
||||
# Uncomment the following if you want to create a postscript file
|
||||
# and comment out the pause at the end
|
||||
#set terminal postscript color "Helvetica" 11
|
||||
#set output 'fht.ps'
|
||||
|
||||
set xdata time
|
||||
set timefmt "%Y-%m-%d_%H:%M:%S"
|
||||
set xlabel " "
|
||||
|
||||
set ylabel "Temperature (Celsius)"
|
||||
set y2label "Actuator (%)"
|
||||
set ytics nomirror
|
||||
set y2tics
|
||||
set y2label "Actuator (%)"
|
||||
|
||||
set title 'FHT log'
|
||||
plot \
|
||||
"< awk '/measured/{print $1, $4}' fht.log"\
|
||||
using 1:2 axes x1y1 title 'Measured temperature' with lines,\
|
||||
"< awk '/actuator/{print $1, $4+0}' fht.log"\
|
||||
using 1:2 axes x1y2 title 'Actuator (%)' with lines\
|
||||
|
||||
pause 100000
|
|
@ -1,6 +0,0 @@
|
|||
CC=gcc
|
||||
|
||||
four2hex : four2hex.c
|
||||
|
||||
install : four2hex
|
||||
install -m 0755 four2hex /usr/local/bin/four2hex
|
|
@ -1,23 +0,0 @@
|
|||
Four2hex was written to convert the housecode based on digits ranging from 1
|
||||
to 4 into hex code and vica versa.
|
||||
Four2hex is freeware based on the GNU Public license.
|
||||
|
||||
To built it:
|
||||
$ make four2hex
|
||||
|
||||
Install it to /usr/local/bin:
|
||||
$ su
|
||||
# make install
|
||||
|
||||
|
||||
Here an example from "four"-based to hex:
|
||||
$ four2hex 12341234
|
||||
1b1b
|
||||
|
||||
Here an example in the other (reverse) direction:
|
||||
$ four2hex -r 1b1b
|
||||
12341234
|
||||
|
||||
Enjoy.
|
||||
Peter Stark, (Peter dot stark at t-online dot de)
|
||||
|
Binary file not shown.
|
@ -1,94 +0,0 @@
|
|||
/*
|
||||
Four2hex was written to convert the housecode based on digits ranging from 1
|
||||
to 4 into hex code and vica versa.
|
||||
Four2hex is freeware based on the GNU Public license.
|
||||
|
||||
To built it:
|
||||
$ make four2hex
|
||||
|
||||
Install it to /usr/local/bin:
|
||||
$ su
|
||||
# make install
|
||||
|
||||
|
||||
Here an example from "four"-based to hex:
|
||||
$ four2hex 12341234
|
||||
1b1b
|
||||
|
||||
Here an example in the other (reverse) direction:
|
||||
$ four2hex -r 1b1b
|
||||
12341234
|
||||
|
||||
Enjoy.
|
||||
Peter Stark, (Peter dot stark at t-online dot de)
|
||||
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <ctype.h>
|
||||
|
||||
int atoh (const char c)
|
||||
{
|
||||
int ret=0;
|
||||
|
||||
ret = (int) (c - '0');
|
||||
if (ret > 9) {
|
||||
ret = (int) (c - 'a' + 10);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
int strlen(const char *);
|
||||
|
||||
main (int argc, char **argv)
|
||||
{
|
||||
char c, *s, *four;
|
||||
long int result;
|
||||
int b, i, h;
|
||||
|
||||
if (argc < 2 || argc >3) {
|
||||
fprintf (stderr, "usage: four2hex four-string\n");
|
||||
fprintf (stderr, " or: four2hex -r hex-string\n");
|
||||
return (1);
|
||||
}
|
||||
result = 0L;
|
||||
if (strcmp(argv[1], "-r") == 0) {
|
||||
/* reverse (hex->4) */
|
||||
for (s = argv[2]; *s != '\0'; s++) {
|
||||
c = tolower(*s);
|
||||
b = atoh(c);
|
||||
for (i = 0; i < 2; i++) {
|
||||
h = ((b & 0xc) >> 2) + 1;
|
||||
b = (b & 0x3) << 2;
|
||||
printf ("%d", h);
|
||||
}
|
||||
}
|
||||
printf ("\n");
|
||||
} else {
|
||||
/* normal (4->hex) */
|
||||
four = argv[1];
|
||||
if (strlen(four) == 4 || strlen(four) == 8) {
|
||||
for (s = four; *s != '\0'; s++) {
|
||||
result = result << 2;
|
||||
switch (*s) {
|
||||
case '1' : result = result + 0; break;
|
||||
case '2' : result = result + 1; break;
|
||||
case '3' : result = result + 2; break;
|
||||
case '4' : result = result + 3; break;
|
||||
default :
|
||||
fprintf (stderr, "four-string may contain '1' to '4' only\n");
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (strlen(four) == 8) {
|
||||
printf ("%04x\n", result);
|
||||
} else {
|
||||
printf ("%02x\n", result);
|
||||
}
|
||||
} else {
|
||||
fprintf (stderr, "four-string must be of length 4 or 8\n");
|
||||
return (1);
|
||||
}
|
||||
}
|
||||
return (0);
|
||||
}
|
|
@ -1,94 +0,0 @@
|
|||
#!/bin/sh
|
||||
#
|
||||
# script to generate a random number of on/off events to simulate presence eg.
|
||||
# while on holidays. normally this script would be executed by an event like a
|
||||
# dawn-sensor (you wouldn't want light during the day...:-)
|
||||
#
|
||||
# Copyright STefan Mayer <stefan@clumsy.ch>
|
||||
|
||||
################## configuration ###########################
|
||||
#number of events (min - max)
|
||||
event_min=5
|
||||
event_max=20
|
||||
|
||||
#maximum delay in minutes
|
||||
delay_max=240
|
||||
|
||||
#minimum and maximum ontime in minutes
|
||||
ontime_min=5
|
||||
ontime_max=60
|
||||
|
||||
#devices to consider
|
||||
declare -a devices='("dg.gang" "dg.wand" "dg.dusche" "dg.bad" "dg.reduit")'
|
||||
|
||||
#output variant [oft|onoff]
|
||||
#oft: use one at with on-for-timer of system
|
||||
#onoff: use two at, one for on one for off
|
||||
variant="onoff"
|
||||
|
||||
#command to execute
|
||||
#command_start="/opt/fhem/fhem.pl 7072 \""
|
||||
command_start="echo /opt/fhem/fhem.pl 7072 \""
|
||||
command_end="\""
|
||||
|
||||
|
||||
##################### Shouldnt need any changes below here #####################
|
||||
|
||||
# count number of devices
|
||||
count=0
|
||||
for i in ${devices[*]}
|
||||
do
|
||||
((count++))
|
||||
done
|
||||
# echo $count
|
||||
|
||||
# maximum random in bash: 32768
|
||||
random_max=32768
|
||||
|
||||
#number of events
|
||||
event=$(($RANDOM * (($event_max - $event_min)) / $random_max +$event_min))
|
||||
|
||||
#initialize command
|
||||
command=$command_start
|
||||
|
||||
for ((i=0; i<$event; i++))
|
||||
do
|
||||
#calculate starttime
|
||||
starttime=$(($RANDOM * $delay_max / $random_max))
|
||||
hour=$(($starttime / 60))
|
||||
minute=$(($starttime % 60))
|
||||
second=$(($RANDOM * 60 / $random_max))
|
||||
|
||||
#calculate ontime
|
||||
ontime=$(($RANDOM * (($ontime_max - $ontime_min)) / $random_max +$ontime_min))
|
||||
|
||||
#choose device
|
||||
dev=$(($RANDOM * $count / $random_max))
|
||||
|
||||
case $variant in
|
||||
oft)
|
||||
printf "event %02d: at +%02d:%02d:%02d set %s on-for-timer %d\n" $i $hour $minute $second ${devices[$dev]} $ontime
|
||||
command=`printf "$command at +%02d:%02d:%02d set %s on-for-timer %d;;" $hour $minute $second ${devices[$dev]} $ontime`
|
||||
;;
|
||||
onoff)
|
||||
offtime=$(($starttime + $ontime))
|
||||
hour_off=$(($offtime / 60))
|
||||
minute_off=$(($offtime % 60))
|
||||
second_off=$(($RANDOM * 60 / $random_max))
|
||||
printf "event %02d/on : at +%02d:%02d:%02d set %s on\n" $i $hour $minute $second ${devices[$dev]}
|
||||
printf "event %02d/off: at +%02d:%02d:%02d set %s off\n" $i $hour_off $minute_off $second_off ${devices[$dev]}
|
||||
command=`printf "$command at +%02d:%02d:%02d set %s on;;" $hour $minute $second ${devices[$dev]}`
|
||||
command=`printf "$command at +%02d:%02d:%02d set %s off;;" $hour_off $minute_off $second_off ${devices[$dev]}`
|
||||
;;
|
||||
*)
|
||||
echo "no variant specifieno variant specified!!"
|
||||
;;
|
||||
esac
|
||||
|
||||
done
|
||||
command="$command $command_end"
|
||||
|
||||
#execute command
|
||||
eval "$command"
|
||||
|
||||
|
|
@ -1,212 +0,0 @@
|
|||
#!/usr/bin/perl
|
||||
|
||||
use warnings;
|
||||
use strict;
|
||||
use IO::Socket::INET;
|
||||
use IO::Handle;
|
||||
|
||||
STDOUT->autoflush(1);
|
||||
|
||||
#################
|
||||
# Formula:
|
||||
# Compute for the last <navg> days + today the avarage temperature and the
|
||||
# sum of rain, then compute the multiplier: (temp/20)^2 - rain/5
|
||||
# Now multiply the duration of each vent with this multiplier
|
||||
# If the value is less than a minimum, then store the value and add it
|
||||
# the next day
|
||||
#################
|
||||
|
||||
my $test = 0; # Test only, do not switch anything
|
||||
my $fhzport = 7072; # Where to contact it
|
||||
my $avg = "/home/rudi/log/avg.log"; # KS300 avarage log file
|
||||
my $navg = 2; # Number of last avg_days to consider
|
||||
my $min = 300; # If the duration is < min (sec) then collect
|
||||
my $col = "/home/rudi/log/gardencoll.log"; # File where it will be collected
|
||||
my $pmp = "GPumpe"; # Name of the water pump, will be switched in first
|
||||
my $maxmult = 4; # Maximum factor (corresponds to 40 degree avg.
|
||||
# temp over $navg days, no rain)
|
||||
|
||||
if(@ARGV) {
|
||||
if($ARGV[0] eq "test") {
|
||||
$test = 1;
|
||||
} else {
|
||||
print "Usage: garden.pl [test]\n";
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
my %list = (
|
||||
GVent1 => { Nr => 1, Dur => 720 },
|
||||
GVent2 => { Nr => 2, Dur => 480 },
|
||||
GVent3 => { Nr => 3, Dur => 720 },
|
||||
GVent4 => { Nr => 4, Dur => 720 },
|
||||
GVent6 => { Nr => 5, Dur => 720 },
|
||||
GVent7 => { Nr => 6, Dur => 480 },
|
||||
GVent8 => { Nr => 7, Dur => 480 },
|
||||
);
|
||||
|
||||
##############################
|
||||
# End of config
|
||||
|
||||
sub fhzcommand($);
|
||||
sub doswitch($$);
|
||||
sub donext($$);
|
||||
|
||||
my ($nlines, $temp, $rain) = (0, 0, 0);
|
||||
my ($KS300name, $server, $last);
|
||||
|
||||
my @t = localtime;
|
||||
printf("%04d-%02d-%02d %02d:%02d:%02d\n",
|
||||
$t[5]+1900, $t[4]+1, $t[3], $t[2], $t[1], $t[0]);
|
||||
|
||||
###########################
|
||||
# First read in the last avg_days
|
||||
open(FH, $avg) || die("$avg: $!\n");
|
||||
my @avg = <FH>;
|
||||
close(FH);
|
||||
|
||||
my @tarr; # Want the printout in the right order
|
||||
while(my $l = pop(@avg)) {
|
||||
next if($l !~ m/avg_day/);
|
||||
my @v = split(" ", $l);
|
||||
push(@tarr, "$v[0]: T: $v[4], R: $v[10]") if($test);
|
||||
$temp += $v[4]; $rain += $v[10];
|
||||
$KS300name = $v[1];
|
||||
$nlines++;
|
||||
last if($nlines >= $navg);
|
||||
}
|
||||
|
||||
###########################
|
||||
# Now get the current day
|
||||
foreach my $l (split("\n", fhzcommand("list $KS300name"))) {
|
||||
next if($l !~ m/avg_day/);
|
||||
my @v = split(" ", $l);
|
||||
print("$v[0] $v[1]: T: $v[4], R: $v[10]\n") if($test);
|
||||
$temp += $v[4]; $rain += $v[10];
|
||||
$nlines++;
|
||||
last;
|
||||
}
|
||||
|
||||
if($test) {
|
||||
foreach my $l (@tarr) {
|
||||
print "$l\n";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
###########################
|
||||
# the collected data
|
||||
my %coll;
|
||||
if(open(FH, $col)) {
|
||||
while(my $l = <FH>) {
|
||||
my ($k, $v) = split("[ \n]", $l);
|
||||
$coll{$k} = $v;
|
||||
}
|
||||
close(FH);
|
||||
}
|
||||
|
||||
###########################
|
||||
# The formula
|
||||
$temp /= $nlines;
|
||||
$rain /= $nlines;
|
||||
|
||||
# safety measures
|
||||
$rain = 0 if($rain < 0);
|
||||
$temp = 0 if($temp < 0);
|
||||
$temp = 40 if($temp > 40);
|
||||
my $mult = exp( 2.0 * log( $temp / 20 )) - $rain/5;
|
||||
$mult = $maxmult if($mult > $maxmult);
|
||||
|
||||
if($mult <= 0) {
|
||||
print("Multiplier is not positive ($mult), exiting\n");
|
||||
exit(0);
|
||||
}
|
||||
|
||||
printf("Multiplier is %.2f (T: $temp, R: $rain)\n", $mult, $temp, $rain);
|
||||
|
||||
my $have = 0;
|
||||
if(!$test) {
|
||||
open(FH, ">$col") || die("Can't open $col: $!\n");
|
||||
}
|
||||
foreach my $a (sort { $list{$a}{Nr} <=> $list{$b}{Nr} } keys %list) {
|
||||
my $dur = int($list{$a}{Dur} * $mult);
|
||||
|
||||
if(defined($coll{$a})) {
|
||||
$dur += $coll{$a};
|
||||
printf(" $a: $dur ($coll{$a})\n");
|
||||
} else {
|
||||
printf(" $a: $dur\n");
|
||||
}
|
||||
|
||||
if($dur > $min) {
|
||||
$list{$a}{Act} = $dur;
|
||||
$have += $dur;
|
||||
} else {
|
||||
print FH "$a $dur\n" if(!$test);
|
||||
}
|
||||
}
|
||||
|
||||
print("Total time is $have\n");
|
||||
exit(0) if($test);
|
||||
close(FH);
|
||||
|
||||
if($have) {
|
||||
doswitch($pmp, "on") if($pmp);
|
||||
sleep(3) if(!$test);
|
||||
foreach my $a (sort { $list{$a}{Nr} <=> $list{$b}{Nr} } keys %list) {
|
||||
next if(!$list{$a}{Act});
|
||||
donext($a, $list{$a}{Act});
|
||||
}
|
||||
donext("", 0);
|
||||
doswitch($pmp, "off") if($pmp);
|
||||
}
|
||||
|
||||
###########################
|
||||
# Switch the next dev on and the last one off
|
||||
sub
|
||||
donext($$)
|
||||
{
|
||||
my ($dev, $sl) = @_;
|
||||
doswitch($dev, "on");
|
||||
doswitch($last, "off");
|
||||
$last = $dev;
|
||||
if($test) {
|
||||
print "sleeping $sl\n";
|
||||
} else {
|
||||
sleep($sl);
|
||||
}
|
||||
}
|
||||
|
||||
###########################
|
||||
# Paranoid setting.
|
||||
sub
|
||||
doswitch($$)
|
||||
{
|
||||
my ($dev, $how) = @_;
|
||||
return if(!$dev || !$how);
|
||||
|
||||
if($test) {
|
||||
print "set $dev $how\n";
|
||||
return;
|
||||
}
|
||||
fhzcommand("set $dev $how");
|
||||
sleep(1);
|
||||
fhzcommand("set $dev $how");
|
||||
}
|
||||
|
||||
###########################
|
||||
sub
|
||||
fhzcommand($)
|
||||
{
|
||||
my $cmd = shift;
|
||||
|
||||
my ($ret, $buf) = ("", "");
|
||||
$server = IO::Socket::INET->new(PeerAddr => "localhost:$fhzport");
|
||||
die "Can't connect to the server at port $fhzport\n" if(!$server);
|
||||
syswrite($server, "$cmd;quit\n");
|
||||
while(sysread($server, $buf, 256) > 0) {
|
||||
$ret .= $buf;
|
||||
}
|
||||
close($server);
|
||||
return $ret;
|
||||
}
|
|
@ -1,46 +0,0 @@
|
|||
#! /bin/sh -e
|
||||
#
|
||||
#
|
||||
#
|
||||
# Written by Stefan Manteuffel
|
||||
|
||||
PATH=/bin:/usr/bin:/sbin:/usr/sbin:/usr/local/bin
|
||||
DAEMON=/usr/local/bin/fhem.pl
|
||||
PIDFILE=/var/run/fhem.pid
|
||||
|
||||
# Arguments to atd
|
||||
#
|
||||
ARGS="/etc/FHZ/fhem.cfg"
|
||||
|
||||
test -x $DAEMON || exit 0
|
||||
|
||||
. /lib/lsb/init-functions
|
||||
|
||||
case "$1" in
|
||||
start)
|
||||
echo "Starting deferred execution scheduler..."
|
||||
start-stop-daemon -b --start --quiet --pidfile $PIDFILE --startas $DAEMON -- $ARGS
|
||||
log_end_msg $?
|
||||
;;
|
||||
stop)
|
||||
log_begin_msg "Stopping deferred execution scheduler..."
|
||||
start-stop-daemon --oknodo --stop --quiet --retry 30 --pidfile $PIDFILE --name fhem.pl
|
||||
|
||||
log_end_msg $?
|
||||
;;
|
||||
force-reload|restart)
|
||||
log_begin_msg "Restarting deferred execution scheduler..."
|
||||
if start-stop-daemon --stop --quiet --retry 30 --pidfile $PIDFILE --name fhem.pl; then
|
||||
start-stop-daemon -b --start --quiet --pidfile $PIDFILE --startas $DAEMON -- $ARGS
|
||||
log_end_msg $?
|
||||
else
|
||||
log_end_msg 1
|
||||
fi
|
||||
;;
|
||||
*)
|
||||
echo "Usage: /etc/init.d/fhem.pl {start|stop|restart|force-reload|reload}"
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
|
||||
exit 0
|
|
@ -1,25 +0,0 @@
|
|||
#!/bin/sh
|
||||
# by Matthias Bauer
|
||||
|
||||
case "$1" in
|
||||
start)
|
||||
echo "Starting $0"
|
||||
fhem.pl /etc/fhem/fhem.conf
|
||||
;;
|
||||
stop)
|
||||
echo "Stopping $0"
|
||||
killall fhem.pl
|
||||
;;
|
||||
status)
|
||||
cnt=`ps -ef | grep "fhem.pl" | grep -v grep | wc -l`
|
||||
if [ "$cnt" -eq "0" ] ; then
|
||||
echo "$0 is not running"
|
||||
else
|
||||
echo "$0 is running"
|
||||
fi
|
||||
;;
|
||||
*)
|
||||
echo "Usage: $0 {start|stop|status}"
|
||||
exit 1
|
||||
esac
|
||||
exit 0
|
|
@ -1,77 +0,0 @@
|
|||
#!/usr/bin/perl
|
||||
|
||||
# Compute Daily and monthly avarage temp/hum/wind and cumulative rain values
|
||||
# from the "standard" KS300 logs.
|
||||
# Best to concatenate all KS300-logs into one big file (cat out*.log > big.log)
|
||||
# and then start the program with ks300avg.pl big.log
|
||||
# Note: the program assumes that there are no "holes" in the logs.
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
if(@ARGV != 1) {
|
||||
print "Usage: ks300avg.pl KS300-logfile\n";
|
||||
exit(1);
|
||||
}
|
||||
|
||||
open(FH, $ARGV[0]) || die("$ARGV[0]: $!\n");
|
||||
|
||||
my ($mt, $mh, $mw, $md) = (0,0,0,0);
|
||||
my ($t, $h, $w) = (0,0,0);
|
||||
my (@ld, $lsec, $lr, $mr, $ldsec);
|
||||
my ($dt, $dev, $sec, @a);
|
||||
|
||||
while(my $l = <FH>) {
|
||||
next if($l =~ m/avg/);
|
||||
|
||||
chomp $l;
|
||||
@a = split(" ", $l);
|
||||
$dev = $a[1];
|
||||
$dt = $a[0];
|
||||
my @d = split("[_:-]", $a[0]);
|
||||
$sec = $d[3]*3600+$d[4]*60+$d[5];
|
||||
|
||||
if(!$lsec) {
|
||||
@ld = @d;
|
||||
$lr = $a[9];
|
||||
$mr = $a[9];
|
||||
$lsec = $ldsec = $sec;
|
||||
next;
|
||||
}
|
||||
|
||||
my $difft = $sec - $lsec;
|
||||
$difft += 86400 if($d[2] != $ld[2]);
|
||||
|
||||
$lsec = $sec;
|
||||
$t += $difft * $a[3];
|
||||
$h += $difft * $a[5];
|
||||
$w += $difft * $a[7];
|
||||
|
||||
$l = <FH>;
|
||||
|
||||
if($d[2] != $ld[2]) { # Day changed
|
||||
my $diff = ($sec - $ldsec) + 86400;
|
||||
$t /= $diff; $h /= $diff; $w /= $diff;
|
||||
printf("$dt $dev avg_day T: %.1f H: %d W: %0.1f R: %.1f\n",
|
||||
$t, $h, $w, $a[9]-$lr);
|
||||
$lr = $a[9];
|
||||
$md++;
|
||||
$mt += $t; $mh += $h; $mw += $w;
|
||||
$t = $h = $w = 0;
|
||||
$ldsec = $sec;
|
||||
}
|
||||
|
||||
if($d[1] != $ld[1]) { # Month changed
|
||||
printf("$dt $dev avg_month T: %.1f H: %d W: %0.1f R: %.1f\n",
|
||||
$mt/$md, $mh/$md, $mw/$md, $a[9]-$mr);
|
||||
$mr = $a[9];
|
||||
$mt = $mh = $mw = $md = 0;
|
||||
}
|
||||
|
||||
@ld = @d;
|
||||
}
|
||||
|
||||
printf("$dt $dev avg_day T: %.1f H: %d W: %0.1f R: %.1f\n",
|
||||
$t/$sec, $h/$sec, $w/$sec, $a[9]-$lr);
|
||||
printf("$dt $dev avg_month T: %.1f H: %d W: %0.1f R: %.1f\n",
|
||||
$mt/$md, $mh/$md, $mw/$md, $a[9]-$mr);
|
|
@ -1,15 +0,0 @@
|
|||
#!/bin/bash
|
||||
|
||||
# What do I want: If I'am sitting e.g. outside I don't want that the rollo goes
|
||||
# down. solution: if the button for e.g. rollo will be pressed after 16:59
|
||||
# o'clock then the at-job for going down by sunset will be deleted
|
||||
|
||||
# put something like the following into your fhz100.cfg:
|
||||
# define rolzwo_not_off notify rolwzo /usr/local/bin/rolwzo_not_off.sh
|
||||
|
||||
|
||||
FHZ="/usr/local/bin/fhem.pl 7072"
|
||||
order="delete rolwzo_off"
|
||||
|
||||
DATESTRING=`date +"%H"`
|
||||
[[ $DATESTRING > 16 ]] && $FHZ "$order"
|
|
@ -1,76 +0,0 @@
|
|||
##############################################
|
||||
# Example for writing to RRD.
|
||||
# notify .*T:.* {RRDUpdateTemp("@","%")}
|
||||
# and put this file in the <modpath>/FHEM directory.
|
||||
|
||||
package main;
|
||||
use strict;
|
||||
use warnings;
|
||||
use RRDs;
|
||||
|
||||
my $DB = "/var/lib/collectd/temperature.rrd";
|
||||
|
||||
sub
|
||||
RRD_Initialize($$)
|
||||
{
|
||||
my ($hash, $init) = @_;
|
||||
$hash->{Type} = "none";
|
||||
|
||||
if(! -f $DB)
|
||||
{
|
||||
Log 3, "***RRD Init";
|
||||
RRDs::create($DB, "--step=300",
|
||||
"DS:innen:GAUGE:1800:-30.0:70.0",
|
||||
"DS:bad:GAUGE:1800:-30.0:70.0",
|
||||
"DS:wasser:GAUGE:1800:-30.0:70.0",
|
||||
"RRA:AVERAGE:0.5:1:288",
|
||||
"RRA:MAX:0.5:12:168",
|
||||
"RRA:MIN:0.5:12:168",
|
||||
"RRA:AVERAGE:0.5:288:365") or die "Create error: ($RRDs::error)";
|
||||
}
|
||||
}
|
||||
|
||||
### FHT80 ###
|
||||
sub
|
||||
RRDUpdateInnen($$)
|
||||
{
|
||||
my ($a1, $a2) = @_;
|
||||
my @a = split(" ", $a2);
|
||||
my $tm = TimeNow();
|
||||
|
||||
my $value = $a[1];
|
||||
Log 5, "Device $a1 was set to $a2 (type: $defs{$a1}{TYPE})";
|
||||
|
||||
Log 2, "***InnenTemp:$value um $tm RRD";
|
||||
RRDs::update($DB, "--template", "innen", "N:$value") or
|
||||
die "Update error: ($RRDs::error)";
|
||||
}
|
||||
|
||||
### HMS ###
|
||||
sub
|
||||
RRDUpdateTemp($$)
|
||||
{
|
||||
my ($a1, $a2) = @_;
|
||||
# a2 is like "T: 21.2 H: 37 "
|
||||
my @a = split(" ", $a2);
|
||||
my $tm = TimeNow();
|
||||
my $value = $a[1];
|
||||
|
||||
Log 5, "Device $a1 was set to $a2 (type: $defs{$a1}{TYPE})";
|
||||
|
||||
if($a1 eq "viebadtemp")
|
||||
{
|
||||
Log 2, "***BadTemp:$value um $tm RRD";
|
||||
RRDs::update($DB, "--template", "bad", "N:$value") or
|
||||
die "Update error: ($RRDs::error)";
|
||||
}
|
||||
|
||||
if($a1 eq "viewassertemp")
|
||||
{
|
||||
Log 2, "***WasserTemp:$value um $tm RRD";
|
||||
RRDs::update($DB, "--template", "wasser", "N:$value") or
|
||||
die "Update error: ($RRDs::error)";
|
||||
}
|
||||
}
|
||||
|
||||
1;
|
|
@ -1,52 +0,0 @@
|
|||
apt-get install rrdtool
|
||||
|
||||
if RRDs.pm is missing apt-get install librrds-perl
|
||||
apt-get collectd
|
||||
|
||||
Zum weiterlesen
|
||||
Messdaten mit RRDtool und Perl verwalten http://www.linux-magazin.de/Artikel/ausgabe/2004/06/perl/perl.html
|
||||
|
||||
my example:
|
||||
|
||||
RRDs::create($DB, "--step=300", #300 = every 5 min
|
||||
"DS:innen:GAUGE:1800:-30.0:70.0", #FHT80 room temperature
|
||||
"DS:bad:GAUGE:1800:-30.0:70.0", #HMS100TF bath temperature
|
||||
"DS:wasser:GAUGE:1800:-30.0:70.0", #HMS100T water temperature
|
||||
"RRA:AVERAGE:0.5:1:288",
|
||||
"RRA:MAX:0.5:12:168",
|
||||
"RRA:MIN:0.5:12:168",
|
||||
"RRA:AVERAGE:0.5:288:365") or die "Create error: ($RRDs::error)";
|
||||
|
||||
Modification on collection.cgi
|
||||
|
||||
temperature => [
|
||||
'DEF:temp_avg={file}:bad:AVERAGE',
|
||||
'DEF:temp_min={file}:bad:MIN',
|
||||
'DEF:temp_max={file}:bad:MAX',
|
||||
'DEF:i_avg={file}:innen:AVERAGE',
|
||||
'DEF:i_min={file}:innen:MIN',
|
||||
'DEF:i_max={file}:innen:MAX',
|
||||
'DEF:w_avg={file}:wasser:AVERAGE',
|
||||
'DEF:w_min={file}:wasser:MIN',
|
||||
'DEF:w_max={file}:wasser:MAX',
|
||||
"AREA:temp_max#$HalfBlue",
|
||||
"AREA:temp_min#$Canvas",
|
||||
"LINE1:temp_avg#$FullRed:Bad",
|
||||
'GPRINT:temp_min:MIN:%4.1lf Min,',
|
||||
'GPRINT:temp_avg:AVERAGE:%4.1lf Avg,',
|
||||
'GPRINT:temp_max:MAX:%4.1lf Max,',
|
||||
'GPRINT:temp_avg:LAST:%4.1lf zuletzt\l',
|
||||
"LINE2:i_avg#$FullGreen:Innen",
|
||||
'GPRINT:i_min:MIN:%4.1lf Min,',
|
||||
'GPRINT:i_avg:AVERAGE:%4.1lf Avg,',
|
||||
'GPRINT:i_max:MAX:%4.1lf Max,',
|
||||
'GPRINT:i_avg:LAST:%4.1lf zuletzt\l',
|
||||
"LINE3:w_avg#$FullBlue:Wasser",
|
||||
'GPRINT:w_min:MIN:%4.1lf Min,',
|
||||
'GPRINT:w_avg:AVERAGE:%4.1lf Avg,',
|
||||
'GPRINT:w_max:MAX:%4.1lf Max,',
|
||||
'GPRINT:w_avg:LAST:%4.1lf zuletzt\l'
|
||||
|
||||
],
|
||||
|
||||
|
|
@ -1,89 +0,0 @@
|
|||
#!/usr/bin/perl
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
use Device::SerialPort;
|
||||
use Time::HiRes qw(gettimeofday);
|
||||
sub pp($$);
|
||||
|
||||
if(@ARGV != 3) {
|
||||
printf("Usage: perl serial.pl serial-device outfile initial-hex-msg\n");
|
||||
exit(1);
|
||||
}
|
||||
my $ser = $ARGV[0];
|
||||
my $fil = $ARGV[1];
|
||||
my $hm = $ARGV[2];
|
||||
|
||||
my $fd;
|
||||
open($fd, ">$fil") || die("Can't open $fil for writing\n");
|
||||
select $fd;
|
||||
$| = 1;
|
||||
|
||||
my $serport = new Device::SerialPort ($ser);
|
||||
die "Can't open $ser: $!\n" if(!$serport);
|
||||
$serport->reset_error();
|
||||
$serport->baudrate(38400);
|
||||
$serport->databits(8);
|
||||
$serport->parity('none');
|
||||
$serport->stopbits(1);
|
||||
$serport->handshake('none');
|
||||
|
||||
my $interval = 2.0; # Seconds
|
||||
|
||||
my $nto = gettimeofday();
|
||||
my $nfound;
|
||||
|
||||
$hm=~ s/ //g;
|
||||
$hm = pack('H*', $hm);
|
||||
|
||||
while (1) {
|
||||
my ($rout, $rin) = ('', '');
|
||||
vec($rin, 0, 1) = 1; # stdin
|
||||
vec($rin, $serport->FILENO, 1) = 1;
|
||||
|
||||
my $to = $nto - gettimeofday();
|
||||
if($to > 0) {
|
||||
$nfound = select($rout=$rin, undef, undef, $to);
|
||||
die("Select error $nfound / $!\n") if($nfound < 0);
|
||||
}
|
||||
|
||||
if($to <= 0 || $nfound == 0) { # Timeout
|
||||
$serport->write($hm);
|
||||
pp("S>", $hm);
|
||||
$nto = gettimeofday() + $interval;
|
||||
}
|
||||
|
||||
if(vec($rout, 0, 1)) {
|
||||
my $buf = <STDIN>;
|
||||
die "EOF on STDIN\n" if(!defined($buf) || length($buf) == 0);
|
||||
$buf=~ s/[ \r\n]//g;
|
||||
$buf = pack('H*', $buf);
|
||||
$serport->write($buf);
|
||||
pp("X>", $buf);
|
||||
}
|
||||
if(vec($rout, $serport->FILENO, 1)) {
|
||||
my $buf = $serport->input();
|
||||
die "EOF on $ser\n" if(!defined($buf) || length($buf) == 0);
|
||||
pp("S<", $buf);
|
||||
}
|
||||
}
|
||||
|
||||
sub
|
||||
pp($$) {
|
||||
my ($prompt, $txt) = @_;
|
||||
|
||||
my ($s, $ms) = gettimeofday();
|
||||
my @t = localtime($s);
|
||||
my $tim = sprintf("%02d:%02d:%02d.%03d", $t[2],$t[1],$t[0], $ms/1000);
|
||||
|
||||
for(my $i = 0; $i < length($txt); $i += 16) {
|
||||
my $a = substr($txt, $i, 16);
|
||||
my $h = unpack("H*", $a);
|
||||
$a =~ s/[\r\n]/./g;
|
||||
$a =~ s/\P{IsPrint}/\./g;
|
||||
$h =~ s/(....)/$1 /g;
|
||||
printf $fd "%s %s %04d %-40s %s\n", $prompt, $tim, $i, $h, $a;
|
||||
}
|
||||
print $fd "\n";
|
||||
|
||||
}
|
|
@ -1,3 +0,0 @@
|
|||
- 2007-12-18
|
||||
- Initial Version
|
||||
|
|
@ -1,3 +0,0 @@
|
|||
- martin, Di Dez 18 21:04:13 CET 2007
|
||||
- initial version
|
||||
|
|
@ -1,56 +0,0 @@
|
|||
****** VoIP2FHEM or HOWTO control the FHEM with Asterisk ******
|
||||
|
||||
Description
|
||||
* This is a HOWTO about the use of a VoIP-DECT-Telephone as a remote
|
||||
controller for the FHEM-Devices.
|
||||
The provided scripts are under the GPL.
|
||||
|
||||
The Goal is
|
||||
-- Switching the FS20-Devices
|
||||
-- text2speach, the Telephone reads e.g. the measured-temp
|
||||
-- Possibility to start scripts with the Remote Telephone
|
||||
-- AND EVERYTHING MUST RUN ON THE NSLU2 :-)
|
||||
|
||||
Technical Overview
|
||||
* On the NLSU2 (or every other Linux Box) runs an Asterisk. This machine
|
||||
must not be the machine with the FHEM. I bought the Voip-DECT-Telephone
|
||||
Siemens Gigaset C470 IP (80.-EUR). It has a nice Webinterface and it is
|
||||
possible to read in a self made telephone book.
|
||||
The Asterisk calls depending on the dialed number a bash skript. After
|
||||
that Asterisk plays two soundfiles < text >< value > in a loop.
|
||||
|
||||
The NSLU2 is a weak machine. It always only creates a soundfile 1x and
|
||||
then stores it on the harddisk. A set of prebuild voices (e.g. digits
|
||||
from -20 to 90) are included. Some scripts for creating soundfiles and
|
||||
automatically the telephone book are provided too.
|
||||
Installation
|
||||
* Go to http://fhem.dnsalias.net/voip2fhem and download the files.
|
||||
-- Install with your package manager asterisk, sox, espeak. On the NLSU2:
|
||||
"apt-get install asterisk sox espeak".
|
||||
-- Debian: activate asterisk in the /etc/default/asterisk
|
||||
-- copy the scripts voip2fhem voip2fhem_create_telefonlist
|
||||
voip2fhem_create_txt2gsm to /usr/local/bin/ and be shure that they are
|
||||
executable (chmod +x /usr/local/bin/voip2fhem*)
|
||||
-- You can find on http://fhem.dnsalias.net/voip2fhem prepared voices:
|
||||
"tar -xvzf voip2fhem_voices.tar.gz -C /" and give the correct rights
|
||||
"chown -R asterisk.asterisk /var/tmp/voip2fhem"
|
||||
-- cp extensions.conf and sip.conf to /etc/asterisk/ and edit these files
|
||||
and the bash script /usr/local/bin/voip2fhem
|
||||
-- restart/reload asterisk (/etc/init.d/asterisk restart or asterisk -
|
||||
r and then "extensions reload" and "sip reload")
|
||||
Hints
|
||||
* -- if there isn't the required soundfile then the NSLU2 creates it. This
|
||||
needs minutes (example: the word "asterisk" needs 3 min). voip2fhem
|
||||
stores this file and the next time it will be used.
|
||||
-- Use the script voip2fhem_create_txt2gsm on a faster machine to create
|
||||
the sounds. Usage: voip2fhem_create_txt2gsm "I love FHEM". The soundfile
|
||||
is then automatically copied to /var/tmp/voip2fhem/
|
||||
-- it is also possible to connect the ASTERISK with the rest of the world
|
||||
(e.g. Sipgate, 1und1) :-)
|
||||
-- for debug asterisk: "asterisk -r", "sip debug"
|
||||
|
||||
|
||||
Have fun and success :-)
|
||||
Martin Haas
|
||||
fhem@martin-haas.de
|
||||
|
|
@ -1,55 +0,0 @@
|
|||
<html>
|
||||
<head>
|
||||
</head>
|
||||
<body>
|
||||
<h1> VoIP2FHEM or HOWTO control the FHEM with Asterisk</h1><br>
|
||||
<b>Description</b><br>
|
||||
<ul>This is a HOWTO about the use of a VoIP-DECT-Telephone as a remote controller for the <a href='http://fhem.de'>FHEM-Devices.</a><br>The provided scripts are under the GPL.<br>
|
||||
<br>
|
||||
The Goal is<br>
|
||||
-- Switching the FS20-Devices <br>
|
||||
-- text2speach, the Telephone reads e.g. the measured-temp <br>
|
||||
-- Possibility to start scripts with the Remote Telephone<br>
|
||||
-- AND EVERYTHING MUST RUN ON THE NSLU2 :-)<br>
|
||||
<br>
|
||||
</ul>
|
||||
|
||||
|
||||
<b>Technical Overview</b><br>
|
||||
<ul>
|
||||
On the NLSU2 (or every other Linux Box) runs an Asterisk. This machine must not be the machine with the FHEM. I bought the Voip-DECT-Telephone Siemens Gigaset C470 IP (80.-EUR). It has a nice Webinterface and it is possible to read in a self made telephone book.<br>
|
||||
The Asterisk calls depending on the dialed number a bash skript. After that Asterisk plays two soundfiles < text >< value > in a loop.<br>
|
||||
<br>
|
||||
The NSLU2 is a weak machine. It always only creates a soundfile 1x and then stores it on the harddisk. A set of prebuild voices (e.g. digits from -20 to 90) are included. Some scripts for creating soundfiles and automatically the telephone book are provided too.
|
||||
|
||||
</ul>
|
||||
|
||||
<b>Installation</b><br>
|
||||
<ul>
|
||||
Go to http://fhem.dnsalias.net/voip2fhem and download the files.<br>
|
||||
-- Install with your package manager asterisk, sox, espeak. On the NLSU2: "apt-get install asterisk sox espeak".<br>
|
||||
-- Debian: activate asterisk in the /etc/default/asterisk<br>
|
||||
-- copy the scripts voip2fhem voip2fhem_create_telefonlist voip2fhem_create_txt2gsm to /usr/local/bin/ and be shure that they are executable (chmod +x /usr/local/bin/voip2fhem*)<br>
|
||||
-- You can find on http://fhem.dnsalias.net/voip2fhem prepared voices: "tar -xvzf voip2fhem_voices.tar.gz -C /" and give the correct rights "chown -R asterisk.asterisk /var/tmp/voip2fhem" <br>
|
||||
-- cp extensions.conf and sip.conf to /etc/asterisk/ and edit these files and the bash script /usr/local/bin/voip2fhem<br>
|
||||
-- restart/reload asterisk (/etc/init.d/asterisk restart or asterisk -r and then "extensions reload" and "sip reload")
|
||||
</ul>
|
||||
|
||||
<b>Hints</b><br>
|
||||
<ul>
|
||||
-- if there isn't the required soundfile then the NSLU2 creates it. This needs minutes (example: the word "asterisk" needs 3 min). voip2fhem stores this file and the next time it will be used.<br>
|
||||
-- Use the script voip2fhem_create_txt2gsm on a faster machine to create the sounds. Usage: voip2fhem_create_txt2gsm "I love FHEM". The soundfile is then automatically copied to /var/tmp/voip2fhem/<br>
|
||||
-- it is also possible to connect the ASTERISK with the rest of the world (e.g. Sipgate, 1und1) :-)<br>
|
||||
-- for debug asterisk: "asterisk -r", "sip debug"<br>
|
||||
|
||||
</ul>
|
||||
|
||||
|
||||
|
||||
<br><br>
|
||||
Have fun and success :-)<br>
|
||||
Martin Haas<br>
|
||||
fhem@martin-haas.de<br>
|
||||
<br>
|
||||
</body>
|
||||
</html>
|
|
@ -1,47 +0,0 @@
|
|||
[FHEM]
|
||||
|
||||
|
||||
; Important for voip2fhem: System(PATH_TO_voip2fhem NAME_FHEM_DEV "TEXT FOR TELEPHONBOOK and espeak" FHEM_TYPE)
|
||||
; after every change of this file make "asterisk -r" and then "extensions reload"
|
||||
|
||||
exten => 3001,1,Answer()
|
||||
exten => 3001,2,System(/usr/local/bin/voip2fhem ks300 "Aussentemperatur ." KS300)
|
||||
exten => 3001,3,Playback(/tmp/asterisk1)
|
||||
exten => 3001,n,Playback(/tmp/asterisk2)
|
||||
exten => 3001,n,Wait(3)
|
||||
exten => 3001,n,Goto(3)
|
||||
|
||||
exten => 3002,1,Answer()
|
||||
exten => 3002,2,System(/usr/local/bin/voip2fhem kesselu "Kesseltemperatur kesselu ." HMS100)
|
||||
exten => 3002,3,Playback(/tmp/asterisk1)
|
||||
exten => 3002,4,Playback(/tmp/asterisk2)
|
||||
exten => 3002,n,Wait(3)
|
||||
exten => 3002,n,Goto(3)
|
||||
|
||||
exten => 3003,1,Answer()
|
||||
exten => 3003,2,System(/usr/local/bin/voip2fhem wz "Wohnzimmertemperatur ." FHT)
|
||||
exten => 3003,3,Playback(/tmp/asterisk1)
|
||||
exten => 3003,4,Playback(/tmp/asterisk2)
|
||||
exten => 3003,n,Wait(3)
|
||||
exten => 3003,n,Goto(3)
|
||||
|
||||
exten => 3004,1,Answer()
|
||||
exten => 3004,2,System(/usr/local/bin/voip2fhem nachto "Nachtlicht oben" FS20)
|
||||
exten => 3004,3,Playback(/tmp/asterisk1)
|
||||
exten => 3004,n,Wait(3)
|
||||
exten => 3004,n,Goto(3)
|
||||
|
||||
exten => 3005,1,Answer()
|
||||
exten => 3005,2,System(/usr/local/bin/voip2fhem stuwz1 "Fernsehlicht" FS20)
|
||||
exten => 3005,3,Playback(/tmp/asterisk1)
|
||||
exten => 3005,n,Wait(3)
|
||||
exten => 3005,n,Goto(3)
|
||||
|
||||
exten => 3006,1,Answer()
|
||||
exten => 3006,2,System(/usr/local/bin/voip2fhem ofen "Status Ofen ." FS20STATE)
|
||||
exten => 3006,3,Playback(/tmp/asterisk1)
|
||||
exten => 3006,n,Playback(/tmp/asterisk2)
|
||||
exten => 3006,n,Wait(3)
|
||||
exten => 3006,n,Goto(3)
|
||||
|
||||
|
|
@ -1,13 +0,0 @@
|
|||
[general]
|
||||
context=FHEM
|
||||
port=5060
|
||||
bindaddr=0.0.0.0
|
||||
|
||||
|
||||
; FHEM: VoIP-Telephone with the Name/Number 2000 and the password 1234
|
||||
[2000]
|
||||
type=friend
|
||||
context=FHEM
|
||||
secret=1234
|
||||
host=dynamic
|
||||
|
|
@ -1,72 +0,0 @@
|
|||
#!/bin/bash
|
||||
# Interface from Asterisk to fhem
|
||||
# this file is called from /etc/asterisk/extensions.conf
|
||||
# Martin Haas 071214
|
||||
|
||||
|
||||
|
||||
# if you want to use the english spoken espeak then change "espeak -v de" to "espeak"
|
||||
|
||||
|
||||
FHEM=localhost # if not localhost then set the port inside of FHEM to global
|
||||
FHEMport=7072
|
||||
location=/var/tmp/voip2fhem # later the owner must be asterisk.asterisk!
|
||||
|
||||
[[ ! -d $location ]] && mkdir $location
|
||||
|
||||
|
||||
|
||||
####################################################
|
||||
##
|
||||
providesound()
|
||||
{
|
||||
lvoice="$location/$(echo $voice | sed -e 's/-//g' -e 's/[ .:]/_/g').gsm"
|
||||
|
||||
echo $lvoice
|
||||
|
||||
if [ ! -f $lvoice ]
|
||||
then
|
||||
espeak -v de -s 120 -w /tmp/asterisk.wav "$voice"
|
||||
sox /tmp/asterisk.wav -r 8000 -c 1 $lvoice resample -ql
|
||||
fi
|
||||
cp $lvoice /tmp/asterisk$type.gsm
|
||||
|
||||
}
|
||||
|
||||
|
||||
###################################
|
||||
##
|
||||
case "$3" in
|
||||
|
||||
######################################
|
||||
KS300)
|
||||
temperature=$(echo "list $1" | netcat -w1 $FHEM $FHEMport | grep temperature | awk '{print $4}')
|
||||
[[ ${temperature:0:1} == - ]] && temperature="minus $temperature" ## negativ temperature
|
||||
voice=$2; type=1; providesound "$voice" $type
|
||||
voice=$temperature; type=2; providesound "$voice" $type
|
||||
;;
|
||||
######################################
|
||||
FHT)
|
||||
temperature=$(echo "list $1" | netcat -w1 $FHEM $FHEMport | grep measured-temp | awk '{print $4}')
|
||||
voice=$2; type=1; providesound "$voice" $type
|
||||
voice=$temperature; type=2; providesound "$voice" $type
|
||||
;;
|
||||
######################################
|
||||
FS20STATE)
|
||||
state=$(echo "list $1" | netcat -w1 $FHEM $FHEMport | grep STATE | awk '{print $2}')
|
||||
voice=$2; type=1; providesound "$voice" $type
|
||||
voice=$state; type=2; providesound "$voice" $type
|
||||
;;
|
||||
#####################################
|
||||
HMS100)
|
||||
temperature=$(echo "list $1" | netcat -w1 $FHEM $FHEMport | grep STATE | awk '{print $3}')
|
||||
voice=$2; type=1; providesound "$voice" $type
|
||||
voice=$temperature; type=2; providesound "$voice" $type
|
||||
;;
|
||||
######################################
|
||||
FS20)
|
||||
echo "set $1 toggle" | netcat -w1 $FHEM $FHEMport
|
||||
voice=$2; type=1; providesound "$voice" $type
|
||||
;;
|
||||
esac
|
||||
|
|
@ -1,30 +0,0 @@
|
|||
#!/bin/bash
|
||||
# this skript creates for e.g. the Siemens C470 IP a telephone book which can be read in by the webinterface of the telephone
|
||||
# The script reads the /etc/asterisk/extensions.conf and creates the /tmp/teledir.vcf
|
||||
# Martin Haas 071216
|
||||
#
|
||||
|
||||
# you need the tool unix2dos :-( It is depending on your Distribution included in unix2dos or tofrodos
|
||||
|
||||
telefonbook=/tmp/teledir.vcf
|
||||
|
||||
rm -f $telefonbook
|
||||
|
||||
grep System /etc/asterisk/extensions.conf | grep -v '^;' | \
|
||||
|
||||
while read fhemdev
|
||||
do
|
||||
number=$(echo $fhemdev | cut -d, -f1 | awk '{print $3}')
|
||||
name=$(echo $fhemdev | cut -d\" -f2 | sed 's/\./ /g')
|
||||
|
||||
echo "BEGIN:VCARD" >>$telefonbook
|
||||
echo "VERSION:2.1" >>$telefonbook
|
||||
echo "FN:$name" >>$telefonbook
|
||||
echo "N:$name" >>$telefonbook
|
||||
echo "TEL;HOME:$number" >>$telefonbook
|
||||
echo "END:VCARD" >>$telefonbook
|
||||
echo >>$telefonbook
|
||||
|
||||
done
|
||||
|
||||
unix2dos $telefonbook
|
|
@ -1,79 +0,0 @@
|
|||
#!/bin/bash
|
||||
# weak machines need a long time to create a gsm-Voicefile.
|
||||
# this script searches for an existing voice and if not it will create it
|
||||
# Martin Haas 071217
|
||||
|
||||
# The NSLU2 needs e.g. 5min to convert the word "Aussentemperatur"
|
||||
|
||||
# Call this file (on a faster machine :-) ) with the words to convert
|
||||
# e-g voip2fhem_create_txt2gsm "This is a test"
|
||||
# otherwise this script creates number from -20 to +90
|
||||
|
||||
# hint: cat examplefile | while read line; do ./voip2fhem_create_txt2gsm "$line"; done
|
||||
|
||||
|
||||
|
||||
|
||||
location=/var/tmp/voip2fhem # later the owner must be asterisk.asterisk
|
||||
|
||||
[[ ! -d $location ]] && { mkdir $location; chown asterisk.asterisk $location; }
|
||||
|
||||
|
||||
|
||||
|
||||
###################################################
|
||||
###
|
||||
CreateVoices()
|
||||
{
|
||||
lvoice="$location/$(echo $voice | sed 's/[ ,.:]/_/g').gsm"
|
||||
|
||||
echo $lvoice
|
||||
|
||||
if [ ! -f $lvoice ]
|
||||
then
|
||||
espeak -v de -s 120 -w /tmp/asterisk.wav "$voice"
|
||||
sox /tmp/asterisk.wav -r 8000 -c 1 $lvoice resample -ql
|
||||
fi
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
###################################################
|
||||
## main
|
||||
|
||||
if [[ $1 ]]
|
||||
then
|
||||
voice=$1
|
||||
CreateVoices "$voice"
|
||||
|
||||
else
|
||||
|
||||
for i in `seq -20 90 ` -0
|
||||
do
|
||||
if [ ${i:0:1} == - ]
|
||||
then
|
||||
m="minus $i" ## negativ temperature
|
||||
voice=$(echo $m | sed -e 's/-//g' -e 's/\./,/g') # English people: change , against .
|
||||
else
|
||||
voice=$(echo $i | sed 's/\./,/g') # English people: change , against .
|
||||
fi
|
||||
|
||||
CreateVoices "$voice"
|
||||
|
||||
origvoice=$voice
|
||||
|
||||
|
||||
for k in `seq 0 9`
|
||||
do
|
||||
|
||||
voice="$origvoice,$k" # English people: change , against .
|
||||
CreateVoices "$voice"
|
||||
voice=$origvoice
|
||||
|
||||
done
|
||||
|
||||
done
|
||||
|
||||
fi
|
|
@ -1,353 +0,0 @@
|
|||
#!perl
|
||||
#
|
||||
# read_ws2000 from device (elv art-Nr. 390-61) and provides socket service (like XPORT),
|
||||
# or act as client for this service
|
||||
# licence GPL2
|
||||
# Thomas Dressler 2008
|
||||
# $Id: ws2000_reader.pl,v 1.1 2008-05-10 21:10:38 tdressler Exp $
|
||||
|
||||
use Switch;
|
||||
use strict;
|
||||
use IO::Socket;
|
||||
use IO::Select;
|
||||
|
||||
our $PortObj;
|
||||
my $server;
|
||||
our $xport;
|
||||
our $sel;
|
||||
our $clients;
|
||||
our %sockets;
|
||||
my ($datum,$data,$lastdate,$lastdata);
|
||||
$SIG{INT}=$SIG{TERM}=\&signalhandler;
|
||||
$|=1;
|
||||
|
||||
PortOpen($ARGV[0]);
|
||||
|
||||
my $ServerPort=$ARGV[1];
|
||||
if ($ServerPort) {
|
||||
$server=IO::Socket::INET->new(LocalPort=>$ServerPort,
|
||||
ReuseAddr=>1,
|
||||
Listen=>10,
|
||||
timeout=>1,
|
||||
blocking=>0
|
||||
);
|
||||
die "ServerStart-Error: $@ \n" if !$server;
|
||||
$clients=IO::Select->new($server);
|
||||
}
|
||||
|
||||
|
||||
MAINLOOP:
|
||||
for(;;) {
|
||||
if($server) {
|
||||
#only for server mode
|
||||
my %message=undef;
|
||||
my $fh;
|
||||
while(my @ready=$clients->can_read(1)) {
|
||||
foreach $fh (@ready) {
|
||||
if ($fh==$server) {
|
||||
#new connection waiting
|
||||
my $new=$server->accept;
|
||||
$new->autoflush(1);
|
||||
$new->blocking(0);
|
||||
$new->timeout(1);
|
||||
$clients->add($new);
|
||||
my $host=$new->peerhost;
|
||||
$sockets{$new}=$host;
|
||||
print "\nNew Client:".$host."\n";
|
||||
#}else{
|
||||
# my $out=undef;
|
||||
# $fh->read($out,1);
|
||||
# $message{$fh}=$out;
|
||||
}
|
||||
}
|
||||
}
|
||||
#check living connections
|
||||
foreach my $fh($clients->handles) {
|
||||
next if $fh==$server;
|
||||
next if ($fh->peerhost);
|
||||
print "Terminate ".$sockets{$fh}. " by Check1\n";
|
||||
Client_disconnect($fh);
|
||||
}
|
||||
|
||||
}
|
||||
$data=get_data();
|
||||
next if ! $data;
|
||||
$datum = time();
|
||||
next if ($data eq $lastdata) && (($datum - $lastdate) < 30);
|
||||
my $result=decode_data($data);
|
||||
print scalar localtime().":".$result."\n";
|
||||
$lastdata = $data;
|
||||
$lastdate = $datum;
|
||||
}
|
||||
PortClose();
|
||||
exit 0;
|
||||
#--------SUBs -----------------------------
|
||||
sub Clientdisconnect{
|
||||
my $fh=shift;
|
||||
print "\n Client ".$sockets{$fh}." disconnected!\n";
|
||||
$clients->remove($fh);
|
||||
delete $sockets{$fh};
|
||||
$fh->shutdown(2);
|
||||
$fh->close;
|
||||
}
|
||||
sub PortOpen{
|
||||
my $PortName=shift;
|
||||
my $quiet=shift ||undef;
|
||||
|
||||
if ($PortName=~/^\/dev|^COM/) {
|
||||
#normal devices (/dev)
|
||||
my $OS=$^O;
|
||||
if ($OS eq 'MSWin32') {
|
||||
eval ("use Win32::SerialPort;");
|
||||
die "$@\n" if ($@);
|
||||
$PortObj = new Win32::SerialPort ($PortName, $quiet)
|
||||
|| die "Can't open $PortName: $^E\n"; # $quiet is optional
|
||||
} else {
|
||||
eval ("use Device::SerialPort;");
|
||||
die "$@\n" if ($@);
|
||||
$PortObj = new Device::SerialPort ($PortName, $quiet)
|
||||
|| die "Can't open $PortName: $^E\n"; # $quiet is optional
|
||||
|
||||
}
|
||||
#Parameter 19200,8,2,Odd,None
|
||||
$PortObj->baudrate(19200);
|
||||
$PortObj->databits(8);
|
||||
$PortObj->parity("odd");
|
||||
$PortObj->stopbits(2);
|
||||
$PortObj->handshake("none");
|
||||
if (! $PortObj->write_settings) {
|
||||
undef $PortObj;
|
||||
die "Write Settings failed!\n";
|
||||
}
|
||||
$sel=IO::Select->new($PortObj->{FD} );
|
||||
}elsif($PortName=~/([\w.]+):(\d{1,5})/){
|
||||
#Sockets(hostname:port)
|
||||
my $host=$1;
|
||||
my $port=$2;
|
||||
$xport=IO::Socket::INET->new(PeerAddr=>$host,
|
||||
PeerPort=>$port,
|
||||
timeout=>1,
|
||||
blocking=>0
|
||||
);
|
||||
die "Cannot connect to $PortName -> $@ ( $!) \n" if ! $xport;
|
||||
$xport->autoflush(1);
|
||||
$sel=IO::Select->new($xport);
|
||||
}else{
|
||||
die "$PortName is no device and not implemented!\n";
|
||||
}
|
||||
}
|
||||
sub PortClose {
|
||||
$PortObj->close if ($PortObj);
|
||||
if ($xport) {
|
||||
$clients->remove($xport) if $clients;
|
||||
$xport->shutdown(2);
|
||||
$xport->close;
|
||||
}
|
||||
if ($clients) {
|
||||
foreach my $socket($clients->handles) {
|
||||
Clientdisconnect($socket);
|
||||
}
|
||||
}
|
||||
}
|
||||
sub signalhandler {
|
||||
my $signal=shift;
|
||||
PortClose();
|
||||
print "\nTerminated by Signal $signal!\n";
|
||||
exit;
|
||||
}
|
||||
|
||||
sub get_data {
|
||||
|
||||
my $STX=2;
|
||||
my $ETX=3;
|
||||
my $retval='';
|
||||
my $status='';
|
||||
my $out=undef;
|
||||
my $message;
|
||||
my $byte;
|
||||
for(;;) {
|
||||
#sleep 1 if(!defined($out) || length($out) == 0);
|
||||
$out=undef;
|
||||
if ($xport) {
|
||||
|
||||
#my @readable=$select->can_read(1);
|
||||
#next if $#readable<0;
|
||||
|
||||
|
||||
#my $fh;
|
||||
#foreach $fh (@readable) {
|
||||
|
||||
next if ! $sel->can_read(1);
|
||||
$xport->read($out,1);
|
||||
#if ($xport->eof) {
|
||||
# print "Xport eof\n";
|
||||
# print "Server disconnected, terminate!\n";
|
||||
# PortClose();
|
||||
# exit 1;
|
||||
|
||||
#}
|
||||
|
||||
|
||||
|
||||
}elsif($PortObj) {
|
||||
$out = $PortObj->read(1);
|
||||
}
|
||||
next if(!defined($out) || length($out) == 0) ;
|
||||
|
||||
|
||||
$byte=ord($out);
|
||||
if($byte eq $STX) {
|
||||
#Log 4, "M232: return value \'" . $retval . "\'";
|
||||
$status= "STX";
|
||||
$message=$out;
|
||||
} elsif($byte eq $ETX) {
|
||||
$status= "ETX";
|
||||
$message .=$out;
|
||||
} elsif ($status eq "STX"){
|
||||
$byte=$byte & 0x7F;
|
||||
$retval .= chr($byte);
|
||||
$message .=$out;
|
||||
}
|
||||
last if($status eq "ETX");
|
||||
|
||||
}
|
||||
if ($server) {
|
||||
foreach my $client($clients->can_write(1)) {
|
||||
next if $client == $server;
|
||||
if (!$client->send($message)){
|
||||
Clientdisconnect($client);
|
||||
next;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
return $retval;
|
||||
}
|
||||
|
||||
|
||||
sub decode_data {
|
||||
my ($sensor,$daten1,$einheit1,$daten2,$einheit2,$daten3,$einheit3,$result);
|
||||
my $data=shift;
|
||||
my ($typ,$w1,$w2,$w3,$w4,$w5)=unpack("U*",$data);
|
||||
my $group = ($typ & 0x70)/16 ;#/slash for komodo syntax checker!
|
||||
my $snr = $typ % 16;
|
||||
|
||||
|
||||
switch ( $group ){
|
||||
case 7 {
|
||||
$sensor = "Fernbedienung";
|
||||
$daten1 = $w1 * 10000 + $w2 * 1000 + $w3 * 100 + $w4 * 10 + $w5;
|
||||
$result = $sensor . "=" . $daten1 . $einheit1;
|
||||
}
|
||||
case 0 {
|
||||
if ($snr < 8) {
|
||||
$sensor = "Temperatursensor V1.1(" . $snr . ")";
|
||||
}else{
|
||||
$sensor = "Temperatursensor V1.2(" .($snr - 8). ")";
|
||||
}
|
||||
if ($w1 >= 64) {
|
||||
$daten1 = ((255 - $w1 - $w2) / 10) * (-1);
|
||||
}else{
|
||||
$daten1 = (($w1 * 128 + $w2) / 10);
|
||||
}
|
||||
$einheit1 = " °C";
|
||||
$result = $sensor . "=" . $daten1 . $einheit1;
|
||||
}
|
||||
case 1 {
|
||||
if ($snr <8) {
|
||||
$sensor = "Temperatursensor mit Feuchte V1.1(" . $snr . ")";
|
||||
}else{
|
||||
$sensor = "Temperatursensor mit Feuchte V1.2(" . ($snr - 8) . ")";
|
||||
}
|
||||
if ($w1 >= 64) {
|
||||
$daten1 = ((255 - $w1 - $w2) / 10) * (-1);
|
||||
}else{
|
||||
$daten1 = (($w1 * 128 + $w2) / 10);
|
||||
}
|
||||
|
||||
$daten2 = $w3;
|
||||
$daten3 = 0;
|
||||
$einheit1 = " °C";
|
||||
$einheit2 = " %";
|
||||
|
||||
$result = $sensor . "=" . $daten1 . $einheit1 . " " . $daten2 .$einheit2;
|
||||
}
|
||||
case 2 {
|
||||
if ( $snr < 8 ) {
|
||||
$sensor = "Regensensor V1.1(" . $snr . ")";
|
||||
}else{
|
||||
$sensor = "Regensensor V1.2(" . ($snr - 8) . ")"
|
||||
}
|
||||
$daten1 = ($w1 * 128 + $w2) * 0.36;
|
||||
$einheit1 = " l/m²";
|
||||
$result = $sensor . "=" . $daten1 . $einheit1;
|
||||
}
|
||||
case 3 {
|
||||
if ($snr < 8) {
|
||||
$sensor = "Windsensor V1.1(" . $snr . ")";
|
||||
}else{
|
||||
$sensor = "Windsensor V1.2(" & ($snr - 8) . ")";
|
||||
}
|
||||
switch( $w3) {
|
||||
case 0 { $einheit3 = "±0 °";}
|
||||
case 1 { $einheit3 = "± 22,5 °";}
|
||||
case 2 { $einheit3 = "± 45 °";}
|
||||
case 3 { $einheit3 = "± 67,5 °";}
|
||||
}
|
||||
$daten1 = ($w1 * 128 + $w2) / 10;
|
||||
$daten2 = $w4 * 128 + $w5;
|
||||
$einheit1 = " km/h";
|
||||
$einheit2 = " °";
|
||||
$result = $sensor . "=" . $daten1 . $einheit1 . " " . $daten2 . $einheit2 . " " . $einheit3;
|
||||
}
|
||||
case 4 {
|
||||
if ($snr < 8) {
|
||||
$sensor = "Innensensor V1.1(" . $snr . ")";
|
||||
}else{
|
||||
$sensor = "Innensensor V1.2(" . ($snr - 8) . ")";
|
||||
}
|
||||
if ($w1 >= 64) {
|
||||
$daten1 = ((255 - $w1 - $w2) / 10) * (-1);
|
||||
}else{
|
||||
$daten1 = (($w1 * 128 + $w2) / 10);
|
||||
}
|
||||
$daten2 = $w3;
|
||||
$daten3 = $w4 * 128 + $w5;
|
||||
$einheit1 = " °C";
|
||||
$einheit2 = " %";
|
||||
$einheit3 = " hPa";
|
||||
$result = $sensor . "=" . $daten1 . $einheit1 . " " . $daten2 . $einheit2 . " " . $daten3 . $einheit3;
|
||||
}
|
||||
case 5 {
|
||||
$sensor = "Helligkeitssensor V1.2(" . ($snr - 8) . ")";
|
||||
switch ($w3) {
|
||||
case 0 {$daten1 = 1;}
|
||||
case 1 {$daten1 = 10;}
|
||||
case 2 {$daten1 = 100;}
|
||||
case 3 {$daten1 = 1000;}
|
||||
}
|
||||
$daten1 = $daten1 * ($w1 * 128 + $w2);
|
||||
$einheit1 = "Lux";
|
||||
$result = $sensor . "=" . $daten1 . $einheit1;
|
||||
}
|
||||
case 6 {
|
||||
$sensor = "Pyranometer V1.2(" . ($snr - 8) . ")";
|
||||
switch ($w3) {
|
||||
case 0 {$daten1 = 1;}
|
||||
case 1 {$daten1 = 10;}
|
||||
case 2 {$daten1 = 100;}
|
||||
case 3 {$daten1 = 1000;}
|
||||
}
|
||||
$daten1 = $daten1 * ($w1 * 128 + $w2);
|
||||
$einheit1 = " W/m²";
|
||||
$result = $sensor . "=" . $daten1 . $einheit1;
|
||||
}
|
||||
else {
|
||||
$sensor = "Störung";
|
||||
$daten1 = $typ;
|
||||
$result = $sensor . "(Group:" . $group . "/Typ:" . $typ . ")";
|
||||
}#switch else
|
||||
|
||||
}#switch
|
||||
return $result;
|
||||
}
|
|
@ -1,70 +0,0 @@
|
|||
EM1000EM
|
||||
reply to request 0x7a
|
||||
|
||||
of
|
||||
fs ty
|
||||
et pe content
|
||||
----------------------
|
||||
00 w counter 2 Hz, counts down from 600 to 0
|
||||
01
|
||||
02 w number of readings
|
||||
03
|
||||
04 ?? ?
|
||||
05 ?? ?
|
||||
06 b number of devices
|
||||
07 dw energy/Wh (total)
|
||||
08
|
||||
09
|
||||
10
|
||||
11 ?? ?
|
||||
12 ?? ?
|
||||
13 w number of pulses
|
||||
14
|
||||
15 w number of pulses max (unsure)
|
||||
16
|
||||
17 w offset 1
|
||||
18
|
||||
19 w offset 2
|
||||
20
|
||||
21 ?? ?
|
||||
22 ?? ?
|
||||
23 ?? ?
|
||||
24 ?? ?
|
||||
25 ?? ?
|
||||
26 ?? ?
|
||||
27 ?? ?
|
||||
28 ?? ?
|
||||
29 ?? ?
|
||||
30 ?? ?
|
||||
31 ?? ?
|
||||
32 ?? ?
|
||||
33 dw energy/Wh (h)
|
||||
34
|
||||
35
|
||||
36
|
||||
37 dw energy/Wh (d)
|
||||
38
|
||||
39
|
||||
40
|
||||
41 dw energy/Wh (w)
|
||||
42
|
||||
43
|
||||
44
|
||||
45 w power limit/W
|
||||
46
|
||||
47 w price/(EUR/kWh*10000)
|
||||
48
|
||||
49 w revolutions/kWh (for EM1000WZ)
|
||||
50
|
||||
|
||||
Notes:
|
||||
1) types:
|
||||
b byte
|
||||
w word
|
||||
dw double word
|
||||
2) field 15 is unsure
|
||||
3) one can observe the following values for a freshly
|
||||
attached device (all readings 0):
|
||||
a) offset 2= offset 1 + number of readings
|
||||
b) fields 21..32 are zero
|
||||
4) fields 17..32 are probably further offsets to a buffer
|
|
@ -1,6 +0,0 @@
|
|||
The snippet files are here just for reference, some of them were created by me,
|
||||
some of them were sent to me by fellow users of the FHZ1000, others found in
|
||||
the newsgroups.
|
||||
|
||||
Do not assume that they were verified, they are by no means thought as an
|
||||
official documentation.
|
|
@ -1,37 +0,0 @@
|
|||
86_FS10.pm is for reading ELV (www.elv.de) weather Sensors, using a Hardware
|
||||
(Part No. 68-390-61) and communicates with pcwsd from Sven Geggus.
|
||||
|
||||
Currently temperature, windspeed, rain and brightness sensors are supported.
|
||||
|
||||
For use with FHEM you have to compile pcwsd like usual, it can be found here
|
||||
http://geggus.net/sven/pcwsd/
|
||||
|
||||
Start pcwsd deamon with
|
||||
pcwsd -d /dev/ttyUSB4 -ld /var/log/fs10- -tlf %Y-%m-%d_%T
|
||||
|
||||
A few minutes later you should see files with temperature values.
|
||||
|
||||
For use with FHEM define
|
||||
|
||||
define fs10 FS10 127.0.0.1 4711 which means pcwsd run on localhost, port 4711
|
||||
|
||||
If you only interested in viewing temperature values with a FHEM frontend like
|
||||
pgm3, 86_FS10.pm can be ommited.
|
||||
|
||||
To display a user defined FS10 temperature graphic in pgm3 define
|
||||
|
||||
########################
|
||||
#
|
||||
$sortnumber=7;
|
||||
$userdef[$sortnumber]['name']='IndoorTemp';
|
||||
$userdef[$sortnumber]['valuefield']=2;
|
||||
$userdef[$sortnumber]['gnuplottype']='temperature';
|
||||
$userdef[$sortnumber]['logpath']='/var/log/fs10/idtemp_7.gnu';
|
||||
$userdef[$sortnumber]['room']='indoor';
|
||||
$userdef[$sortnumber]['semlong']='Temp indor';
|
||||
$userdef[$sortnumber]['semshort']='°';
|
||||
$userdef[$sortnumber]['imagemax']=725;
|
||||
$userdef[$sortnumber]['imagemay']=52;
|
||||
$userdef[$sortnumber]['maxcount']=575;
|
||||
$userdef[$sortnumber]['XcorrectMainText']=25;
|
||||
$userdef[$sortnumber]['logrotatelines']=2050;
|
File diff suppressed because it is too large
Load Diff
|
@ -1,277 +0,0 @@
|
|||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
|
||||
|
||||
<html xmlns="http://www.w3.org/1999/xhtml">
|
||||
|
||||
<head>
|
||||
<title>FHEM FAQ</title>
|
||||
</head>
|
||||
|
||||
<body style="background-color: white;">
|
||||
|
||||
<h2>FHEM FAQ</h2>
|
||||
|
||||
<a href="#faq1">1. I am using fhem.pl with an fhz1000.pl config file and fhem.pl
|
||||
won't start</a><br><br>
|
||||
|
||||
<a href="#faq2">2. I get "undefined" messages in the log after upgrading
|
||||
fhem.pl</a><br><br>
|
||||
|
||||
<a href="#faq3">3. I switched on a FS20 device directly (without the remote),
|
||||
but the fhem.pl did not noticed it. Is it a bug?</a><br><br>
|
||||
|
||||
<a href="#faq4">4. I have some FS20/FHT/HMS devices. How do I know their
|
||||
housecode?</a><br><br>
|
||||
|
||||
<a href="#faq5">5. I have the code for my devices in the ELV notation, which
|
||||
contains 1,2,3 and 4, but you require a hex code. How should I convert
|
||||
it?</a><br><br>
|
||||
|
||||
<a href="#faq6">6. I replaced my FHZ1X00PC, now the FHT80b's does not work
|
||||
anymore. Help me!</a><br><br>
|
||||
|
||||
<a href="#faq7">7. I can specify an optional ml/raincounter for a KS300. Why
|
||||
do you think that 255 should be the default?</a><br><br>
|
||||
|
||||
<a href="#faq8">8. The time specification of the builtin at command is not very
|
||||
flexible. Please add day/month/weekday to it.</a><br><br>
|
||||
|
||||
<a href="#faq9">9. I defined my FS20STR as an FHT device, but I do not get
|
||||
any data from it.</a><br><br>
|
||||
|
||||
<a href="#faq10">10. How to convert the FHT8b code seen in its display to the
|
||||
hex code needed by fhem.pl?</a><br><br>
|
||||
|
||||
<a href="#faq11">11. I'd like to use this sunrise/sunset stuff, can you help
|
||||
me?</a><br><br>
|
||||
|
||||
<a href="#faq12">12. I'd like to switch on the ventilator if the FHT tells me its too hot. How to tell fhem to do that?</a><br><br>
|
||||
|
||||
<br>
|
||||
<br>
|
||||
<br>
|
||||
<br>
|
||||
|
||||
<a name="faq1"></a>
|
||||
<b>1. I am using fhem.pl with an fhz1000.pl config file and fhem.pl won't
|
||||
start</b>
|
||||
|
||||
<ul>
|
||||
The syntax changed, you have to modify you config file:
|
||||
<ul>
|
||||
<li>logfile/modpath/pidfile/port/verbose "renamed" to "attr global xx</li>
|
||||
<ul>
|
||||
<li>change logfile <xxx> to attr global logfile <xxx></li>
|
||||
<li>change modpath <xxx> to attr global modpath <xxx></li>
|
||||
<li>change pidfile <xxx> to attr global pidfilename <xxx></li>
|
||||
<li>change port <xxx> to attr global port <xxx></li>
|
||||
<li>change verbose <xxx> to attr global verbose <xxx></li>
|
||||
</ul>
|
||||
<li>savefile renamed to "attr global statefile" (<b>not</b> savefile)</li>
|
||||
<li>at/notify "renamed" to "define at/notify"<br>
|
||||
This means you have to give a name to each of your at's or
|
||||
notify commands. E.g.:
|
||||
<ul>
|
||||
<li><code>at *07:00 set lamp on</code><br>
|
||||
becomes<br>
|
||||
<code>define wake_me at *07:00 set lamp on</code></li>
|
||||
<li><code>notify fire:on "send_sms"</code><br>
|
||||
becomes<br>
|
||||
<code>define fire_alarm notify fire:on "send_sms"</code><br>
|
||||
</ul>
|
||||
This seems to be tedious at the beginning but you get easy
|
||||
deletion and attribute specification for these commands.
|
||||
</ul>
|
||||
</ul>
|
||||
|
||||
|
||||
<a name="faq2"></a>
|
||||
<b>2. I get "undefined" messages in the log after upgrading fhem.pl</b>
|
||||
<ul>
|
||||
Stop fhem.pl, delete the previous .save file and restart fhem.pl.
|
||||
If the problem still exists, send a bugreport.
|
||||
</ul>
|
||||
|
||||
|
||||
<a name="faq3"></a>
|
||||
<b>3. I switched on a FS20 device directly (without the remote), but
|
||||
the fhem.pl did not noticed it.<br>Is it a bug?</b>
|
||||
<ul>
|
||||
The protocol used by the FS20 family is quite simple: it is </b>not</b>
|
||||
encrypted in any way, and there is no feedback to the sender. So if you
|
||||
push any buttons on a pure receiver, no radio waves will be sent out, and
|
||||
the FHZ1000 won't notice anything. The FHZ1000PC does not even know if
|
||||
somebody received its message, it simply sends it out 3 times and hopes
|
||||
for good luck.<br>
|
||||
To answer the question: it is not a bug :-)
|
||||
</ul>
|
||||
|
||||
|
||||
<a name="faq4"></a>
|
||||
<b>4. I have some FS20/FHT/HMS devices.<br>
|
||||
How do I know their housecode?</b><br>
|
||||
<ul>
|
||||
If you already programmed some devices, then just start fhem.pl with one
|
||||
of the example configuration files, and watch the log. When activating a
|
||||
device (e.g. with the remote) then it will be logged as an unknown device
|
||||
with the housecode. Note: the verbose level must be 3 or higher. KS300
|
||||
devices do not have a proper code, so you can use anything.
|
||||
</ul>
|
||||
|
||||
|
||||
<a name="faq5"></a>
|
||||
<b>5. I have the code for my devices in the ELV notation, which contains 1,2,3
|
||||
and 4, but you require a hex code.<br> How should I convert it?</b>
|
||||
|
||||
<ul>
|
||||
The code used by ELV is in the "quaternal" (?) system plus one added to each
|
||||
digit, so you can even use the 4 button remote for programming. To convert,
|
||||
you have two choices: the program four2hex in the contrib directory, or the
|
||||
good old unix program bc.
|
||||
<ul>
|
||||
<li>From quaternal (ELV Remote) to hex (fhem.pl):<br>
|
||||
<pre>
|
||||
% bc
|
||||
obase=16
|
||||
ibase=4
|
||||
<elv number></pre>
|
||||
where <elv number> is the number used on the remote, but 1
|
||||
substracted from every digit (so each digit is between 0 and 3).</li>
|
||||
|
||||
<li>From hex (fhem.pl) to quaternal (ELV Remote):<br>
|
||||
<pre>
|
||||
% bc
|
||||
ibase=16
|
||||
obase=4
|
||||
<hex number></pre>
|
||||
Now add 1 to each digit of the result, and prepend it with 1's if
|
||||
it has less than 4 digits.</li> </ul>
|
||||
|
||||
|
||||
</ul>
|
||||
|
||||
|
||||
<a name="faq6"></a>
|
||||
<b>6. I replaced my FHZ1X00PC, now the FHT80b's does not work anymore.<br>
|
||||
Help me!</b>
|
||||
<ul>
|
||||
The FHT80b's are talking to a single FHZ1XXX device, which has a unique
|
||||
"FHTcode". You have two choices: if you know the old FHTcode, then you can
|
||||
set it, or you can tell the FHT80b to forget the old FHZ, and start talking
|
||||
with the new one.
|
||||
<ul>
|
||||
<li>Set the FHTcode: The problem with this method is that I don't know how
|
||||
to read out the value, we just can change it with<br>
|
||||
<code>set FHZ FHTcode <hex-code></code></li>
|
||||
<li>Resync the FHT80b: Press PROG until "Sond" appears, then select "CEnt"
|
||||
with the wheel, press PROG again, Select "nA" with the wheel, press PROG
|
||||
again.</li>
|
||||
|
||||
</ul>
|
||||
</ul>
|
||||
|
||||
|
||||
<a name="faq7"></a>
|
||||
<b>7. I can specify an optional ml/raincounter for a KS300.<br>
|
||||
Why do you think that 255 should be the default?</b>
|
||||
<ul>
|
||||
The manual talks about 0.3l resolution, but I wanted to calibrate my device.
|
||||
So I filled a plastic bottle with 0.5 liter water from the measuring cup,
|
||||
drilled a small hole in the bottom of the bottle, let the water flow slowly
|
||||
in the KS300 rain-cup, and looked at the counter after the bottle was empty.<br>
|
||||
|
||||
The raincounter was incremented by 130 ticks. The diameter of my KS300
|
||||
rain-cup is 13.9 cm, the area ca 151.75 cm<sup>2</sup>, which
|
||||
is ca 1/65.9 m<sup>2</sup>.
|
||||
The 0.5 liter corresponds to 32.95 liter per m<sup>2</sup>. 130 ticks
|
||||
correspond to 32.95 l/m<sum>2</sup> -> 1 tick is ca 253 ml. I estimate
|
||||
the error margin to +/- 2%<br>
|
||||
|
||||
You are welcome to do your own experiments, I am interested in the results.
|
||||
</ul>
|
||||
|
||||
|
||||
<a name="faq8"></a>
|
||||
<b>8. The time specification of the builtin at command is not very
|
||||
flexible.<br> Please add day/month/weekday to it.</b>
|
||||
<ul>
|
||||
I think the command is complex and flexible enough. Use a perl expression
|
||||
for this functionality like (described in the commandref.html):
|
||||
<pre>at *07:00:00 { fhz "set lamp on" if($we) }</pre>
|
||||
</ul>
|
||||
|
||||
|
||||
<a name="faq9"></a>
|
||||
<b>9. I defined my FS20STR as an FHT device, but I do not get any data from
|
||||
it.</b>
|
||||
<ul>
|
||||
The FS20STR is an FS20 device, even if it looks like an FHT80b.
|
||||
You'll get "only" on-for-timer and off-for-timer events sent.
|
||||
</ul>
|
||||
|
||||
|
||||
<a name="faq10"></a>
|
||||
<b>10. How to convert the FHT8b code seen in its display to the hex code needed
|
||||
by fhem.pl?</b>
|
||||
|
||||
<ul>
|
||||
Convert the first 2 digits first from decimal to hex, then the next two. Example:<br>
|
||||
<pre>
|
||||
% bc
|
||||
obase=16
|
||||
<first two digits>
|
||||
<last two digits></pre>
|
||||
E.g The FHT8b code 1121 is 0b15 for the fhem.pl
|
||||
</ul>
|
||||
|
||||
|
||||
<a name="faq11"></a>
|
||||
<b>11. I'd like to use this sunrise/sunset stuff, can you help me?</b>
|
||||
<ul>
|
||||
Copy contrib/99_SUNRISE_EL.pm into your FHEM directory.
|
||||
Next look for the geographic coordinates of your home, e.g with a GPS
|
||||
receiver or with googleearth. Compute the latitude/longitude as needed, and
|
||||
enter them in your lastinclude file with the command:
|
||||
<pre>{sunrise_coord("<latitude>", "<longitude>", "") }</pre>
|
||||
If everything is ok, typing
|
||||
<pre>{ sunrise_abs() }</pre>
|
||||
in the telnet prompt, will return the time of the sunrise today, in a
|
||||
HH:MM:SS format.<br><br>
|
||||
|
||||
99_SUNRISE_EL.pm is the ExtraLight version of the original 99_SUNRISE.pm,
|
||||
which needs the DateTime::Event::Sunrise perl module, which in turn is
|
||||
usually difficult to install. If you still want to use the original module,
|
||||
then the initialization string will be slightly different:
|
||||
<pre>{sunrise_coord("<latitude>", "<longitude>", "Europe/Berlin") }</pre>
|
||||
|
||||
</ul>
|
||||
|
||||
<a name="faq12"></a>
|
||||
<b>12. I'd like to switch on the ventilator if the FHT tells me its too hot. How to tell fhem to do that?</b>
|
||||
<ul>
|
||||
|
||||
To get used to the methods, we do it step by step. Telnet to fhem, and type
|
||||
the following:
|
||||
|
||||
<pre>
|
||||
# Check simply the value. It is the same as seen in "list"
|
||||
FHZ> {$value{myfht}}
|
||||
measured-temp: 23.8 (Celsius)
|
||||
|
||||
# Get the second word, so we can compare it.
|
||||
FHZ> { my @a = split(" ", $value{myfht});; $a[1] }
|
||||
23.8
|
||||
|
||||
# Set the ventilator on now, if its too hot.
|
||||
FHZ> { my @a = split(" ", $value{myfht});; fhem("set ventilator on") if($a[1] > 25.0) }
|
||||
|
||||
# Now do this regularly
|
||||
FHZ> define chilldown at +*00:30:00 { my @a = split(" ", $value{myfht});; fhem("set ventilator on") if($a[1] > 25.0) }
|
||||
|
||||
# An alternative:
|
||||
FHZ> define chilldown at +*00:30:00 { fhem("set ventilator on") if($value{myfht} gt "measured-temp: 25.0") }
|
||||
</pre>
|
||||
|
||||
</ul>
|
||||
|
||||
</body>
|
||||
</html>
|
|
@ -1,234 +0,0 @@
|
|||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
|
||||
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
|
||||
<html xmlns="http://www.w3.org/1999/xhtml">
|
||||
|
||||
<head>
|
||||
<title>Home of FHEM</title>
|
||||
</head>
|
||||
|
||||
<body style="background-color: white">
|
||||
|
||||
|
||||
<h1>FHEM</h1>
|
||||
GPL'd server to access devices like FHZ1000/FHZ1300,EM1010PC,WS300,SCIVT.
|
||||
Formerly known as fhz1000.pl
|
||||
<br/><br/>
|
||||
Current Version: (as of =DATE=) is <a href="http://www.koeniglich.de/fhem/fhem-=VERS=.tar.gz">=VERS=</a>
|
||||
See the <a href="CHANGED">CHANGED</a> file for current changes.
|
||||
|
||||
<h2>Description</h2>
|
||||
<ul>
|
||||
This program makes the FHZ1000/FHZ1300/WS300 and other USB devices sold by ELV,
|
||||
Conrad and others useable with Linux. In fact, there is nothing Linux special
|
||||
in it, there are reports from OS X and Windows. You should be able to use it on
|
||||
other platforms as long as you can access the hardware as a serial device.<br>
|
||||
The program runs as a server, you can control it via telnet, command line
|
||||
program or TCP/IP directly, like the supplied web frontends do.<br> <br>
|
||||
|
||||
Currently implemented features:<br>
|
||||
<ul>
|
||||
<li>Via the FHZ module (with access to one or more FHZ1000/FHZ1300 device):
|
||||
<ul>
|
||||
<li>reading and sending FS20 events (on/off/dimming, timer commands)<br>
|
||||
<li>support of FS20 address features function group, local and global master
|
||||
<li>reading and changing FHT80b parameters (temp, actuator, etc).<br>
|
||||
The FHT8b seems to work too. <b>Note:</b> the FHT8 wont work.<br>
|
||||
Internal software buffer to prevent lost commands.<br>
|
||||
</li>
|
||||
<li>reading HMS data (HMS100-T,-TF,-WD,-MG,-TFK and RM100-2)</li>
|
||||
<li>reading KS300 data</li>
|
||||
</ul>
|
||||
<b>Note:</b>The FHZ1350 WLAN is probably not working due to a prorietary
|
||||
encryption.
|
||||
</li>
|
||||
<li>reading WS300 data, and up to 9 attached devices</li>
|
||||
<li>reading EM1000WZ/EM1000EM data via an attached EM1010PC</li>
|
||||
<li>reading attached SCIVT devices</li>
|
||||
<li>reading attached M232 devices</li>
|
||||
<li>reading attached WS2000/WS25000 devices, also via raw network converters(xport)</li>
|
||||
<li>extract sensor data from IPWE networked weather data receiver</li>
|
||||
<li>logging events to files or databases, with regexp filters</li>
|
||||
<li>notifying external programs or internal modules when receiving certain
|
||||
events</li>
|
||||
<li>timed commands (e.g. switching a lamp on from sunset till midnight)</li>
|
||||
<li>modular architecture, easy to add your special device</li>
|
||||
<li>different web frontends, choose your favorite</li>
|
||||
<br>
|
||||
</ul>
|
||||
See <a href="commandref.html">commandref.html</a> for a detailed command
|
||||
description and <a href="faq.html">faq.html</a> for the F.A.Q.
|
||||
</ul>
|
||||
|
||||
<h2>Links:</h2>
|
||||
<ul>
|
||||
Homepage: <a href="http://www.koeniglich.de/fhem/fhem.html">
|
||||
http://www.koeniglich.de/fhem/fhem.html</a><br>
|
||||
Download: <a href="http://www.koeniglich.de/fhem/fhem-=VERS=.tar.gz">
|
||||
http://www.koeniglich.de/fhem/fhem-=VERS=.tar.gz</a><br>
|
||||
FAQ: <a href="http://www.koeniglich.de/fhem/faq.html">
|
||||
http://www.koeniglich.de/fhem/faq.html</a><br>
|
||||
Google-Group: <a href="http://groups.google.com/group/FHZ1000-users-on-unix">
|
||||
http://groups.google.com/group/FHZ1000-users-on-unix</a><br>
|
||||
Martins Web frontend (webpgm3): <a href="http://www.martin-haas.de/fhz">
|
||||
http://www.martin-haas.de/fhz</a><br>
|
||||
Another Martins Web frontend (myHCE): <a href="http://www.fischer-net.de/projekte/haustechnik/myhce.html">http://www.fischer-net.de/projekte/haustechnik/myhce.html</a><br>
|
||||
CVS@berlios: <a href="http://developer.berlios.de/projects/fhem">
|
||||
http://developer.berlios.de/projects/fhem</a><br>
|
||||
LinViex (home automation frontend):
|
||||
<a href="http://sourceforge.net/projects/linviex">
|
||||
|
||||
http://sourceforge.net/projects/linviex</a><br><br>
|
||||
Device/OS Specific installation guides:<br>
|
||||
<ul>
|
||||
<li>Linux driver installation:
|
||||
<a href="http://www.koeniglich.de/fhem/linux.html">
|
||||
http://www.koeniglich.de/fhem/linux.html</a></li>
|
||||
<li>Windows driver installation:
|
||||
<a href="http://fhz4linux.info/tiki-index.php?page=Driver%20installation">
|
||||
http://fhz4linux.info/tiki-index.php?page=Driver%20installation</a> <br>
|
||||
(use "Solution B", only COM1..COM9 is supported)</li>
|
||||
<li>Instructions for Nas/Routers (NSLU2):
|
||||
<a href="http://www.martin-haas.de/fhz/nslu2fhz">
|
||||
http://www.martin-haas.de/fhz/nslu2fhz</a></li>
|
||||
<li>Instructions for the Fritz!Box:
|
||||
<a href="fritzbox.html">
|
||||
http://www.koeniglich.de/fhem/fritzbox.html</a></li>
|
||||
<li>Instructions for the Allnet all6250:
|
||||
<a href="http://wiki.dungeon.de/all6250_opennas_mit_fhem">
|
||||
http://wiki.dungeon.de/all6250_opennas_mit_fhem</a></li>
|
||||
</ul>
|
||||
|
||||
</ul>
|
||||
<h2>Related projects:</h2>
|
||||
<ul>
|
||||
<a href="http://fhz4linux.info/">http://fhz4linux.info/</a><br>
|
||||
</ul>
|
||||
|
||||
<h2>Installation</h2>
|
||||
<ul>
|
||||
|
||||
<h3>Perl modules</h3>
|
||||
<ul>
|
||||
You need perl >=5.6, on Unix with the Device::SerialPort (<a
|
||||
href="http://search.cpan.org/dist/Device-SerialPort/">
|
||||
http://search.cpan.org/dist/Device-SerialPort/</a>),
|
||||
on Windows Win32::SerialPort (use ActiveState's ActivePerl)
|
||||
module.
|
||||
If this module reports <code>Can't call method "opened" on an undefined
|
||||
value...</code> when starting the server, then you either may ignore
|
||||
this message, or replace the mentioned line with:<pre>
|
||||
$self->{HANDLE}->close if (defined($self->{HANDLE}) &&
|
||||
$self->{HANDLE}->opened);</pre>
|
||||
</ul>
|
||||
|
||||
<h3>Server installation on Unix</h3>
|
||||
<ul>
|
||||
<li>Copy the file <code>fhem.pl</code> into your path (e.g.
|
||||
<code>/usr/local/bin</code>), and the FHEM directory e.g. to
|
||||
<code>/usr/local/lib</code>. </li>
|
||||
<li>Copy additional modules from the contrib directory
|
||||
(like 99_SUNRISE_EL.pm)</li>
|
||||
<li>Make sure that you can access the serial USB
|
||||
device (e.g. <code>/dev/tts/USB0</code>).</li>
|
||||
<li>Create a configuration file (see the examples directory and
|
||||
docs/commandref.html), change at least the modpath
|
||||
(<code>/usr/local/lib</code>) and define FHZ FHZ (<code>/dev/tts/USB0</code>)
|
||||
parameters.</li>
|
||||
<li>Start the server with <code>fhem.pl <configfile></code></li>
|
||||
</ul>
|
||||
|
||||
<h3>Server installation on Windows</h3>
|
||||
If you are using cygwin for your perl installation you can follow the guidelines for Unix.
|
||||
<ul>
|
||||
<li>be sure you have perl.exe in your path (%PATH%)</li>
|
||||
<li>unpack distribution in a directory of your choice </li>
|
||||
<li>Copy additional modules from the contrib directory
|
||||
(like 99_SUNRISE_EL.pm)</li>
|
||||
<li>Make sure that you can access the serial USB
|
||||
device via virtual COM-Port or via socket(e.g. <code>COMX or xport:10001</code>).</li>
|
||||
<li>Create a configuration file (see the examples directory and
|
||||
docs/commandref.html), change at least the modpath
|
||||
(<code>your_install_dir</code>) and define FHZ FHZ (<code>COM10</code>)
|
||||
parameters.</li>
|
||||
<li>Start the server with <code>fhem.pl <configfile></code></li>
|
||||
</ul>
|
||||
|
||||
|
||||
<h3>General Notes for Webfrontends:</h3>
|
||||
<ul>
|
||||
<li>You don't have to install all of them, one is probably more than
|
||||
enough :-)</li>
|
||||
<li>The web server and the fhem server must be on the same host</li>
|
||||
<li><b>Important:</b> Make sure you add some protection (.htaccess, etc)
|
||||
else everybody will be able to set your devices</li>
|
||||
<li>The list below contains the 2 actively maintained fronteds:</li>
|
||||
</ul>
|
||||
|
||||
<h3>Web frontend 2 (webfrontend/pgm2)</h3>
|
||||
<ul>
|
||||
This frontend is a FHEM module implementing a HTTP server. It has support
|
||||
for grouping devices into rooms, manipulating devices, direct fhem commands,
|
||||
displaying logfiles as text or plot (SVG builtin or PNG by gnuplot),
|
||||
navigating/zooming in the plots. <br/>
|
||||
|
||||
Screenshots: <a href="pgm2-1.png">overview</a>, <a href="pgm2-2.png">detail</a>,
|
||||
<a href="pgm2-3.png">SVG-plots</a>.
|
||||
<br><br>
|
||||
For installation see the webpgm/pgm2/README file.<br>
|
||||
</ul>
|
||||
|
||||
<h3>Web frontend 3 (webfrontend/pgm3)</h3>
|
||||
<ul>
|
||||
This frontend is PHP based and was contributed by Martin Haas.
|
||||
Look at the webfrontends/pgm3/docs for more documentation or at
|
||||
<a href="pgm3-0.5.1.png">this screenshot</a>. A lot more details can be
|
||||
found on Martins page: <a href="http://www.martin-haas.de/fhz">
|
||||
http://www.martin-haas.de/fhz</a>
|
||||
<br><br>
|
||||
|
||||
<ul>
|
||||
<li>Install PHP and enable it by commenting in the "LoadModule
|
||||
phpX_module ..." directive in httpd.conf (perhaps it is already
|
||||
done by your distro). Restart/reload httpd.</li>
|
||||
|
||||
<li>Create a directory (e.g.: /home/httpd/html/pgm3) and copy all the
|
||||
files from the webfrontend/pgm3 to this directory.<br>Make sure that this
|
||||
directory is writeable by the webserver!</li>
|
||||
|
||||
<li>Edit index.php (/home/httpd/html/pgm3/index.php), and check the
|
||||
required settings section</li>
|
||||
|
||||
<li>If you want to have access to the FHT temperature logs, then:
|
||||
<ul>
|
||||
<li>Make sure gnuplot is installed</li>
|
||||
<li>check the showgnuplot section in index.php</li>
|
||||
<li>For each FHT device copy the file docs/gnuplot/gnuplot.wz to
|
||||
gnuplot.fhtdevicename (to the /home/httpd/html/pgm3 directory) and
|
||||
replace fht.log in this file with the absolute name of the current
|
||||
logfile.</li>
|
||||
</ul>
|
||||
<li>Call <your-site>/pgm3/index.php</li>
|
||||
</ul>
|
||||
</ul>
|
||||
|
||||
<h2>License:</h2>
|
||||
<ul>
|
||||
Copyright:<br>
|
||||
<ul>
|
||||
<li>Rudolf Koenig (r dot koenig at koeniglich dot de)</li>
|
||||
<li>Raoul Matthiessen (webfrontends/pgm1)</li>
|
||||
<li>Martin Haas (webfrontends/pgm3)</li>
|
||||
</ul>
|
||||
License: GPL (v2)
|
||||
</ul>
|
||||
|
||||
</ul>
|
||||
|
||||
<h2>Misc:</h2>
|
||||
<ul>
|
||||
Thanks for Tosti for inspiration and numerous other people for help. <br>
|
||||
</ul>
|
||||
|
||||
</body>
|
||||
|
||||
</html>
|
|
@ -1,141 +0,0 @@
|
|||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
|
||||
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
|
||||
<html xmlns="http://www.w3.org/1999/xhtml">
|
||||
|
||||
<head>
|
||||
<title>Home of FHEM</title>
|
||||
</head>
|
||||
|
||||
<body style="background-color: white">
|
||||
|
||||
|
||||
<h1><a href="fhem.html">FHEM</a> on the Fritz!Box</h1>
|
||||
|
||||
<h2>Description</h2>
|
||||
<ul>
|
||||
This document describes how to install <a href="fhem.html">FHEM</a> on the
|
||||
fritzbox.<br>
|
||||
<br>
|
||||
What works:<br>
|
||||
<ul>
|
||||
<li>The basic fhem.pl server with at commands, notify, logging (tested)</li>
|
||||
<li>FHZ1000 and FHZ1300 (both tested)</li>
|
||||
<li>FS20, FHT and KS300-2 (tested)</li>
|
||||
<li>HMS (untested, but should work)</li>
|
||||
<li>SunSet/SunRise.</li>
|
||||
<li>one of the Web frontends (webpgm2, the builtin one)</li>
|
||||
</ul>
|
||||
|
||||
<br>
|
||||
What does not work right now:<br>
|
||||
<ul>
|
||||
<li>Gnuplot. No idea how to replace it, perhaps we compile a fritzbox
|
||||
version</li>
|
||||
<li>EM1010PC. I tried it without batteries, and I think the USB interface
|
||||
cannot power an USB hub, an FHZ1300 and an EM1010PC together. The fritzbox
|
||||
resets when trying to initialize the devices. More experiments needed.</li>
|
||||
<li>WS300PC. Untested, don't have one.</li>
|
||||
</ul>
|
||||
</ul>
|
||||
|
||||
<h2>Howto</h2>
|
||||
<ul>
|
||||
Tested on the fritzbox 7170, with Firmware 29.04.49.<br>
|
||||
<b>Note:</b>The kernel modules are for kernel 2.16.13.1, and perl is compiled
|
||||
for uCLibc 0.9.28.<br><br>
|
||||
|
||||
Prerequisites:<br>
|
||||
<ul>
|
||||
<li>You need a fritzbox with an USB host port. Check your kernel version.
|
||||
If it won't match the version above, see the "Compile tips" in this
|
||||
document.</li>
|
||||
<li>an USB hub (a small passive one is enough).</li>
|
||||
<li>an FHZ1000 or FHZ1300</li>
|
||||
<li>a USB stick, at least 64MB. As the fritzbox is USB 1.1 only,
|
||||
the slowest is fast enough.</li>
|
||||
<li>telnet access for the fritzbox. See the links on how to enable it.
|
||||
<li>the complete fhem package from the links section.</li>
|
||||
</ul>
|
||||
<br>
|
||||
Installation:<br>
|
||||
<ul>
|
||||
<li>Connect the USB stick to a PC, and unpack the content of the
|
||||
fb_fhem_x.y.tar.gz in the root directory of the USB stick. You'll
|
||||
get a perl 5.6.2 installation with just those modules wich are needed
|
||||
by fhem, an empty 32MB swapfile with a swapon/swapoff command,
|
||||
the fhem server with an empty configuration file, and an rc.fhem
|
||||
script which should start everything.</li>
|
||||
<li>Connect the USB stick and the FHZ1x00 via the USB hub to the
|
||||
fritzbox.</li>
|
||||
<li>Log in via telnet to the fritzbox.</li>
|
||||
<li>Change into the directory /var/media/ftp/*Partition*/usr/fhem .</li>
|
||||
<li>Execute the command rc.fhem.</li>
|
||||
<li>Now you can either use a Web browser:<br>
|
||||
<ul>
|
||||
<a href="http://192.168.178.1:8083/fhem">
|
||||
http://192.168.178.1:8083/fhem</a><br>
|
||||
</ul>
|
||||
with the online help, or choose the command-line via:<br>
|
||||
<ul>
|
||||
telnet fritz.box 7072<br>
|
||||
</ul>
|
||||
to define your devices.</li>
|
||||
<li>To enable automatic startup after reboot of the fritzbox enter the
|
||||
following at the end of the /var/flash/debug.cfg:<br>
|
||||
<ul>
|
||||
/bin/sleep 120<br>
|
||||
cd /var/media/ftp/*Partition*/usr/fhem && ./rc.fhem
|
||||
</ul></li>
|
||||
</ul>
|
||||
<br>
|
||||
Tips:<br>
|
||||
<ul>
|
||||
<li>The installation creates the link /var/usr to the USB disk
|
||||
(/var/media/ftp/*Partition*/usr)</li>
|
||||
<li>In the beginning only the most necessary (in my opinion, anyway :-)
|
||||
modules are installed: FHZ/FS20/HMS/KS300/SUNRISE_EL. If you want to
|
||||
use other modules, they are in the /var/usr/fhem/FHEM/unused directory,
|
||||
just move the needed module in the parent directory, and do a
|
||||
"reload module" (without the .pm suffix).</li>
|
||||
<li>If you use webpgm2, and unsure about an attribute, then just define it,
|
||||
you'll get a link to the description of the attribute in the online
|
||||
help".</li>
|
||||
<li>If your're unsure about the parameters for a command try "?" as an
|
||||
argument, e.g.:
|
||||
<ul>
|
||||
?<br>
|
||||
define <name> ?<br>
|
||||
define <name> <type> ?<br>
|
||||
set <name> ?<br>
|
||||
</ul>
|
||||
</li>
|
||||
</ul>
|
||||
</ul>
|
||||
|
||||
<h2>Compile tips</h2>
|
||||
<ul>
|
||||
<b>Note:</b> You don't need to compile anything if you have the correct
|
||||
kernel and uclibc version.<br><br>
|
||||
|
||||
I compiled the ftdi_sio module with the help of the ds26-15.1 packages, see
|
||||
the links.<br>
|
||||
The ftdi_sio module had to be modified, as 2.16.13 does not contain the USB
|
||||
ID's of the ELV devices.<br>
|
||||
Compiling a working perl for the fritzbox was a nightmare. After compiling
|
||||
5.8.8 I dicovered it has a strange bug: Appending numbers to strings won't
|
||||
work on the fritzbox. This is why I compiled an "old" (5.6.2) one, which
|
||||
seems to work perfectly. </ul>
|
||||
|
||||
<h2>Links</h2>
|
||||
<ul>
|
||||
<li>Complete fhem package for the fritzbox: <a href="fb_fhem_0.3.tar.gz">
|
||||
fb_fhem_0.3.tar.gz</a></li>
|
||||
<li>Telnet on the fritzbox:
|
||||
<a href="http://www.ip-phone-forum.de/showthread.php?t=69245">
|
||||
ip-phone-thread</a></li>
|
||||
<li>Compiler for the fritzbox:
|
||||
<a href="http://www.ip-phone-forum.de/showthread.php?t=142389">
|
||||
ds26-15.1</a></li>
|
||||
</body>
|
||||
|
||||
</html>
|
|
@ -1,44 +0,0 @@
|
|||
*** orig/drivers/usb/serial/ftdi_sio.c 2004-12-14 02:54:04.000000000 +0100
|
||||
--- linux/drivers/usb/serial/ftdi_sio.c 2004-12-13 19:04:24.000000000 +0100
|
||||
*************** static struct usb_device_id id_table_8U2
|
||||
*** 350,355 ****
|
||||
--- 350,356 ----
|
||||
{ USB_DEVICE_VER(FTDI_VID, PROTEGO_SPECIAL_3, 0, 0x3ff) },
|
||||
{ USB_DEVICE_VER(FTDI_VID, PROTEGO_SPECIAL_4, 0, 0x3ff) },
|
||||
{ USB_DEVICE_VER(FTDI_VID, FTDI_ELV_UO100_PID, 0, 0x3ff) },
|
||||
+ { USB_DEVICE_VER(FTDI_VID, FTDI_ELV_FHZ1000_PID, 0, 0x3ff) },
|
||||
{ } /* Terminating entry */
|
||||
};
|
||||
|
||||
*************** static struct usb_device_id id_table_FT2
|
||||
*** 431,436 ****
|
||||
--- 432,438 ----
|
||||
{ USB_DEVICE_VER(FTDI_VID, PROTEGO_SPECIAL_3, 0x400, 0xffff) },
|
||||
{ USB_DEVICE_VER(FTDI_VID, PROTEGO_SPECIAL_4, 0x400, 0xffff) },
|
||||
{ USB_DEVICE_VER(FTDI_VID, FTDI_ELV_UO100_PID, 0x400, 0xffff) },
|
||||
+ { USB_DEVICE_VER(FTDI_VID, FTDI_ELV_FHZ1000_PID, 0x400, 0xffff) },
|
||||
{ USB_DEVICE(FTDI_VID, FTDI_CCSICDU20_0_PID) },
|
||||
{ USB_DEVICE(FTDI_VID, FTDI_CCSICDU40_1_PID) },
|
||||
{ } /* Terminating entry */
|
||||
*************** static __devinitdata struct usb_device_i
|
||||
*** 531,536 ****
|
||||
--- 533,539 ----
|
||||
{ USB_DEVICE(FTDI_VID, PROTEGO_SPECIAL_3) },
|
||||
{ USB_DEVICE(FTDI_VID, PROTEGO_SPECIAL_4) },
|
||||
{ USB_DEVICE(FTDI_VID, FTDI_ELV_UO100_PID) },
|
||||
+ { USB_DEVICE(FTDI_VID, FTDI_ELV_FHZ1000_PID) },
|
||||
{ USB_DEVICE(FTDI_VID, FTDI_CCSICDU20_0_PID) },
|
||||
{ USB_DEVICE(FTDI_VID, FTDI_CCSICDU40_1_PID) },
|
||||
{ } /* Terminating entry */
|
||||
*** orig/drivers/usb/serial/ftdi_sio.h 2004-12-14 02:54:04.000000000 +0100
|
||||
--- linux/drivers/usb/serial/ftdi_sio.h 2004-12-13 19:03:21.000000000 +0100
|
||||
***************
|
||||
*** 143,148 ****
|
||||
--- 143,149 ----
|
||||
|
||||
/* ELV USB Module UO100 (PID sent by Stefan Frings) */
|
||||
#define FTDI_ELV_UO100_PID 0xFB58 /* Product Id */
|
||||
+ #define FTDI_ELV_FHZ1000_PID 0xF06F /* Product Id */
|
||||
|
||||
/*
|
||||
* Definitions for ID TECH (www.idt-net.com) devices
|
|
@ -1,149 +0,0 @@
|
|||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
|
||||
|
||||
<html xmlns="http://www.w3.org/1999/xhtml">
|
||||
|
||||
<head>
|
||||
<title>fhem.pl - Hints for GNU/Linux</title>
|
||||
</head>
|
||||
|
||||
<body style="background-color: white;">
|
||||
|
||||
<h2>fhem.pl - Hints for GNU/Linux</h2>
|
||||
|
||||
<table border=1><tr><td>
|
||||
Note: Depending on the GNU/Linux distribution (Debian, openSuSE, etc.) and version of the Linux kernel you may or <i>may not</i> have to do the following steps.<br>
|
||||
It is worth giving it a try without any modifications <b>first</b>.<br>
|
||||
We have convinced the kernel developers to enable all (currently known) ELV devices by default. Starting with kernel 2.6.24.2 (e.g. openSUSE 11) the changes below are <b>not</b> required. You can check your running kernel version using the command:
|
||||
<code><br>uname -r<br></code>
|
||||
</td></tr></table>
|
||||
<hr>
|
||||
<p><b><a name="onedevice">One device</a></b><br>
|
||||
If you connect one USB device (FHZ1000PC, FHZ1300PC, EM1010PC, WS300, ...)
|
||||
to your GNU/Linux server you can use the regular <i>ftdi_sio</i> kernel module.
|
||||
However, it may not recognize our device. Therefore you need to get the
|
||||
<i>vendor</i> and <i>product</i> codes:
|
||||
<code><br>
|
||||
# lsusb<br>
|
||||
...<br>
|
||||
Bus 002 Device 002: ID <b>0403</b>:<b>e0e8</b> Future Technology Devices International, Ltd <br>
|
||||
...<br>
|
||||
</code><br>
|
||||
Now you need to edit your <code>/etc/modprobe.conf</code> or
|
||||
<code>/etc/modprobe.conf.local</code> file (depending on your distribution).
|
||||
Add the following line to it:<br>
|
||||
|
||||
<code><br>
|
||||
options ftdi_sio vendor=0x<b>0403</b> product=0x<b>e0e8</b><br>
|
||||
</code><br>
|
||||
Replace the vendor and product code with the output of the <i>lsusb</i> command.
|
||||
The you load the module using:<br>
|
||||
<code><br>
|
||||
# modprobe ftdi_sio<br>
|
||||
</code><br>
|
||||
<hr>
|
||||
<p><b><a name="multipledevices">Multiple devices</a></b><br>
|
||||
If you're using multiple USB devices (FHZ1000PC, FHZ1300PC, EM1010PC, WS300, ...)
|
||||
you cannot use the method above. You need to modify the ftdi_sio kernel module
|
||||
to make it work. The following example was done with openSuSE 10.1:<br>
|
||||
You need to have the kernel-source-<i>version</i> RPM of your
|
||||
current kernel (see output of <code>uname -r</code>) installed.<br>
|
||||
<code><br>
|
||||
# cd /usr/src/linux<br>
|
||||
# make cloneconfig<br>
|
||||
# make modules_prepare<br>
|
||||
# cp /boot/symvers-2.6.*-default.gz /usr/src/linux<br>
|
||||
# mv symvers-2.6.*-default.gz Module.symvers.gz<br>
|
||||
# gunzip /usr/src/linux/Module.symvers.gz<br>
|
||||
# make modules_prepare<br>
|
||||
# cd drivers/usb/serial<br>
|
||||
</code>
|
||||
For the EM1010PC you (may) need to add the following line:
|
||||
<code><br>
|
||||
# vi ftdi_sio.h<br>
|
||||
...<br>
|
||||
#define FTDI_ELV_WS500_PID 0xE0E9 /* PC-Wetterstation (WS 500) */<br>
|
||||
<b>#define FTDI_ELV_EM1010PC_PID 0xE0EF /* EM 1010 PC */</b><br>
|
||||
</code><br>
|
||||
Now we need to uncomment some lines to enable all of our devices.
|
||||
<code><br>
|
||||
# vi ftdi_sio.c<br>
|
||||
...<br>
|
||||
{ USB_DEVICE(FTDI_VID, FTDI_ELV_WS300PC_PID) }, <br>
|
||||
{ USB_DEVICE(FTDI_VID, FTDI_ELV_FHZ1300PC_PID) },<br>
|
||||
{ USB_DEVICE(FTDI_VID, FTDI_ELV_WS500_PID) }, <br>
|
||||
{ USB_DEVICE(FTDI_VID, FTDI_ELV_EM1010PC_PID) },<br>
|
||||
...<br>
|
||||
</code><br>
|
||||
Remove the <b>/*</b> and <b>*/</b> of your devices and save the file.
|
||||
<br>
|
||||
<code>
|
||||
# cd /usr/src/linux<br>
|
||||
</code>
|
||||
Now you have 3 choices:<br>
|
||||
<table border=1>
|
||||
<tr><td>
|
||||
<code>
|
||||
# mv Module.symvers Module.symvers.notneeded<br>
|
||||
# make M=drivers/usb/serial</code>
|
||||
<td>
|
||||
... to build the modules for all of <i>usb serial</i>.<br>
|
||||
If you have a less powerful machine like the ARM-Based NSLU2 then it is sufficient to only build the required module.
|
||||
</td></tr>
|
||||
<td><code>
|
||||
# make modules</code>
|
||||
</td><td>
|
||||
... to build all modules (takes a long time).
|
||||
</td></tr>
|
||||
<tr><td>
|
||||
<code>
|
||||
# make driver/usb/serial/ftdi_sio.ko
|
||||
</code>
|
||||
</td><td>
|
||||
... to build just the <i>ftdi_sio.ko</i> module. However, this does not seem to be working always.
|
||||
</td></tr>
|
||||
</table>
|
||||
Once you have the module:<br>
|
||||
<code><br>
|
||||
# cd /lib/modules/<i>yourKernelVerion</i>/kernel/drivers/usb/serial<br>
|
||||
# cp ftdi_sio.ko ftdi_sio.ko_backup<br>
|
||||
# cp /usr/src/linux/drivers/usb/serial/ftdi_sio.ko .<br>
|
||||
</code><br>
|
||||
To activete it you may need to stop applications (like fhem) who
|
||||
are using the /dev/ttyUSB device and unload the module and load it again.<br>
|
||||
<code><br>
|
||||
# rmmod ftdi_so<br>
|
||||
# modprobe ftdi_so<br>
|
||||
</code><br>
|
||||
You should now see multiple ttyUSB devices:
|
||||
<code><br>
|
||||
# ls -l /dev/ttyUSB*<br>
|
||||
crw-rw---- 1 root uucp 188, 0 2007-02-11 23:00 /dev/ttyUSB0<br>
|
||||
crw-rw---- 1 root uucp 188, 1 2007-02-11 23:00 /dev/ttyUSB1<br>
|
||||
</code><br>
|
||||
<hr>
|
||||
<p><b><a name="devicelinks">Device links</a></b><br>
|
||||
If you're using multiple USB devices (FHZ, EM, WS...) it might occur that the
|
||||
enumeration of the /dev/ttyUSB<i>n</i> numbers get mixed up if one of the
|
||||
device is missing or after a reboot.<br>
|
||||
Starting with kernel 2.6 the UDEV implements means for using virtual names
|
||||
instead of the bare numbers.<br>
|
||||
Edit the file <code>/etc/udev/rules.d/10-udev.rules</code> (create if necessary)
|
||||
and insert the following lines:
|
||||
<br>
|
||||
If you use udev prior to version 103:<br>
|
||||
<code>
|
||||
KERNEL=="ttyUSB*", SYSFS{product}=="ELV FHZ 1300 PC", SYMLINK+="elv_fhz1300pc"<br>
|
||||
KERNEL=="ttyUSB*", SYSFS{product}=="ELV EM 1010 PC", SYMLINK+="elv_em1010pc"<br>
|
||||
</code><br>
|
||||
Starting with udev 103 the SYSFS will be replaced by ATTRS:
|
||||
<br>
|
||||
<code>
|
||||
KERNEL=="ttyUSB*", ATTRS{product}=="ELV FHZ 1300 PC", SYMLINK+="elv_fhz1300pc"<br>
|
||||
KERNEL=="ttyUSB*", ATTRS{product}=="ELV EM 1010 PC", SYMLINK+="elv_em1010pc"<br>
|
||||
</code><br>
|
||||
|
||||
Now you need to reload (rmmod/modprobe) the ftdio_sio kernel module to
|
||||
use the device paths <code><b>/dev/elv_fhz1300pc</b></code> or
|
||||
<code><b>/dev/elv_em1010pc</b></code> in your FHEM configuration file.
|
||||
</body>
|
||||
</html>
|
Binary file not shown.
Before Width: | Height: | Size: 37 KiB |
Binary file not shown.
Before Width: | Height: | Size: 64 KiB |
Binary file not shown.
Before Width: | Height: | Size: 44 KiB |
Binary file not shown.
Before Width: | Height: | Size: 93 KiB |
Binary file not shown.
Before Width: | Height: | Size: 28 KiB |
|
@ -1,22 +0,0 @@
|
|||
On the telnet prompt do:
|
||||
{FS20_Parse(undef, "<code>");}
|
||||
e.g.
|
||||
{FS20_Parse(undef, "81xx04xx0101a0011234030011")}
|
||||
|
||||
where <code> is one of:
|
||||
|
||||
81xx04xx0101a0011234030011 FS20 dev: 1234 button: 03 on (11)
|
||||
81xx04xx0101a0011234030000 FS20 dev: 1234 button: 03 off (00)
|
||||
|
||||
810d04xx4027a001de53187654321f KS300: Raincounter hex:123 (ca 75l/m2),
|
||||
Wind 45.6 km/h Humidity: 78%, Temp: 13.5
|
||||
Unknown fields: d,e,f
|
||||
{FhzDecode("810d04xx4027a001de53187654321f")}
|
||||
|
||||
810e04d70213a001b16d000003000000 RM100-2 smoke on
|
||||
810e04d70213a001b16d000000000000 RM100-2 smoke off
|
||||
|
||||
81xx04xx0101a0011234030011 FS20 dev: 1234 button: 03 on (11)
|
||||
|
||||
To send it:
|
||||
set FHZ raw 04 0101a0011234030011
|
|
@ -1,28 +0,0 @@
|
|||
|
||||
810e041f0213a001d396000000000000
|
||||
|
||||
// Reset:
|
||||
810e04ea0293a001ae06000000000000
|
||||
// Normal:
|
||||
810e046a0213a001ae06000000000000
|
||||
|
||||
==========
|
||||
810e04ba0293a001b1d3000000000000
|
||||
810e04a90293a0016a09000000000000
|
||||
|
||||
By andikt:
|
||||
// Batteries are inserted into the smoke detector
|
||||
810e04540293a001b16d000000000000
|
||||
[the same comes 10 times]
|
||||
|
||||
// No smoke applied, status messages each 30min
|
||||
810e04d40213a001b16d000000000000
|
||||
|
||||
// Smoke applied, detector beeps loud
|
||||
810e04d70213a001b16d000003000000
|
||||
|
||||
// no more smoke, detector stops beeping, red LED flashes for some more
|
||||
// seconds
|
||||
810e04d40213a001b16d000000000000
|
||||
|
||||
|
|
@ -1,74 +0,0 @@
|
|||
Startup
|
||||
-------
|
||||
1a
|
||||
PUT C9 - 02 01 1F 64
|
||||
1.st fhz1000: C9 - 01 02 1F 02 78 05 5C 24 FF
|
||||
2.nd fhz1000: C9 - 01 02 1F 02 78 05 5C 24 FF
|
||||
3.rd fhz1000: C9 - 01 02 1F 02 78 05 5C 0A FF
|
||||
1b
|
||||
PUT C9 - 02 01 1F 0A
|
||||
4.th fhz1000: C9 - 01 02 1F 02 78 07 B6 22 80
|
||||
1c
|
||||
PUT C9 - 02 01 1F 60
|
||||
C9 - 01 02 1F 02 78 07 1C 22 80
|
||||
|
||||
2
|
||||
PUT 04 - C9 01 84 57 02 08
|
||||
1.st fhz1000: C9 - 01 02 84 01 08 05 FF 13 6E 21 BC 4B 1B # Serial no: 136E21BC (?)
|
||||
3.rd fhz1000: C9 - 01 02 84 01 08 05 FF 13 6E 29 0E 51 18 # Serial no: 136E290E (?)
|
||||
|
||||
3
|
||||
PUT: 04 - C9 01 86
|
||||
PUT: 04 - C9 01 96
|
||||
PUT: C9 - 02 01 61 04 0C 10 12 0A # Set Date to 2004-12-16 14:10
|
||||
|
||||
|
||||
Switching FS20 device on / off
|
||||
------------------------------
|
||||
|
||||
PUT: 04 - 020101 - HHHH BT VL
|
||||
|
||||
HHHH: Transmitter (Hauscode)
|
||||
BT: Button
|
||||
VL: Values:
|
||||
00 => off,
|
||||
01 => dim06%,
|
||||
02 => dim12%,
|
||||
03 => dim18%,
|
||||
04 => dim25%,
|
||||
05 => dim31%,
|
||||
06 => dim37%,
|
||||
07 => dim43%,
|
||||
08 => dim50%,
|
||||
09 => dim56%,
|
||||
0A => dim62%,
|
||||
0B => dim68%,
|
||||
0C => dim75%,
|
||||
0D => dim81%,
|
||||
0E => dim87%,
|
||||
0F => dim93%,
|
||||
10 => dim100%,
|
||||
11 => on, # Set to previous dim value (before switching it off)
|
||||
12 => toggle, # between off and previous dim val
|
||||
13 => dimup,
|
||||
14 => dimdown,
|
||||
15 => dimupdown,
|
||||
16 => timer,
|
||||
17 => sendstate,
|
||||
18 => off-for-timer,
|
||||
19 => on-for-timer,
|
||||
1a => on-old-for-timer,
|
||||
1b => reset,
|
||||
|
||||
The FSST20 switches on for dim*.
|
||||
|
||||
When setting bit 6 (counted from 1) in the value, you can also
|
||||
send a further byte, the time as suggested in snippet_6.
|
||||
|
||||
The FS20ST only respects this for the values
|
||||
timer, off-for-timer, on-for-timer
|
||||
If the timer is set, then it works for dim*, on, *-for-timer
|
||||
|
||||
sendstate does not work for the FS20ST
|
||||
|
||||
=================================
|
|
@ -1,102 +0,0 @@
|
|||
// Init FHZ1000PC (Studio) mit FHT80b und HMS
|
||||
<- 81 06 c9 2c 02 01 1f 0a
|
||||
-> 81 0b c9 fb 01 02 1f 02 78 07 b6 22 80
|
||||
<- 81 08 04 ba c9 01 84 5e 0b 03
|
||||
-> 81 0a c9 ea 01 02 84 01 03 01 5b 03
|
||||
<- 81 05 04 50 c9 01 86
|
||||
<- 81 0b 04 __ 02 01 83 HH HH 65 ff 66 ff // FHT80b 1
|
||||
<- 81 0b 04 __ 02 01 83 HH HH 65 ff 66 ff // FHT80b 2
|
||||
<- 81 06 04 62 c9 01 96 02
|
||||
<- 81 0a c9 af 02 01 61 05 0a 0e 16 18 // Datum Uhrzeit
|
||||
|
||||
// Init FHZ1000PC (Standard) mit FHT80b und HMS
|
||||
<- 81 06 c9 82 02 01 1f 60
|
||||
-> 81 0b c9 61 01 02 1f 02 78 07 1c 22 80
|
||||
<- 81 08 04 af c9 01 84 57 02 08
|
||||
-> 81 0f c9 __ 01 02 84 01 08 07 80 xx xx xx xx 51 0f // Seriennummer
|
||||
<- 81 05 04 50 c9 01 86
|
||||
<- 81 0b 04 __ 02 01 83 HH HH 65 ff 66 ff // FHT80b 1
|
||||
<- 81 05 04 60 c9 01 96
|
||||
<- 81 0a c9 __ 02 01 61 jj mm tt ss mm // Datum Uhrzeit
|
||||
<- 81 05 04 4f c9 01 85 // Speicherabfrage
|
||||
-> 81 07 c9 ac 01 02 85 01 23 // 23 ?bytes? frei
|
||||
<- 81 0b 04 __ 02 01 83 HH HH 65 ff 66 ff // FHT80b 2
|
||||
<- 81 05 04 4f c9 01 85 // Speicherabfrage
|
||||
-> 81 07 c9 a5 01 02 85 01 1c // 1c ?bytes? frei
|
||||
|
||||
// FHZ1000PC
|
||||
<- 81 0a c9 __ 02 01 61 jj mm tt ss mm // Uhrzeit 50 mal am Anfang einer Minute
|
||||
|
||||
<- 81 05 04 4f c9 01 85 // Speicherabfrage
|
||||
-> 81 07 c9 __ 01 02 85 01 xx // xx = ?bytes? frei
|
||||
|
||||
// FHT80b
|
||||
// SB=StartByte LL=Laenge TT=TelegrammType BC=BlockCheck ST=Status
|
||||
// HH=Hauscode
|
||||
// SB LL TT BC CODE FUNKT ST Param
|
||||
-> 81 0c 04 __ 09 09 a0 01 HH HH 00 00 _6 xx // Istwert Stellantrieb
|
||||
-> 81 0c 04 __ 09 09 a0 01 HH HH 00 00 2c xx // Synczeit
|
||||
-> 81 0c 04 __ 09 09 a0 01 HH HH 14 00 69 xx // Montag von1 in 1/6 Stunde (10 Min.)
|
||||
-> 81 0c 04 __ 09 09 a0 01 HH HH 15 00 69 xx // Montag bis1
|
||||
-> 81 0c 04 __ 09 09 a0 01 HH HH 16 00 69 xx // Montag von2 (90 = frei)
|
||||
-> 81 0c 04 __ 09 09 a0 01 HH HH 17 00 69 xx // Montag bis2
|
||||
-> 81 0c 04 __ 09 09 a0 01 HH HH 18 00 69 xx // Dienstag von1
|
||||
-> 81 0c 04 __ 09 09 a0 01 HH HH 19 00 69 xx // bis 1
|
||||
-> 81 0c 04 __ 09 09 a0 01 HH HH 1a 00 69 xx // von2
|
||||
-> 81 0c 04 __ 09 09 a0 01 HH HH 1b 00 69 xx // bis2
|
||||
-> 81 0c 04 __ 09 09 a0 01 HH HH 1c 00 69 xx //Mittwoch von1
|
||||
-> 81 0c 04 __ 09 09 a0 01 HH HH 1d 00 69 xx
|
||||
-> 81 0c 04 __ 09 09 a0 01 HH HH 1e 00 69 xx
|
||||
-> 81 0c 04 __ 09 09 a0 01 HH HH 1f 00 69 xx
|
||||
-> 81 0c 04 __ 09 09 a0 01 HH HH 20 00 69 xx // Donnerstag
|
||||
-> 81 0c 04 __ 09 09 a0 01 HH HH 21 00 69 xx
|
||||
-> 81 0c 04 __ 09 09 a0 01 HH HH 22 00 69 xx
|
||||
-> 81 0c 04 __ 09 09 a0 01 HH HH 23 00 69 xx
|
||||
-> 81 0c 04 __ 09 09 a0 01 HH HH 24 00 69 xx // Freitag
|
||||
-> 81 0c 04 __ 09 09 a0 01 HH HH 25 00 69 xx
|
||||
-> 81 0c 04 __ 09 09 a0 01 HH HH 26 00 69 xx
|
||||
-> 81 0c 04 __ 09 09 a0 01 HH HH 27 00 69 xx
|
||||
-> 81 0c 04 __ 09 09 a0 01 HH HH 28 00 69 xx // Samstag
|
||||
-> 81 0c 04 __ 09 09 a0 01 HH HH 29 00 69 xx
|
||||
-> 81 0c 04 __ 09 09 a0 01 HH HH 2a 00 69 xx
|
||||
-> 81 0c 04 __ 09 09 a0 01 HH HH 2b 00 69 xx
|
||||
-> 81 0c 04 __ 09 09 a0 01 HH HH 2c 00 69 xx // Sonntag
|
||||
-> 81 0c 04 __ 09 09 a0 01 HH HH 2d 00 69 xx
|
||||
-> 81 0c 04 __ 09 09 a0 01 HH HH 2e 00 69 xx
|
||||
-> 81 0c 04 __ 09 09 a0 01 HH HH 2f 00 69 xx
|
||||
-> 81 0c 04 __ 09 09 a0 01 HH HH 3e 00 69 xx // 0=auto 1=manuell 2=Urlaub
|
||||
-> 81 0c 04 __ 09 09 a0 01 HH HH 3f 00 69 xx // Urlaub Endeuhrzeit oder Endetag
|
||||
-> 81 0c 04 __ 09 09 a0 01 HH HH 40 00 69 xx // Urlaub Endetag 10=heute 11=morgen 0x=Endemonat
|
||||
-> 81 0c 04 __ 09 09 a0 01 HH HH 41 00 69 xx // aktuelle Solltemperatur (x*0.5)
|
||||
-> 81 0c 04 __ 09 09 a0 01 HH HH 42 00 69 xx // ist Temperatur (x/10)
|
||||
-> 81 0c 04 __ 09 09 a0 01 HH HH 43 00 69 xx // ?????
|
||||
-> 81 0c 04 __ 09 09 a0 01 HH HH 44 00 69 xx // bit0=Batterie 0=OK 1=leer bit5=Fenster 0=zu 1=offen
|
||||
-> 81 0c 04 __ 09 09 a0 01 HH HH 4b 00 67 xx // ?????
|
||||
-> 81 0c 04 __ 09 09 a0 01 HH HH 82 00 69 xx // Tag Temperatur (x*0.5)
|
||||
-> 81 0c 04 __ 09 09 a0 01 HH HH 84 00 69 xx // Nacht Temperatur (x*0.5)
|
||||
-> 81 0c 04 __ 09 09 a0 01 HH HH 85 00 69 04 // ?????
|
||||
-> 81 0c 04 __ 09 09 a0 01 HH HH 8a 00 69 xx // Fenster offen Temperatur (x*0.5)
|
||||
-> 81 0c 04 __ 09 09 a0 01 HH HH 7e 00 67 xx // ?????
|
||||
|
||||
<- 81 09 04 __ 02 01 83 HH HH 3e xx // Modus setzen 00=auto 01=manu 02=Urlaub
|
||||
-> 81 0b 04 __ 84 09 83 01 HH HH 3e xx yy // Übernahmequittung yy=Speicherstelle
|
||||
<- 81 09 04 __ 02 01 83 HH HH 41 xx // Solltemp setzen (x=soll/0.5)
|
||||
Die anderen Register können genauso verändert werden.
|
||||
|
||||
//HMS100TF
|
||||
-> 81 0e 04 __ 05 10 a0 01 HH HH 00 00 ss tt gu ff // Temp = (utt*0.04) Feuchte = (ffg*100/4096)
|
||||
|
||||
// Status bit7=Negative Temp. bit6=Batterie
|
||||
|
||||
//ST-2
|
||||
<- 81 09 04 __ 02 01 01 a0 01 HH HH xx yy // xx=Taste yy=Funktion
|
||||
//Funktionen
|
||||
00 Aus
|
||||
01-10 Dimmen direkt
|
||||
11 Ein
|
||||
12 Dimmen Eintastenmodus
|
||||
13 Dimmen runter
|
||||
14 Dimmen rauf
|
||||
15 Umschalten
|
||||
16 Timerprogrammierung start/stop
|
||||
1b Auslieferungszustand
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue