Sensorwerte in FHEM importieren

Begonnen von Persuasiv, 26 Juli 2017, 19:47:56

Vorheriges Thema - Nächstes Thema

Persuasiv

Hallo,

ich habe mir auf Basis des 32u4 einen eigenen Sensor und eine eigenes Gateway gebaut. Die Messwerte werden derzeit als String an das Gateway geschickt. Ich arbeite mit der Arduino IDE. Die Formatierung sieht derzeit so aus (.csv Formatierung):

SensorID, Batteriespannung*1024, Temperatur*128, Luftdruck*128, Luftfeuchtigkeit*128

Jetzt ist mir noch unklar, ob bzw. wie ich die Werte in FHEM importieren kann. Hat jemand eine Idee? Die Werte müssen auch noch umgerechnet und einem Sensor zugeordnet werden.

Besten Dank!



Dr. Boris Neubert

Hi, schau Dir bitte mal das Modul ECMD an. Viele Grüße Boris
Globaler Moderator, Developer, aktives Mitglied des FHEM e.V. (Marketing, Verwaltung)
Bitte keine unaufgeforderten privaten Nachrichten!

justme1968

hue, tradfri, alexa-fhem, homebridge-fhem, LightScene, readingsGroup, ...

https://github.com/sponsors/justme-1968

Persuasiv

Das KeyValueProtokoll scheint geeignet zu sein. Nur verstehe ich immer noch nicht wie ich das Gateway mit FHEM koppeln kann. Die Formatierung:

ZitatKV <Type> <Address> <Key>=<Value>,<Key>=<Value>,<Key>=<Value>, ...

kann ich problemlos liefern. Wie kann ich vom 32u4 eine Nachricht an FHEM schicken? Beim 32u4 kommt die Nachricht ja bereits an.

justme1968

wenn das ding per usb angeschlossen ist: nimm ein JeeLink device als io.

am anfang des strings muss OK VALUES <Type> <Address> kommen.
hue, tradfri, alexa-fhem, homebridge-fhem, LightScene, readingsGroup, ...

https://github.com/sponsors/justme-1968

Persuasiv

Ich habe jetzt versucht ein JeeLink device zu definieren. Der Empfänger hängt bei mir an COM4. Das Entspricht laut Gerätemanager scheinbar USB Port 2 ...

Zitatdefine Empfaenger JeeLink /dev/ttyUSB2@57600

Jetzt kommt die Fehlermeldung:

ZitatCan't locate Win32/SerialPort.pm in @INC (you may need to install the Win32::SerialPort module) (@INC contains: . c:/my-fhem/perl/site/lib c:/my-fhem/perl/vendor/lib c:/my-fhem/perl/lib ./FHEM) at ./FHEM/DevIo.pm line 386.

Der Versuch Abhilfe zu schaffen schlug fehl:

Zitatupdate Win32::SerialPort

Ergibt:

Zitatnothing to do...

Ich habe versucht mich an dem hier zu orientieren: https://wiki.fhem.de/wiki/JeeLink


justme1968

das SerialPort modul musst du auf perl ebene installieren. je nach dem welches perl du hast per cpan oder ppm oder ...

zu windows kann ich dir nicht weiter helfen aber z.b. hier steht etwas darüber: https://wiki.fhem.de/wiki/Windows_-_FHEM_installieren#Perl_installieren

gruss
  andre
hue, tradfri, alexa-fhem, homebridge-fhem, LightScene, readingsGroup, ...

https://github.com/sponsors/justme-1968

Wernieman

Wenn Du Dir ein gateway programmiert hast, könntest Du alternativ per "telnet" auch die Daten direkt in FHEM reinpusten ...
- Bitte um Input für Output
- When there is a Shell, there is a Way
- Wann war Dein letztes Backup?

Wie man Fragen stellt: https://tty1.net/smart-questions_de.html

justme1968

#8
telnet ist keine gute lösung da pro reading ein eigenes kommando abgesetzt werden muss. das ist schon deutlich mehr overhead. es geht auch kein autocreate und die device namen müssen festgelegt werden.

