use Protocol.pm and read more params
authorDobrica Pavlinusic <dpavlin@rot13.org>
Mon, 21 Sep 2020 11:22:01 +0000 (13:22 +0200)
committerDobrica Pavlinusic <dpavlin@rot13.org>
Mon, 21 Sep 2020 11:22:01 +0000 (13:22 +0200)
zc-mqtt

diff --git a/zc-mqtt b/zc-mqtt
index f954956..8cea33c 100755 (executable)
--- a/zc-mqtt
+++ b/zc-mqtt
@@ -16,6 +16,9 @@ use Getopt::Long;
 use Pod::Usage;
 use POSIX qw(strftime);
 
+use lib '.';
+use Protocol;
+
 $|=1; # flush STDOUT
 
 my $help;
@@ -76,7 +79,8 @@ while (1) {
 
 #      if ( $msg->topic =~ m{Inclinometer/ZCT330Ex_SWP_N_YK/869858031634109/up} ) {
       if ( substr($msg->message,2,1) eq "\x07" ) { # heartbeat
-       my $raw = "\x5a\x0b\x03\x09\x00\x00\x04\xe8\x03\x00\x00\x21\x44\xaa\x4B\xF3";
+       #my $raw = "\x5a\x0b\x03\x09\x00\x00\x04\xe8\x03\x00\x00\x21\x44\xaa\x4B\xF3";
+       my $raw = read_parameter_frame( "\x00" => "\x04\xe8\x03\x00\x00", "\x21", "\x44", "\x12", "\x14", "\x1a\x21\x22\x23\x24\x33\x34\x35\x3b" );
        my $topic = $msg->topic;
        $topic =~ s/up$/down/;
        send_message($socket,
@@ -236,34 +240,3 @@ the same terms as the Perl 5 programming language system itself.
 
 =cut
 
-# 6. Protocol Format 
-# Valid data ID and parameter range supported by the product 
-# DATA ID      ID Description  Data Type( Data Length)       R/W     Range   Default         Remark 
-
-__DATA__
-0x00   Seq #                   DWord(4)        R       /               0       The platform can carry the ID when the platform downstream reads and sets the device parameters, and the device returns the same data. Please refer to the example for use.Each seq # refer to one command and its response. 
-0x01   PN                      DWord(4)        R       /                /      / 
-0x02   Model                   Byte(1)         R       32              32      Inner number:32 
-0x03   X axis angle            Float(4)        R        ‐90°~90°   /       X axis angle 
-0x04   Y axis angle            Float(4)        R       ‐90°~90°    /       Y axis angle 
-0x09   X axis relative angle   Float(4)        R       ‐90°~90°    0       Return the X angle value according to the set relative zero 
-0x0A   Y axis relative angle   Float(4)        R       ‐90°~90°    0       Return the Y angle value according to the set relative zero 
-0x0C   Sensor temperature      Word(2)         R       ‐32768~32767  /       signed,sensor temperature =Data/100, unit ℃ 
-0x0D   Power source voltage    Word(2)         R       0~65535         /       Voltage= Data/100, unit V 
-0x11    Arming/disarming       Byte(1)         R/W     0~255           1       0 means disarming, non‐zero means arming 
-0x12   Alarm delay time        Byte(1)         R/W     3~255           20       The unit is 0.1 second, which means that the product responds to the alarm only after the alarm has exceeded the alarm angle for a certain period of time. 
-
-0x13   Restore factory setting Byte(1)         R/W     0~255           0       0: Do nothing Non‐zero: Restore the non‐network‐related parameters of the sensor. 
-0x14   Server IP&port          4*Byte(1)+Word(2)       R/W     /       CTIOT:117.60.157.137,5683 MQTT:0.0.0.0,0        The server address should be IP, not the domain name; using the domain name may cause the connection server to be unstable and cause data loss.
-0x17   Signal strength         Byte(1)         R       10~34           /       A larger value indicates a stronger signal 
-0x18   Sensor operating mode   Byte(1)         R/W     0               0       The sensor can only work in absolute measurement mode 
-0x19    Alarm axis             Byte(1)         R       0~      3       /       0: no alarm; 1: X‐axis alarm 2: Y axis alarm; 3: X/Y axis alarm at the same time 
-0x1A   SIM card ID             QWord(8)        R       0~18446744073709551615  /       Take the first 19 digits, the last digit is discarded 
-0x21    Heartbeat interval     DWord(4)        R/W     60~131071        86400  Interval at which the device periodically uploads data to the server 
-0x22   IMEI number of the device       QWord(8)         R      0~18446744073709551615  /       Refers to the IMEI of the NB‐IOT network module in the product. 
-0x23   Backup server IP&port   4*Byte(1)+Word(2)       R/W     /       CTIOT:117.60.157.137,5683 MQTT:0.0.0.0,0        / 
-0x24   Backup server enable    Byte(1)         R/W     0~255   0       0 means off, non‐zero means on 
-0x33   DNS IP address          4*Byte(1)       R/W     /       208.67.222.222  / 
-0x34   Domain name and port    64*Byte(1)      R/W     /       mqtt.zc‐sensor.com,1883       Supports CTIOT and MQTT protocols. Priority IP in the case of IP (ID number 0x14); domain name and port should be separated with comma, length <=64 
-0x35    MQTT‐ClientID                32*Byte(1)      R/W      /      IMEI number of the device       Length <=32, subject to MQTT related specifications 
-0x36   MQTT‐Username                 32*Byte(1)      R/W     /       empty           Length <=32, subject to MQTT related specifications