hier hängt das gateway ja auch per usb am fhem system. da passt das JeeLink modul schon. falls das gateway direkt am netzwerk hängt kann man ebenfalls das JeeLink modul verwenden oder wenn das gateway per udp sendet das KVPUDP modul.

telnet/nc/fhem ist eigentlich nur dann eine sinnvolle lösung wenn die daten aus irgend einem binary oder shellscipt kommen.
hue, tradfri, alexa-fhem, homebridge-fhem, LightScene, readingsGroup, ...

https://github.com/sponsors/justme-1968

Persuasiv

#9
Ich bekomme das leider nicht installiert. Perl ist kein Problem. Ab hier funktioniert die Anleitung nicht mehr:

Zitatppm install Win32-SerialPort

Liefert:
Zitat
Microsoft Windows [Version 6.1.7601]
Copyright (c) 2009 Microsoft Corporation. Alle Rechte vorbehalten.

C:\Users\xxx>ppm install Win32-SerialPort
ppm install failed: Can't find any package that provides Win32-SerialPort

Ein weiterer Versuch mit

Zitatcpan Win32::SerialPort

schlägt auch fehl:

Microsoft Windows [Version 6.1.7601]
Copyright (c) 2009 Microsoft Corporation. Alle Rechte vorbehalten.

C:\Users\xxx>cpan Win32::SerialPort
Loading internal null logger. Install Log::Log4perl for logging messages
CPAN: Term::ANSIColor loaded ok (v4.06)
CPAN: Storable loaded ok (v2.56_01)
Reading 'C:\Perl64\cpan\Metadata'
  Database was generated on Thu, 27 Jul 2017 04:29:02 GMT
Running install for module 'Win32::SerialPort'
CPAN: Digest::SHA loaded ok (v5.96)
CPAN: Compress::Zlib loaded ok (v2.07)
Checksum for C:\Perl64\cpan\sources\authors\id\B\BB\BBIRTH\Win32-SerialPort-0.22
.tar.gz ok
CPAN: Archive::Tar loaded ok (v2.24)
Win32-SerialPort-0.22/
Win32-SerialPort-0.22/html/
Win32-SerialPort-0.22/html/Win32/
Win32-SerialPort-0.22/html/Win32/SerialPort.html
Win32-SerialPort-0.22/html/Win32API/
Win32-SerialPort-0.22/html/Win32API/CommPort.html
Win32-SerialPort-0.22/lib/
Win32-SerialPort-0.22/lib/Win32/
Win32-SerialPort-0.22/lib/Win32/SerialPort.pm
Win32-SerialPort-0.22/lib/Win32API/
Win32-SerialPort-0.22/lib/Win32API/CommPort.pm
Win32-SerialPort-0.22/Changes
Win32-SerialPort-0.22/README
Win32-SerialPort-0.22/MANIFEST
Win32-SerialPort-0.22/META.yml
Win32-SerialPort-0.22/README.txt
Win32-SerialPort-0.22/Makefile.PL
Win32-SerialPort-0.22/t/
Win32-SerialPort-0.22/t/test6.t
Win32-SerialPort-0.22/t/test4.t
Win32-SerialPort-0.22/t/test2.t
Win32-SerialPort-0.22/t/test7.t
Win32-SerialPort-0.22/t/test1.t
Win32-SerialPort-0.22/t/test3.t
Win32-SerialPort-0.22/t/test5.t
Win32-SerialPort-0.22/t/AltPort.pm
Win32-SerialPort-0.22/eg/
Win32-SerialPort-0.22/eg/demo6.plx
Win32-SerialPort-0.22/eg/elec_meter.pl
Win32-SerialPort-0.22/eg/demo1.plx
Win32-SerialPort-0.22/eg/demo4.plx
Win32-SerialPort-0.22/eg/demo3.plx
Win32-SerialPort-0.22/eg/demo9.plx
Win32-SerialPort-0.22/eg/demo8.plx
Win32-SerialPort-0.22/eg/options.plx
Win32-SerialPort-0.22/eg/demo2.plx
Win32-SerialPort-0.22/eg/demo7.plx
Win32-SerialPort-0.22/eg/stty.plx
Win32-SerialPort-0.22/eg/any_os.plx
Win32-SerialPort-0.22/eg/demo5.plx
CPAN: File::Temp loaded ok (v0.2304)
CPAN: YAML::XS loaded ok (v0.63)
CPAN: CPAN::Meta::Requirements loaded ok (v2.140)
CPAN: Parse::CPAN::Meta loaded ok (v2.150010)
CPAN: CPAN::Meta loaded ok (v2.150010)
CPAN: Module::CoreList loaded ok (v5.20170114_24)
Configuring B/BB/BBIRTH/Win32-SerialPort-0.22.tar.gz with Makefile.PL
found result=0, file=COM1
            Win32::SerialPort and Win32API::CommPort
                        VERSION 0.22

A 'Makefile' created for those with 'make' or CPAN.pm users.
It will test using PORT = COM1. To test using a different PORT,
run again specifying: 'perl Makefile.PL TESTPORT=<PORT>'
The normal 'Mantra' would then apply:
        make
        make test
        make install

For those without 'make' or an equivalent like 'nmake' or 'dmake' there
are perl-only scripts which do the same things:
        Test with:    perl nomake_test
        Install with: perl nomake_install

Test with nothing connected to COM1.
PORT is not verified present and accessible until tests run.
Timeout tests can take up to 30 seconds per test.

Creating new t/DefaultPort.pm
Creating new nomake_test
Creating new nomake_install
Checking if your kit is complete...
Looks good
Generating a dmake-style Makefile
Writing Makefile for Win32::SerialPort
Writing MYMETA.yml and MYMETA.json
  BBIRTH/Win32-SerialPort-0.22.tar.gz
  C:\Perl64\bin\perl.exe Makefile.PL INSTALLDIRS=site -- OK
Running make for B/BB/BBIRTH/Win32-SerialPort-0.22.tar.gz
cp lib/Win32API/CommPort.pm blib\lib\Win32API\CommPort.pm
cp lib/Win32/SerialPort.pm blib\lib\Win32\SerialPort.pm
  BBIRTH/Win32-SerialPort-0.22.tar.gz
  C:\Perl64\site\bin\dmake.exe -- OK
Running make test
"C:\Perl64\bin\perl.exe" "-MExtUtils::Command::MM" "-MTest::Harness" "-e" "undef
*Test::Harness::Switches; test_harness(0, 'blib\lib', 'blib\arch')" t/*.t
t/test1.t .. 1/309
#   Failed test 'write 180 characters'
#   at t/test1.t line 411.
#          got: undef
#     expected: '180'
t/test1.t .. 303/309 # Looks like you failed 1 test of 309.
t/test1.t .. Dubious, test returned 1 (wstat 256, 0x100)
Failed 1/309 subtests
        (less 61 skipped subtests: 247 okay)
t/test2.t .. 1/146
#   Failed test 'write 180 characters'
#   at t/test2.t line 110.
#          got: undef
#     expected: '180'
t/test2.t .. 145/146 # Looks like you failed 1 test of 146.
t/test2.t .. Dubious, test returned 1 (wstat 256, 0x100)
Failed 1/146 subtests
        (less 99 skipped subtests: 46 okay)
t/test3.t .. 1/?
#   Failed test 'write 180 characters'
#   at t/test3.t line 393.
#          got: undef
#     expected: '180'
t/test3.t .. 200/? # Looks like you failed 1 test of 264.
t/test3.t .. Dubious, test returned 1 (wstat 256, 0x100)
Failed 1/264 subtests
        (less 54 skipped subtests: 209 okay)
t/test4.t .. 1/?
#   Failed test 'write 180 characters'
#   at t/test4.t line 600.
#          got: undef
#     expected: '180'
# Looks like you failed 1 test of 518.
t/test4.t .. Dubious, test returned 1 (wstat 256, 0x100)
Failed 1/518 subtests
        (less 90 skipped subtests: 427 okay)
t/test5.t .. ok
t/test6.t .. 1/? SetCommState failed at t/test6.t line 306.
t/test6.t .. ok
t/test7.t .. 1/90
#   Failed test 'confirm no error'
#   at t/test7.t line 96.
#          got: '1121'
#     expected: '0'

#   Failed test 'PRINT method'
#   at t/test7.t line 99.
#          got: undef
#     expected: '1'
# Looks like you failed 2 tests of 90.
t/test7.t .. Dubious, test returned 2 (wstat 512, 0x200)
Failed 2/90 subtests
        (less 55 skipped subtests: 33 okay)

Test Summary Report
-------------------
t/test1.t (Wstat: 256 Tests: 309 Failed: 1)
  Failed test:  157
  Non-zero exit status: 1
t/test2.t (Wstat: 256 Tests: 146 Failed: 1)
  Failed test:  27
  Non-zero exit status: 1
t/test3.t (Wstat: 256 Tests: 264 Failed: 1)
  Failed test:  149
  Non-zero exit status: 1
t/test4.t (Wstat: 256 Tests: 518 Failed: 1)
  Failed test:  366
  Non-zero exit status: 1
t/test7.t (Wstat: 512 Tests: 90 Failed: 2)
  Failed tests:  21-22
  Non-zero exit status: 2
Files=7, Tests=1808,  5 wallclock secs ( 0.11 usr +  0.00 sys =  0.11 CPU)
Result: FAIL
Failed 5/7 test programs. 6/1808 subtests failed.
dmake.exe:  Error code 130, while making 'test_dynamic'
  BBIRTH/Win32-SerialPort-0.22.tar.gz
  C:\Perl64\site\bin\dmake.exe test -- NOT OK
//hint// to see the cpan-testers results for installing this module, try:
  reports BBIRTH/Win32-SerialPort-0.22.tar.gz


Strawberry Perl funktioniert auch nicht:

Zitatperl -MCPAN -e "install Win32::SerialPort"

Microsoft Windows [Version 6.1.7601]
Copyright (c) 2009 Microsoft Corporation. Alle Rechte vorbehalten.

C:\Users\xxx>perl -MCPAN -e "install Win32::SerialPort"
Reading 'C:\Perl64\cpan\Metadata'
  Database was generated on Thu, 27 Jul 2017 04:29:02 GMT
Running install for module 'Win32::SerialPort'
Checksum for C:\Perl64\cpan\sources\authors\id\B\BB\BBIRTH\Win32-SerialPort-0.22
.tar.gz ok
Win32-SerialPort-0.22/
Win32-SerialPort-0.22/html/
Win32-SerialPort-0.22/html/Win32/
Win32-SerialPort-0.22/html/Win32/SerialPort.html
Win32-SerialPort-0.22/html/Win32API/
Win32-SerialPort-0.22/html/Win32API/CommPort.html
Win32-SerialPort-0.22/lib/
Win32-SerialPort-0.22/lib/Win32/
Win32-SerialPort-0.22/lib/Win32/SerialPort.pm
Win32-SerialPort-0.22/lib/Win32API/
Win32-SerialPort-0.22/lib/Win32API/CommPort.pm
Win32-SerialPort-0.22/Changes
Win32-SerialPort-0.22/README
Win32-SerialPort-0.22/MANIFEST
Win32-SerialPort-0.22/META.yml
Win32-SerialPort-0.22/README.txt
Win32-SerialPort-0.22/Makefile.PL
Win32-SerialPort-0.22/t/
Win32-SerialPort-0.22/t/test6.t
Win32-SerialPort-0.22/t/test4.t
Win32-SerialPort-0.22/t/test2.t
Win32-SerialPort-0.22/t/test7.t
Win32-SerialPort-0.22/t/test1.t
Win32-SerialPort-0.22/t/test3.t
Win32-SerialPort-0.22/t/test5.t
Win32-SerialPort-0.22/t/AltPort.pm
Win32-SerialPort-0.22/eg/
Win32-SerialPort-0.22/eg/demo6.plx
Win32-SerialPort-0.22/eg/elec_meter.pl
Win32-SerialPort-0.22/eg/demo1.plx
Win32-SerialPort-0.22/eg/demo4.plx
Win32-SerialPort-0.22/eg/demo3.plx
Win32-SerialPort-0.22/eg/demo9.plx
Win32-SerialPort-0.22/eg/demo8.plx
Win32-SerialPort-0.22/eg/options.plx
Win32-SerialPort-0.22/eg/demo2.plx
Win32-SerialPort-0.22/eg/demo7.plx
Win32-SerialPort-0.22/eg/stty.plx
Win32-SerialPort-0.22/eg/any_os.plx
Win32-SerialPort-0.22/eg/demo5.plx
Configuring B/BB/BBIRTH/Win32-SerialPort-0.22.tar.gz with Makefile.PL
found result=0, file=COM1
            Win32::SerialPort and Win32API::CommPort
                        VERSION 0.22

A 'Makefile' created for those with 'make' or CPAN.pm users.
It will test using PORT = COM1. To test using a different PORT,
run again specifying: 'perl Makefile.PL TESTPORT=<PORT>'
The normal 'Mantra' would then apply:
        make
        make test
        make install

For those without 'make' or an equivalent like 'nmake' or 'dmake' there
are perl-only scripts which do the same things:
        Test with:    perl nomake_test
        Install with: perl nomake_install

Test with nothing connected to COM1.
PORT is not verified present and accessible until tests run.
Timeout tests can take up to 30 seconds per test.

Creating new t/DefaultPort.pm
Creating new nomake_test
Creating new nomake_install
Checking if your kit is complete...
Looks good
Generating a dmake-style Makefile
Writing Makefile for Win32::SerialPort
Writing MYMETA.yml and MYMETA.json
  BBIRTH/Win32-SerialPort-0.22.tar.gz
  C:\Perl64\bin\perl.exe Makefile.PL INSTALLDIRS=site -- OK
Running make for B/BB/BBIRTH/Win32-SerialPort-0.22.tar.gz
cp lib/Win32API/CommPort.pm blib\lib\Win32API\CommPort.pm
cp lib/Win32/SerialPort.pm blib\lib\Win32\SerialPort.pm
  BBIRTH/Win32-SerialPort-0.22.tar.gz
  C:\Perl64\site\bin\dmake.exe -- OK
Running make test
"C:\Perl64\bin\perl.exe" "-MExtUtils::Command::MM" "-MTest::Harness" "-e" "undef
*Test::Harness::Switches; test_harness(0, 'blib\lib', 'blib\arch')" t/*.t
t/test1.t .. 1/309
#   Failed test 'write 180 characters'
#   at t/test1.t line 411.
#          got: undef
#     expected: '180'
t/test1.t .. 297/309 # Looks like you failed 1 test of 309.
t/test1.t .. Dubious, test returned 1 (wstat 256, 0x100)
Failed 1/309 subtests
        (less 61 skipped subtests: 247 okay)
t/test2.t .. 1/146
#   Failed test 'write 180 characters'
#   at t/test2.t line 110.
#          got: undef
#     expected: '180'
t/test2.t .. 145/146 # Looks like you failed 1 test of 146.
t/test2.t .. Dubious, test returned 1 (wstat 256, 0x100)
Failed 1/146 subtests
        (less 99 skipped subtests: 46 okay)
t/test3.t .. 1/?
#   Failed test 'write 180 characters'
#   at t/test3.t line 393.
#          got: undef
#     expected: '180'
t/test3.t .. 262/? # Looks like you failed 1 test of 264.
t/test3.t .. Dubious, test returned 1 (wstat 256, 0x100)
Failed 1/264 subtests
        (less 54 skipped subtests: 209 okay)
t/test4.t .. 1/?
#   Failed test 'write 180 characters'
#   at t/test4.t line 600.
#          got: undef
#     expected: '180'
# Looks like you failed 1 test of 518.
t/test4.t .. Dubious, test returned 1 (wstat 256, 0x100)
Failed 1/518 subtests
        (less 90 skipped subtests: 427 okay)
t/test5.t .. ok
t/test6.t .. 1/? SetCommState failed at t/test6.t line 306.
t/test6.t .. ok
t/test7.t .. 1/90
#   Failed test 'confirm no error'
#   at t/test7.t line 96.
#          got: '1121'
#     expected: '0'

#   Failed test 'PRINT method'
#   at t/test7.t line 99.
#          got: undef
#     expected: '1'
# Looks like you failed 2 tests of 90.
t/test7.t .. Dubious, test returned 2 (wstat 512, 0x200)
Failed 2/90 subtests
        (less 55 skipped subtests: 33 okay)

Test Summary Report
-------------------
t/test1.t (Wstat: 256 Tests: 309 Failed: 1)
  Failed test:  157
  Non-zero exit status: 1
t/test2.t (Wstat: 256 Tests: 146 Failed: 1)
  Failed test:  27
  Non-zero exit status: 1
t/test3.t (Wstat: 256 Tests: 264 Failed: 1)
  Failed test:  149
  Non-zero exit status: 1
t/test4.t (Wstat: 256 Tests: 518 Failed: 1)
  Failed test:  366
  Non-zero exit status: 1
t/test7.t (Wstat: 512 Tests: 90 Failed: 2)
  Failed tests:  21-22
  Non-zero exit status: 2
Files=7, Tests=1808,  4 wallclock secs ( 0.02 usr +  0.05 sys =  0.06 CPU)
Result: FAIL
Failed 5/7 test programs. 6/1808 subtests failed.
dmake.exe:  Error code 130, while making 'test_dynamic'
  BBIRTH/Win32-SerialPort-0.22.tar.gz
  C:\Perl64\site\bin\dmake.exe test -- NOT OK
//hint// to see the cpan-testers results for installing this module, try:
  reports BBIRTH/Win32-SerialPort-0.22.tar.gz


Folglich kann auch FHEM das Win32::SerialPort module nicht finden. Die Anleitung bezieht sich vermutlich auf eine alte Version.

EDIT: Scheint ein Bug der 64 Bit Version zu sein. Ich werde es mit der 32 Bit Version versuchen ...

EDIT: Bei der 32 Bit Version bin ich eigentlich der Meinung, dass ich alles befolgt habe. Die Installation des Moduls klappt scheinbar ... Die Fehlermeldung ist aber die gleiche:

Can't locate Win32/SerialPort.pm in @INC (you may need to install the Win32::SerialPort module) (@INC contains: . c:/my-fhem/perl/site/lib c:/my-fhem/perl/vendor/lib c:/my-fhem/perl/lib ./FHEM) at ./FHEM/DevIo.pm line 386.

Persuasiv

Ich habe es jetzt mit Ubuntu probiert. Dort funktioniert mein Befehl:

Zitatdefine Empfaenger JeeLink /dev/ttyUSB2@57600

@Win7 habe ich das Win32-SerialPort-Modul nicht installiert bekommen.

Persuasiv

Ich habe es jetzt geschafft den Empfänger anzuschließen. Darüber hinaus habe ich den JeeLink angelegt. Wie gehe ich jetzt weiter vor (mit Ausnahme der Formatierung des Strings)?

habeIchVergessen

die Nachrichten müssen wie folgt aussehen

OK VALUES <TYPE> <ID> Temperatur=10.2,Feuchtigkeit=67.25

Type ist ein frei wählbarer Name. ID identifiziert einen Sensor von Type xy.

Autocreate sollte ein Device KeyValueProtocol_[Type]_[ID] anlegen.

Das Mapping erlaubt das Setzen einer Kurzbezeichnung für den Namen der Readings
z.B. Tempaeratur=1

OK VALUES <TYPE> <ID> 1=10.2,2=67.25

Persuasiv

Besten Dank! Es hat funktioniert ... Jetzt muss ich die Messwerte nur noch graphisch darstellen.