5d
(→HTTP POST 格式) |
(→Data Recorder Spec) |
||
第400行: | 第400行: | ||
<br><br> | <br><br> | ||
− | == | + | == 采集器建议规范 == |
− | === | + | === 采集器硬件要求 === |
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
单次采集,数据量很大,硬件最好满足如下基本要求: | 单次采集,数据量很大,硬件最好满足如下基本要求: | ||
第473行: | 第410行: | ||
* 下行一路 RS485 最少支持 40 块表,支持多路 RS485 | * 下行一路 RS485 最少支持 40 块表,支持多路 RS485 | ||
+ | <br> | ||
− | + | === 采集器固件功能要求 === | |
* 上行到服务器,用以太网,IP 地址和端口可配置,支持 DHCP (可选) | * 上行到服务器,用以太网,IP 地址和端口可配置,支持 DHCP (可选) | ||
第480行: | 第418行: | ||
* 数据间隔可调,最小粒度2分钟,即:每 2 分钟抄一次所有表,随后 http 发往内网服务器 | * 数据间隔可调,最小粒度2分钟,即:每 2 分钟抄一次所有表,随后 http 发往内网服务器 | ||
* 集中器如果数据上行 http push失败,至少要能存储一天的历史数据,待内网服务器恢复后,自动将历史数据推送到服务器 (可选) | * 集中器如果数据上行 http push失败,至少要能存储一天的历史数据,待内网服务器恢复后,自动将历史数据推送到服务器 (可选) | ||
− | + | * 支持配置 building_id 和 gateway_id(可选) | |
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | * 支持配置 building_id 和 | + | |
第495行: | 第425行: | ||
<br> | <br> | ||
− | === | + | === 采集器上传数据格式 === |
− | + | * building_id 为建筑编号;gateway_id 为采集器编号 | |
− | + | * meter_id 为电表地址, way_id 为电表的路号,支持一路的电表 way_id 为 1。支持六路三相电监控的路号为 1 ~ 6 | |
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | * 电表数据要详细到三相电的每一相,就是上面 xml 格式内的phase A, B,C。每项的监测数据有电压 (U),电流 (I),功率 (P),功率因数 (PF),视在功率 (S)和无功功率 (Q) | |
− | + | * 三相总的(phase All)数据:功率因数 (PF),有功功率 (P),无功功率 (Q),视在功率 (S),正向有功总电能 (PEP),反向有功总电能 (NEP),正向无功总电能 (PEQ),反向无功总电能 (NEQ) | |
− | + | * 每一个时间间隔抄表,上行数据的 timestamp 必须统一 (xml: <time>20170908123000</time>) | |
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | |||
<source lang=xml> | <source lang=xml> | ||
第799行: | 第712行: | ||
</common> | </common> | ||
</root> | </root> | ||
+ | </source> | ||
+ | |||
+ | <br> | ||
+ | |||
+ | === HTTP POST 格式 === | ||
+ | |||
+ | <source lang=bash> | ||
+ | POST /dev/elec HTTP/1.1 | ||
+ | Host: 192.168.1.20 | ||
+ | User-Agent: curl/7.52.1 | ||
+ | Accept: */* | ||
+ | Content-Length: 3401 | ||
+ | Content-Type: application/x-www-form-urlencoded | ||
+ | Expect: 100-continue | ||
+ | |||
+ | <?xml version="1.0" encoding="utf-8" ?><root><common><building_id>110101B001</building_id><gateway_id>2</gateway_id><type>report</type><data operation="report"><sequence>0</sequence><parser>yes</parser><time>20170810093040</time><total>1</total><current>1</current><meter id="70"><function id="1" coding="01" error="0"><way id="1"><phase id="A"><U>226.12</U><I>7.00</I><S>0.00</S><P>0.70</P><Q>0.00</Q><PF>0.77</PF></phase><phase id="B"><U>226.12</U><I>7.00</I><S>0.00</S><P>0.70</P><Q>0.00</Q><PF>0.77</PF></phase><phase id="C"><U>226.12</U><I>7.00</I><S>0.00</S><P>0.70</P><Q>0.00</Q><PF>0.77</PF></phase><phase id="All"><S>0.00</S><P>0.00</P><Q>0.00</Q><PF>0.00</PF><PEP>5.00</PEP><NEP>6.00</NEP><PEQ>5.00</PEQ><NEQ>6.00</NEQ></phase></way></function></meter><meter id="1"><function id="1" coding="01" error="0"><way id="1"><phase id="A"><U>226.12</U><I>0.00</I><S>0.00</S><P>0.00</P><Q>0.00</Q><PF>0.10</PF></phase><phase id="B"><U>226.12</U><I>0.00</I><S>0.00</S><P>0.00</P><Q>0.00</Q><PF>0.10</PF></phase><phase id="C"><U>226.12</U><I>0.00</I><S>0.00</S><P>0.00</P><Q>0.00</Q><PF>0.10</PF></phase><phase id="All"><S>0.00</S><P>0.00</P><Q>0.00</Q><PF>0.00</PF><PEP>5.00</PEP><NEP>6.00</NEP><PEQ>5.00</PEQ><NEQ>6.00</NEQ></phase></way><way id="2"><phase id="A"><U>226.12</U><I>0.00</I><S>0.00</S><P>0.00</P><Q>0.00</Q><PF>0.20</PF></phase><phase id="B"><U>226.12</U><I>0.00</I><S>0.00</S><P>0.00</P><Q>0.00</Q><PF>0.20</PF></phase><phase id="C"><U>226.12</U><I>0.00</I><S>0.00</S><P>0.00</P><Q>0.00</Q><PF>0.20</PF></phase><phase id="All"><S>0.00</S><P>0.00</P><Q>0.00</Q><PF>0.00</PF><PEP>5.00</PEP><NEP>6.00</NEP><PEQ>5.00</PEQ><NEQ>6.00</NEQ></phase></way><way id="3"><phase id="A"><U>226.12</U><I>0.00</I><S>0.00</S><P>0.00</P><Q>0.00</Q><PF>0.30</PF></phase><phase id="B"><U>226.12</U><I>0.00</I><S>0.00</S><P>0.00</P><Q>0.00</Q><PF>0.30</PF></phase><phase id="C"><U>226.12</U><I>0.00</I><S>0.00</S><P>0.00</P><Q>0.00</Q><PF>0.30</PF></phase><phase id="All"><S>0.00</S><P>0.00</P><Q>0.00</Q><PF>0.00</PF><PEP>5.00</PEP><NEP>6.00</NEP><PEQ>5.00</PEQ><NEQ>6.00</NEQ></phase></way><way id="4"><phase id="A"><U>226.12</U><I>0.00</I><S>0.00</S><P>0.00</P><Q>0.00</Q><PF>0.40</PF></phase><phase id="B"><U>226.12</U><I>0.00</I><S>0.00</S><P>0.00</P><Q>0.00</Q><PF>0.40</PF></phase><phase id="C"><U>226.12</U><I>0.00</I><S>0.00</S><P>0.00</P><Q>0.00</Q><PF>0.40</PF></phase><phase id="All"><S>0.00</S><P>0.00</P><Q>0.00</Q><PF>0.00</PF><PEP>5.00</PEP><NEP>6.00</NEP><PEQ>5.00</PEQ><NEQ>6.00</NEQ></phase></way><way id="5"><phase id="A"><U>226.12</U><I>0.00</I><S>0.00</S><P>0.00</P><Q>0.00</Q><PF>0.50</PF></phase><phase id="B"><U>226.12</U><I>0.00</I><S>0.00</S><P>0.00</P><Q>0.00</Q><PF>0.50</PF></phase><phase id="C"><U>226.12</U><I>0.00</I><S>0.00</S><P>0.00</P><Q>0.00</Q><PF>0.50</PF></phase><phase id="All"><S>0.00</S><P>0.00</P><Q>0.00</Q><PF>0.00</PF><PEP>5.00</PEP><NEP>6.00</NEP><PEQ>5.00</PEQ><NEQ>6.00</NEQ></phase></way><way id="6"><phase id="A"><U>226.12</U><I>0.00</I><S>0.00</S><P>0.00</P><Q>0.00</Q><PF>0.60</PF></phase><phase id="B"><U>226.12</U><I>0.00</I><S>0.00</S><P>0.00</P><Q>0.00</Q><PF>0.60</PF></phase><phase id="C"><U>226.12</U><I>0.00</I><S>0.00</S><P>0.00</P><Q>0.00</Q><PF>0.60</PF></phase><phase id="All"><S>0.00</S><P>0.00</P><Q>0.00</Q><PF>0.00</PF><PEP>5.00</PEP><NEP>6.00</NEP><PEQ>5.00</PEQ><NEQ>6.00</NEQ></phase></way></function></meter></data></common></root> | ||
+ | </source> | ||
+ | |||
+ | or: | ||
+ | |||
+ | <source lang=bash> | ||
+ | $ cat d.xml | ||
+ | <?xml version="1.0" encoding="utf-8" ?><root><common><building_id>110101B001</building_id><gateway_id>2</gateway_id><type>report</type><data operation="report"><sequence>0</sequence><parser>yes</parser><time>20170810093040</time><total>1</total><current>1</current><meter id="70"><function id="1" coding="01" error="0"><way id="1"><phase id="A"><U>226.12</U><I>7.00</I><S>0.00</S><P>0.70</P><Q>0.00</Q><PF>0.77</PF></phase><phase id="B"><U>226.12</U><I>7.00</I><S>0.00</S><P>0.70</P><Q>0.00</Q><PF>0.77</PF></phase><phase id="C"><U>226.12</U><I>7.00</I><S>0.00</S><P>0.70</P><Q>0.00</Q><PF>0.77</PF></phase><phase id="All"><S>0.00</S><P>0.00</P><Q>0.00</Q><PF>0.00</PF><PEP>5.00</PEP><NEP>6.00</NEP><PEQ>5.00</PEQ><NEQ>6.00</NEQ></phase></way></function></meter><meter id="1"><function id="1" coding="01" error="0"><way id="1"><phase id="A"><U>226.12</U><I>0.00</I><S>0.00</S><P>0.00</P><Q>0.00</Q><PF>0.10</PF></phase><phase id="B"><U>226.12</U><I>0.00</I><S>0.00</S><P>0.00</P><Q>0.00</Q><PF>0.10</PF></phase><phase id="C"><U>226.12</U><I>0.00</I><S>0.00</S><P>0.00</P><Q>0.00</Q><PF>0.10</PF></phase><phase id="All"><S>0.00</S><P>0.00</P><Q>0.00</Q><PF>0.00</PF><PEP>5.00</PEP><NEP>6.00</NEP><PEQ>5.00</PEQ><NEQ>6.00</NEQ></phase></way><way id="2"><phase id="A"><U>226.12</U><I>0.00</I><S>0.00</S><P>0.00</P><Q>0.00</Q><PF>0.20</PF></phase><phase id="B"><U>226.12</U><I>0.00</I><S>0.00</S><P>0.00</P><Q>0.00</Q><PF>0.20</PF></phase><phase id="C"><U>226.12</U><I>0.00</I><S>0.00</S><P>0.00</P><Q>0.00</Q><PF>0.20</PF></phase><phase id="All"><S>0.00</S><P>0.00</P><Q>0.00</Q><PF>0.00</PF><PEP>5.00</PEP><NEP>6.00</NEP><PEQ>5.00</PEQ><NEQ>6.00</NEQ></phase></way><way id="3"><phase id="A"><U>226.12</U><I>0.00</I><S>0.00</S><P>0.00</P><Q>0.00</Q><PF>0.30</PF></phase><phase id="B"><U>226.12</U><I>0.00</I><S>0.00</S><P>0.00</P><Q>0.00</Q><PF>0.30</PF></phase><phase id="C"><U>226.12</U><I>0.00</I><S>0.00</S><P>0.00</P><Q>0.00</Q><PF>0.30</PF></phase><phase id="All"><S>0.00</S><P>0.00</P><Q>0.00</Q><PF>0.00</PF><PEP>5.00</PEP><NEP>6.00</NEP><PEQ>5.00</PEQ><NEQ>6.00</NEQ></phase></way><way id="4"><phase id="A"><U>226.12</U><I>0.00</I><S>0.00</S><P>0.00</P><Q>0.00</Q><PF>0.40</PF></phase><phase id="B"><U>226.12</U><I>0.00</I><S>0.00</S><P>0.00</P><Q>0.00</Q><PF>0.40</PF></phase><phase id="C"><U>226.12</U><I>0.00</I><S>0.00</S><P>0.00</P><Q>0.00</Q><PF>0.40</PF></phase><phase id="All"><S>0.00</S><P>0.00</P><Q>0.00</Q><PF>0.00</PF><PEP>5.00</PEP><NEP>6.00</NEP><PEQ>5.00</PEQ><NEQ>6.00</NEQ></phase></way><way id="5"><phase id="A"><U>226.12</U><I>0.00</I><S>0.00</S><P>0.00</P><Q>0.00</Q><PF>0.50</PF></phase><phase id="B"><U>226.12</U><I>0.00</I><S>0.00</S><P>0.00</P><Q>0.00</Q><PF>0.50</PF></phase><phase id="C"><U>226.12</U><I>0.00</I><S>0.00</S><P>0.00</P><Q>0.00</Q><PF>0.50</PF></phase><phase id="All"><S>0.00</S><P>0.00</P><Q>0.00</Q><PF>0.00</PF><PEP>5.00</PEP><NEP>6.00</NEP><PEQ>5.00</PEQ><NEQ>6.00</NEQ></phase></way><way id="6"><phase id="A"><U>226.12</U><I>0.00</I><S>0.00</S><P>0.00</P><Q>0.00</Q><PF>0.60</PF></phase><phase id="B"><U>226.12</U><I>0.00</I><S>0.00</S><P>0.00</P><Q>0.00</Q><PF>0.60</PF></phase><phase id="C"><U>226.12</U><I>0.00</I><S>0.00</S><P>0.00</P><Q>0.00</Q><PF>0.60</PF></phase><phase id="All"><S>0.00</S><P>0.00</P><Q>0.00</Q><PF>0.00</PF><PEP>5.00</PEP><NEP>6.00</NEP><PEQ>5.00</PEQ><NEQ>6.00</NEQ></phase></way></function></meter></data></common></root> | ||
+ | |||
+ | $ curl -X POST -d @d.xml http://192.168.1.20:8000/dev/elec | ||
</source> | </source> | ||
2018年5月11日 (五) 11:14的版本
目录 |
1 现场调试操作
- http://192.168.1.2:8000/device/yard
- http://192.168.1.2:8000/device/yard2
- http://192.168.1.2:8000/device/temp
- http://192.168.1.2:8000/device/temp2
- pull elect data: http://192.168.1.2:8000/dev/data?meter_id=1B&way_id=3
- push data: http://192.168.1.2:8000/dev/temp?building_id=110101B001&devid=MKD393830497658&temp=19.2
- pull data: http://192.168.1.2:8000/tempdata?devid=MKD118581004672
以下所有操作都在 USB 连接集中器后获取的串口终端里操作,参见《集中器本地调试指南》
[root@mcuzone root]# [root@mcuzone root]#[gprs.c][ModelIdentify][671] ps ax PID USER TIME COMMAND 1 root 0:00 init 2 root 0:00 [kthreadd] 3 root 0:00 [ksoftirqd/0] 4 root 0:00 [kworker/0:0] 5 root 0:00 [kworker/u:0] 6 root 0:00 [rcu_kthread] 7 root 0:00 [khelper] 8 root 0:00 [kworker/u:1] 136 root 0:00 [sync_supers] 138 root 0:00 [bdi-default] 140 root 0:00 [kblockd] 152 root 0:00 [khubd] 186 root 0:00 [cfg80211] 187 root 0:00 [kworker/0:1] 270 root 0:00 [rpciod] 277 root 0:00 [kswapd0] 278 root 0:00 [fsnotify_mark] 279 root 0:00 [nfsiod] 280 root 0:00 [crypto] 347 root 0:00 [mtdblock0] 352 root 0:00 [mtdblock1] 360 root 0:00 [ubi_bgt0d] 402 root 0:00 [ubifs_bgt0_0] 416 root 0:00 telnetd 421 root 0:00 {runapp.sh} /bin/sh ./runapp.sh 422 root 0:00 -sh 423 root 0:00 /sbin/getty 115200 tty1 vt100 429 root 0:00 ./gather_V0 446 root 0:00 [flush-ubifs_0_0] 452 root 0:00 sleep 10 455 root 0:00 ps ax [root@mcuzone root]#kill -9 421 [root@mcuzone root]#kill -9 429
1.1 更改上行网络
net_type 网络类型:
- 0 - GPRS
- 1 - RS485
- 2 - Ethernet (NOT SUPPORT)
- 3 - Zigbee (NOT SUPPORT)
typedef enum em_net_mod { em_net_gprs = 0, em_net_rs485, em_net_eth, em_net_zigbee } net_mod;
现场集中器上行使用 RS485 转 Ethernet 组网,因此需将 net_type 改为 1 (RS485):
[root@mcuzone root]#cd /app [root@mcuzone /app]#sqlite3 ./gatherdb.db SQLite version 3.10.0 2016-01-06 11:01:07 Enter ".help" for usage hints. sqlite> select * from t_base_define; sqlite> .head on sqlite> .mode column sqlite> select * from t_base_define; f_id f_config_name f_config_value ---------- -------------- -------------- 1 primary_server 122.5.18.174 2 primary_dns 219.146.0.130 3 primary_port 9011 4 second_server 219.146.0.130 5 second_dns 219.146.0.130 6 second_port 9027 7 gateway_id 37060001 8 net_type 0 9 md5_key 863CA654 10 aes_key d41d8cd98f00b2 11 collect_mode 0 12 collect_cycle 15 13 report_mode 0 14 beat_cycle 2 15 svr_num 0001 16 appmd5 28a011de19210e sqlite> update t_base_define set f_config_value='1' where f_config_name='net_type'; sqlite> sqlite> select * from t_base_define; f_id f_config_name f_config_value ---------- -------------- -------------- 1 primary_server 122.5.18.174 2 primary_dns 219.146.0.130 3 primary_port 9011 4 second_server 219.146.0.130 5 second_dns 219.146.0.130 6 second_port 9027 7 gateway_id 37060001 8 net_type 1 9 md5_key 863CA654 10 aes_key d41d8cd98f00b2 11 collect_mode 0 12 collect_cycle 15 13 report_mode 0 14 beat_cycle 2 15 svr_num 0001 16 appmd5 28a011de19210e
1.2 校准 RTC
确认集中器内 RTC 时间:
[root@mcuzone root]#hwclock -r Thu Jan 1 12:38:56 1970 0.000000 seconds
此时间会影响到上行 XML 数据内时间戳,时间不正确,需要根据现在时间校准集线器的 RTC:
[root@mcuzone root]#date -s 2017.01.06-12:38:48 Thu Jan 6 12:38:48 CST 2017 [root@mcuzone root]#hwclock -w # write RTC to store the time [root@mcuzone root]#hwclock -r Thu Jan 6 12:38:56 2017 0.000000 seconds
1.3 集中器联网
集中器联网,旨在更新集中器内部抄表核心程序。更新完毕网络即可拔除
打开集中器外壳,插上网线使其可访问外网
集中器 IP:
[root@mcuzone root]#ifconfig eth0 192.168.1.251 [root@mcuzone root]#ifconfig eth0 up eth0 Link encap:Ethernet HWaddr 4E:FC:21:ED:70:7A inet addr:192.168.1.251 Bcast:192.168.1.255 Mask:255.255.255.0 UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:16 errors:0 dropped:0 overruns:0 frame:0 TX packets:0 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:1344 (1.3 KiB) TX bytes:0 (0.0 B) Interrupt:24 Base address:0xc000
Gateway:
[root@mcuzone root]#route -n Kernel IP routing table Destination Gateway Genmask Flags Metric Ref Use Iface 192.168.1.0 0.0.0.0 255.255.255.0 U 0 0 0 eth0 [root@mcuzone root]#ping 42.121.85.30 PING 42.121.85.30 (42.121.85.30): 56 data bytes ping: sendto: Network is unreachable [root@mcuzone root]#route add default gw 192.168.1.1 [root@mcuzone root]#route -n Kernel IP routing table Destination Gateway Genmask Flags Metric Ref Use Iface 0.0.0.0 192.168.1.1 0.0.0.0 UG 0 0 0 eth0 192.168.1.0 0.0.0.0 255.255.255.0 U 0 0 0 eth0
Ping testing:
[root@mcuzone root]#ping 42.121.85.30 PING 42.121.85.30 (42.121.85.30): 56 data bytes 64 bytes from 42.121.85.30: seq=0 ttl=51 time=27.494 ms 64 bytes from 42.121.85.30: seq=1 ttl=51 time=28.665 ms 64 bytes from 42.121.85.30: seq=2 ttl=51 time=28.041 ms Ctrl+C --- 42.121.85.30 ping statistics --- 3 packets transmitted, 3 packets received, 0% packet loss round-trip min/avg/max = 27.494/28.066/28.665 ms
1.4 更新集中器核心程序
确认集中器可访问外网后,先备份原有抄表核心程序:
[root@mcuzone root]#cd /app [root@mcuzone /app]#ls buff1.xml buff3.xml gatherdb.db rcS x buff2.xml gather_V0 log.txt runapp.sh [root@mcuzone /app]#mv gather_V0 gather_V0.old [root@mcuzone /app]#ls buff1.xml buff3.xml gatherdb.db rcS x buff2.xml gather_V0.old log.txt runapp.sh
获取修正后的抄表核心程序:
[root@mcuzone /app]#wget http://42.121.85.30/gather_V0 Connecting to 42.121.85.30 (42.121.85.30:80) gather_V0 100% |*******************************| 316k 0:00:00 ETA [root@mcuzone /app]#ls buff1.xml buff3.xml gather_V0.old log.txt runapp.sh buff2.xml gather_V0 gatherdb.db rcS [root@mcuzone /app]#ls -l gather* -rw-r--r-- 1 root root 324430 Jan 6 12:25 gather_V0 -rwxr-xr-x 1 root root 294111 Jan 5 23:43 gather_V0.old -rw-r--r-- 1 1002 1002 51200 Jan 6 12:13 gatherdb.db [root@mcuzone /app]#chmod +x gather_V0 [root@mcuzone /app]#ls -l gather* -rwxr-xr-x 1 root root 324430 Jan 6 12:25 gather_V0 -rwxr-xr-x 1 root root 294111 Jan 5 23:43 gather_V0.old -rw-r--r-- 1 1002 1002 51200 Jan 6 12:13 gatherdb.db
试运行:
[root@mcuzone /app]#./gather_V0 Creat QMSG_FILE OK. g_uiQmsgFd = 0. XMLBuf_Init OK. QueuesInit OK! open_IOControl OK! ...... ...... [db.c][each_meter_info][1027] meter_type length : 2 [db.c][each_meter_info][1030] meter_type: 40 [db.c][each_meter_info][1052]135000000 ...... ......
重启集中器:
[root@mcuzone /app]#reboot
Or press the SW1 button to reset the Collector
1.5 ZLAN 5102 设置
ZLAN 配置工作在 TCP Client 模式,这样集中器通过 RS485 上行的 XML 数据自动被 ZLAN 转发到:
- Dest IP 为 122.5.18.172 的服务器(调试目的此 IP 为调试人员 PC)
- Dest Port 为 9011
因此运行于 122.5.18.172 上的上位机程序服务端口为 9011,上位服务器通过此端口获取集中器主动上发的 XML 数据,解析后需向集中器发包响应
没有响应数据包,集中器会认为发送失败,会重复发送上行数据
1.6 验证
到此,在调试人员 PC 122.5.18.172 上,开一个 TCP Server 端口在 9011,就能收到,集中器定时上传的 XML 数据:
comcat@jackslab:/work/5d/src/src-x$ sudo nc -l -p 9011 <?xml version="1.0" encoding="utf-8"?> <root><common><sadd>37060001</sadd><oadd></oadd><func_type>6</func_type><oper_type>3</oper_type></common><trans><total_meter_num>1</total_meter_num><frame_idx>1</frame_idx><meter_num>1</meter_num><time_node>2017-01-05 22:38:00</time_node></trans><row id="1"><f_id>2375</f_id><f_meter_type>40</f_meter_type><f_device_id>3</f_device_id><f_meter_address>00000000000087</f_meter_address><f_timestamp>2017-01-05 22:38:43</f_timestamp><f_time>2017-01-05 22:38:00</f_time><f_pact_tot_elec>null</f_pact_tot_elec><f_nact_tot_elec>null</f_nact_tot_elec><f_preact_tot_elec>null</f_preact_tot_elec><f_nreact_tot_elec>null</f_nreact_tot_elec><f_act_tot_elec>null</f_act_tot_elec><f_react_tot_elec>null</f_react_tot_elec></row></root> <?xml version="1.0" encoding="utf-8"?> <root><common><sadd>37060001</sadd><oadd></oadd><func_type>6</func_type><oper_type>3</oper_type></common><trans><total_meter_num>1</total_meter_num><frame_idx>1</frame_idx><meter_num>1</meter_num><time_node>2017-01-05 22:38:00</time_node></trans><row id="1"><f_id>2375</f_id><f_meter_type>40</f_meter_type><f_device_id>3</f_device_id><f_meter_address>00000000000087</f_meter_address><f_timestamp>2017-01-05 22:38:43</f_timestamp><f_time>2017-01-05 22:38:00</f_time><f_pact_tot_elec>null</f_pact_tot_elec><f_nact_tot_elec>null</f_nact_tot_elec><f_preact_tot_elec>null</f_preact_tot_elec><f_nreact_tot_elec>null</f_nreact_tot_elec><f_act_tot_elec>null</f_act_tot_elec><f_react_tot_elec>null</f_react_tot_elec></row></root> ...... ......
集中器默认抄表时间间隔为 15 分钟,调试目的,可将时间间隔调整为 2 分钟:
[root@mcuzone root]#cd /app [root@mcuzone /app]#sqlite3 ./gatherdb.db SQLite version 3.10.0 2016-01-06 11:01:07 Enter ".help" for usage hints. sqlite> select * from t_base_define where f_config_name='collect_cycle'; f_id f_config_name f_config_value ---------- -------------- -------------- 12 collect_cycle 15 sqlite> update t_base_define set f_config_value='2' where f_config_name='collect_cycle'; sqlite> .exit
重启集中器,即可生效:
[root@mcuzone /app]#reboot
2 Update APP
Your PC:
$ sudo apt-get install nfs-kernel-server Config the nfs directory: $ sudo mkdir -p /tftpboot/rootfs $ cat /etc/exports /work/armv9 *(async,rw,insecure,insecure_locks,no_root_squash) $ sudo /etc/init.d/nfs-kernel-server restart
In collector:
[root@mcuzone /app]#mount -o port=2049,nolock,proto=tcp -t nfs 192.168.1.72:/wor k/5d/src ./x [root@mcuzone /app]#ls x bin db include nfsroot src ubi.in chmod.sh dbtest.c lib sh src-x [root@mcuzone /app]#ls x/src-x Makefile main.c sysinit.c bsp.c meter_table.c uart_gprs.c commap.c notes.md uart_mbus_down485.c db.c queue.c uart_set.c elect.c read_heatmeter.c water.c gather_V1 readallmeters.c xml.c gprs.c rs485up.c include sysfuctions.c
Copy the gather_V1 into collector:
[root@mcuzone /app]#cp x/src-x/gather_V1 . [root@mcuzone /app]#ls 1runapp.sh buff2.xml gather_V0 gatherdb.db rcS x buff1.xml buff3.xml gather_V1 log.txt runapp.sh
3 Debug Log
4 采集器建议规范
4.1 采集器硬件要求
单次采集,数据量很大,硬件最好满足如下基本要求:
- 至少 32MB 内存
- 能跑嵌入式 Linux 系统
- 下行一路 RS485 最少支持 40 块表,支持多路 RS485
4.2 采集器固件功能要求
- 上行到服务器,用以太网,IP 地址和端口可配置,支持 DHCP (可选)
- 通过 http post 请求往内网服务器推送数据
- 数据间隔可调,最小粒度2分钟,即:每 2 分钟抄一次所有表,随后 http 发往内网服务器
- 集中器如果数据上行 http push失败,至少要能存储一天的历史数据,待内网服务器恢复后,自动将历史数据推送到服务器 (可选)
- 支持配置 building_id 和 gateway_id(可选)
- 集中器最好支持配置电表的 CT 变比,自动乘上 CT 变比 (可选)
4.3 采集器上传数据格式
- building_id 为建筑编号;gateway_id 为采集器编号
- meter_id 为电表地址, way_id 为电表的路号,支持一路的电表 way_id 为 1。支持六路三相电监控的路号为 1 ~ 6
- 电表数据要详细到三相电的每一相,就是上面 xml 格式内的phase A, B,C。每项的监测数据有电压 (U),电流 (I),功率 (P),功率因数 (PF),视在功率 (S)和无功功率 (Q)
- 三相总的(phase All)数据:功率因数 (PF),有功功率 (P),无功功率 (Q),视在功率 (S),正向有功总电能 (PEP),反向有功总电能 (NEP),正向无功总电能 (PEQ),反向无功总电能 (NEQ)
- 每一个时间间隔抄表,上行数据的 timestamp 必须统一 (xml: <time>20170908123000</time>)
<?xml version="1.0" encoding="utf-8"?> <root> <common> <building_id>110101B001</building_id> <gateway_id>2</gateway_id> <type>report</type> <data operation="report"> <sequence>0</sequence> <parser>yes</parser> <time>20170810093040</time> <total>1</total> <current>1</current> <meter id="70"> <function id="1" coding="01" error="0"> <way id="1"> <phase id="A"> <U>226.12</U> <I>7.00</I> <S>0.00</S> <P>0.70</P> <Q>0.00</Q> <PF>0.77</PF> </phase> <phase id="B"> <U>226.12</U> <I>7.00</I> <S>0.00</S> <P>0.70</P> <Q>0.00</Q> <PF>0.77</PF> </phase> <phase id="C"> <U>226.12</U> <I>7.00</I> <S>0.00</S> <P>0.70</P> <Q>0.00</Q> <PF>0.77</PF> </phase> <phase id="All"> <S>0.00</S> <P>0.00</P> <Q>0.00</Q> <PF>0.00</PF> <PEP>5.00</PEP> <NEP>6.00</NEP> <PEQ>5.00</PEQ> <NEQ>6.00</NEQ> </phase> </way> </function> </meter> <meter id="1"> <function id="1" coding="01" error="0"> <way id="1"> <phase id="A"> <U>226.12</U> <I>0.00</I> <S>0.00</S> <P>0.00</P> <Q>0.00</Q> <PF>0.10</PF> </phase> <phase id="B"> <U>226.12</U> <I>0.00</I> <S>0.00</S> <P>0.00</P> <Q>0.00</Q> <PF>0.10</PF> </phase> <phase id="C"> <U>226.12</U> <I>0.00</I> <S>0.00</S> <P>0.00</P> <Q>0.00</Q> <PF>0.10</PF> </phase> <phase id="All"> <S>0.00</S> <P>0.00</P> <Q>0.00</Q> <PF>0.00</PF> <PEP>5.00</PEP> <NEP>6.00</NEP> <PEQ>5.00</PEQ> <NEQ>6.00</NEQ> </phase> </way> <way id="2"> <phase id="A"> <U>226.12</U> <I>0.00</I> <S>0.00</S> <P>0.00</P> <Q>0.00</Q> <PF>0.20</PF> </phase> <phase id="B"> <U>226.12</U> <I>0.00</I> <S>0.00</S> <P>0.00</P> <Q>0.00</Q> <PF>0.20</PF> </phase> <phase id="C"> <U>226.12</U> <I>0.00</I> <S>0.00</S> <P>0.00</P> <Q>0.00</Q> <PF>0.20</PF> </phase> <phase id="All"> <S>0.00</S> <P>0.00</P> <Q>0.00</Q> <PF>0.00</PF> <PEP>5.00</PEP> <NEP>6.00</NEP> <PEQ>5.00</PEQ> <NEQ>6.00</NEQ> </phase> </way> <way id="3"> <phase id="A"> <U>226.12</U> <I>0.00</I> <S>0.00</S> <P>0.00</P> <Q>0.00</Q> <PF>0.30</PF> </phase> <phase id="B"> <U>226.12</U> <I>0.00</I> <S>0.00</S> <P>0.00</P> <Q>0.00</Q> <PF>0.30</PF> </phase> <phase id="C"> <U>226.12</U> <I>0.00</I> <S>0.00</S> <P>0.00</P> <Q>0.00</Q> <PF>0.30</PF> </phase> <phase id="All"> <S>0.00</S> <P>0.00</P> <Q>0.00</Q> <PF>0.00</PF> <PEP>5.00</PEP> <NEP>6.00</NEP> <PEQ>5.00</PEQ> <NEQ>6.00</NEQ> </phase> </way> <way id="4"> <phase id="A"> <U>226.12</U> <I>0.00</I> <S>0.00</S> <P>0.00</P> <Q>0.00</Q> <PF>0.40</PF> </phase> <phase id="B"> <U>226.12</U> <I>0.00</I> <S>0.00</S> <P>0.00</P> <Q>0.00</Q> <PF>0.40</PF> </phase> <phase id="C"> <U>226.12</U> <I>0.00</I> <S>0.00</S> <P>0.00</P> <Q>0.00</Q> <PF>0.40</PF> </phase> <phase id="All"> <S>0.00</S> <P>0.00</P> <Q>0.00</Q> <PF>0.00</PF> <PEP>5.00</PEP> <NEP>6.00</NEP> <PEQ>5.00</PEQ> <NEQ>6.00</NEQ> </phase> </way> <way id="5"> <phase id="A"> <U>226.12</U> <I>0.00</I> <S>0.00</S> <P>0.00</P> <Q>0.00</Q> <PF>0.50</PF> </phase> <phase id="B"> <U>226.12</U> <I>0.00</I> <S>0.00</S> <P>0.00</P> <Q>0.00</Q> <PF>0.50</PF> </phase> <phase id="C"> <U>226.12</U> <I>0.00</I> <S>0.00</S> <P>0.00</P> <Q>0.00</Q> <PF>0.50</PF> </phase> <phase id="All"> <S>0.00</S> <P>0.00</P> <Q>0.00</Q> <PF>0.00</PF> <PEP>5.00</PEP> <NEP>6.00</NEP> <PEQ>5.00</PEQ> <NEQ>6.00</NEQ> </phase> </way> <way id="6"> <phase id="A"> <U>226.12</U> <I>0.00</I> <S>0.00</S> <P>0.00</P> <Q>0.00</Q> <PF>0.60</PF> </phase> <phase id="B"> <U>226.12</U> <I>0.00</I> <S>0.00</S> <P>0.00</P> <Q>0.00</Q> <PF>0.60</PF> </phase> <phase id="C"> <U>226.12</U> <I>0.00</I> <S>0.00</S> <P>0.00</P> <Q>0.00</Q> <PF>0.60</PF> </phase> <phase id="All"> <S>0.00</S> <P>0.00</P> <Q>0.00</Q> <PF>0.00</PF> <PEP>5.00</PEP> <NEP>6.00</NEP> <PEQ>5.00</PEQ> <NEQ>6.00</NEQ> </phase> </way> </function> </meter> </data> </common> </root>
4.4 HTTP POST 格式
POST /dev/elec HTTP/1.1 Host: 192.168.1.20 User-Agent: curl/7.52.1 Accept: */* Content-Length: 3401 Content-Type: application/x-www-form-urlencoded Expect: 100-continue <?xml version="1.0" encoding="utf-8" ?><root><common><building_id>110101B001</building_id><gateway_id>2</gateway_id><type>report</type><data operation="report"><sequence>0</sequence><parser>yes</parser><time>20170810093040</time><total>1</total><current>1</current><meter id="70"><function id="1" coding="01" error="0"><way id="1"><phase id="A"><U>226.12</U><I>7.00</I><S>0.00</S><P>0.70</P><Q>0.00</Q><PF>0.77</PF></phase><phase id="B"><U>226.12</U><I>7.00</I><S>0.00</S><P>0.70</P><Q>0.00</Q><PF>0.77</PF></phase><phase id="C"><U>226.12</U><I>7.00</I><S>0.00</S><P>0.70</P><Q>0.00</Q><PF>0.77</PF></phase><phase id="All"><S>0.00</S><P>0.00</P><Q>0.00</Q><PF>0.00</PF><PEP>5.00</PEP><NEP>6.00</NEP><PEQ>5.00</PEQ><NEQ>6.00</NEQ></phase></way></function></meter><meter id="1"><function id="1" coding="01" error="0"><way id="1"><phase id="A"><U>226.12</U><I>0.00</I><S>0.00</S><P>0.00</P><Q>0.00</Q><PF>0.10</PF></phase><phase id="B"><U>226.12</U><I>0.00</I><S>0.00</S><P>0.00</P><Q>0.00</Q><PF>0.10</PF></phase><phase id="C"><U>226.12</U><I>0.00</I><S>0.00</S><P>0.00</P><Q>0.00</Q><PF>0.10</PF></phase><phase id="All"><S>0.00</S><P>0.00</P><Q>0.00</Q><PF>0.00</PF><PEP>5.00</PEP><NEP>6.00</NEP><PEQ>5.00</PEQ><NEQ>6.00</NEQ></phase></way><way id="2"><phase id="A"><U>226.12</U><I>0.00</I><S>0.00</S><P>0.00</P><Q>0.00</Q><PF>0.20</PF></phase><phase id="B"><U>226.12</U><I>0.00</I><S>0.00</S><P>0.00</P><Q>0.00</Q><PF>0.20</PF></phase><phase id="C"><U>226.12</U><I>0.00</I><S>0.00</S><P>0.00</P><Q>0.00</Q><PF>0.20</PF></phase><phase id="All"><S>0.00</S><P>0.00</P><Q>0.00</Q><PF>0.00</PF><PEP>5.00</PEP><NEP>6.00</NEP><PEQ>5.00</PEQ><NEQ>6.00</NEQ></phase></way><way id="3"><phase id="A"><U>226.12</U><I>0.00</I><S>0.00</S><P>0.00</P><Q>0.00</Q><PF>0.30</PF></phase><phase id="B"><U>226.12</U><I>0.00</I><S>0.00</S><P>0.00</P><Q>0.00</Q><PF>0.30</PF></phase><phase id="C"><U>226.12</U><I>0.00</I><S>0.00</S><P>0.00</P><Q>0.00</Q><PF>0.30</PF></phase><phase id="All"><S>0.00</S><P>0.00</P><Q>0.00</Q><PF>0.00</PF><PEP>5.00</PEP><NEP>6.00</NEP><PEQ>5.00</PEQ><NEQ>6.00</NEQ></phase></way><way id="4"><phase id="A"><U>226.12</U><I>0.00</I><S>0.00</S><P>0.00</P><Q>0.00</Q><PF>0.40</PF></phase><phase id="B"><U>226.12</U><I>0.00</I><S>0.00</S><P>0.00</P><Q>0.00</Q><PF>0.40</PF></phase><phase id="C"><U>226.12</U><I>0.00</I><S>0.00</S><P>0.00</P><Q>0.00</Q><PF>0.40</PF></phase><phase id="All"><S>0.00</S><P>0.00</P><Q>0.00</Q><PF>0.00</PF><PEP>5.00</PEP><NEP>6.00</NEP><PEQ>5.00</PEQ><NEQ>6.00</NEQ></phase></way><way id="5"><phase id="A"><U>226.12</U><I>0.00</I><S>0.00</S><P>0.00</P><Q>0.00</Q><PF>0.50</PF></phase><phase id="B"><U>226.12</U><I>0.00</I><S>0.00</S><P>0.00</P><Q>0.00</Q><PF>0.50</PF></phase><phase id="C"><U>226.12</U><I>0.00</I><S>0.00</S><P>0.00</P><Q>0.00</Q><PF>0.50</PF></phase><phase id="All"><S>0.00</S><P>0.00</P><Q>0.00</Q><PF>0.00</PF><PEP>5.00</PEP><NEP>6.00</NEP><PEQ>5.00</PEQ><NEQ>6.00</NEQ></phase></way><way id="6"><phase id="A"><U>226.12</U><I>0.00</I><S>0.00</S><P>0.00</P><Q>0.00</Q><PF>0.60</PF></phase><phase id="B"><U>226.12</U><I>0.00</I><S>0.00</S><P>0.00</P><Q>0.00</Q><PF>0.60</PF></phase><phase id="C"><U>226.12</U><I>0.00</I><S>0.00</S><P>0.00</P><Q>0.00</Q><PF>0.60</PF></phase><phase id="All"><S>0.00</S><P>0.00</P><Q>0.00</Q><PF>0.00</PF><PEP>5.00</PEP><NEP>6.00</NEP><PEQ>5.00</PEQ><NEQ>6.00</NEQ></phase></way></function></meter></data></common></root>
or:
$ cat d.xml <?xml version="1.0" encoding="utf-8" ?><root><common><building_id>110101B001</building_id><gateway_id>2</gateway_id><type>report</type><data operation="report"><sequence>0</sequence><parser>yes</parser><time>20170810093040</time><total>1</total><current>1</current><meter id="70"><function id="1" coding="01" error="0"><way id="1"><phase id="A"><U>226.12</U><I>7.00</I><S>0.00</S><P>0.70</P><Q>0.00</Q><PF>0.77</PF></phase><phase id="B"><U>226.12</U><I>7.00</I><S>0.00</S><P>0.70</P><Q>0.00</Q><PF>0.77</PF></phase><phase id="C"><U>226.12</U><I>7.00</I><S>0.00</S><P>0.70</P><Q>0.00</Q><PF>0.77</PF></phase><phase id="All"><S>0.00</S><P>0.00</P><Q>0.00</Q><PF>0.00</PF><PEP>5.00</PEP><NEP>6.00</NEP><PEQ>5.00</PEQ><NEQ>6.00</NEQ></phase></way></function></meter><meter id="1"><function id="1" coding="01" error="0"><way id="1"><phase id="A"><U>226.12</U><I>0.00</I><S>0.00</S><P>0.00</P><Q>0.00</Q><PF>0.10</PF></phase><phase id="B"><U>226.12</U><I>0.00</I><S>0.00</S><P>0.00</P><Q>0.00</Q><PF>0.10</PF></phase><phase id="C"><U>226.12</U><I>0.00</I><S>0.00</S><P>0.00</P><Q>0.00</Q><PF>0.10</PF></phase><phase id="All"><S>0.00</S><P>0.00</P><Q>0.00</Q><PF>0.00</PF><PEP>5.00</PEP><NEP>6.00</NEP><PEQ>5.00</PEQ><NEQ>6.00</NEQ></phase></way><way id="2"><phase id="A"><U>226.12</U><I>0.00</I><S>0.00</S><P>0.00</P><Q>0.00</Q><PF>0.20</PF></phase><phase id="B"><U>226.12</U><I>0.00</I><S>0.00</S><P>0.00</P><Q>0.00</Q><PF>0.20</PF></phase><phase id="C"><U>226.12</U><I>0.00</I><S>0.00</S><P>0.00</P><Q>0.00</Q><PF>0.20</PF></phase><phase id="All"><S>0.00</S><P>0.00</P><Q>0.00</Q><PF>0.00</PF><PEP>5.00</PEP><NEP>6.00</NEP><PEQ>5.00</PEQ><NEQ>6.00</NEQ></phase></way><way id="3"><phase id="A"><U>226.12</U><I>0.00</I><S>0.00</S><P>0.00</P><Q>0.00</Q><PF>0.30</PF></phase><phase id="B"><U>226.12</U><I>0.00</I><S>0.00</S><P>0.00</P><Q>0.00</Q><PF>0.30</PF></phase><phase id="C"><U>226.12</U><I>0.00</I><S>0.00</S><P>0.00</P><Q>0.00</Q><PF>0.30</PF></phase><phase id="All"><S>0.00</S><P>0.00</P><Q>0.00</Q><PF>0.00</PF><PEP>5.00</PEP><NEP>6.00</NEP><PEQ>5.00</PEQ><NEQ>6.00</NEQ></phase></way><way id="4"><phase id="A"><U>226.12</U><I>0.00</I><S>0.00</S><P>0.00</P><Q>0.00</Q><PF>0.40</PF></phase><phase id="B"><U>226.12</U><I>0.00</I><S>0.00</S><P>0.00</P><Q>0.00</Q><PF>0.40</PF></phase><phase id="C"><U>226.12</U><I>0.00</I><S>0.00</S><P>0.00</P><Q>0.00</Q><PF>0.40</PF></phase><phase id="All"><S>0.00</S><P>0.00</P><Q>0.00</Q><PF>0.00</PF><PEP>5.00</PEP><NEP>6.00</NEP><PEQ>5.00</PEQ><NEQ>6.00</NEQ></phase></way><way id="5"><phase id="A"><U>226.12</U><I>0.00</I><S>0.00</S><P>0.00</P><Q>0.00</Q><PF>0.50</PF></phase><phase id="B"><U>226.12</U><I>0.00</I><S>0.00</S><P>0.00</P><Q>0.00</Q><PF>0.50</PF></phase><phase id="C"><U>226.12</U><I>0.00</I><S>0.00</S><P>0.00</P><Q>0.00</Q><PF>0.50</PF></phase><phase id="All"><S>0.00</S><P>0.00</P><Q>0.00</Q><PF>0.00</PF><PEP>5.00</PEP><NEP>6.00</NEP><PEQ>5.00</PEQ><NEQ>6.00</NEQ></phase></way><way id="6"><phase id="A"><U>226.12</U><I>0.00</I><S>0.00</S><P>0.00</P><Q>0.00</Q><PF>0.60</PF></phase><phase id="B"><U>226.12</U><I>0.00</I><S>0.00</S><P>0.00</P><Q>0.00</Q><PF>0.60</PF></phase><phase id="C"><U>226.12</U><I>0.00</I><S>0.00</S><P>0.00</P><Q>0.00</Q><PF>0.60</PF></phase><phase id="All"><S>0.00</S><P>0.00</P><Q>0.00</Q><PF>0.00</PF><PEP>5.00</PEP><NEP>6.00</NEP><PEQ>5.00</PEQ><NEQ>6.00</NEQ></phase></way></function></meter></data></common></root> $ curl -X POST -d @d.xml http://192.168.1.20:8000/dev/elec
5 Old XML Format
From collector:
<?xml version="1.0" encoding="utf-8"?> <root> <common> <sadd>37060001</sadd> <oadd></oadd> <func_type>6</func_type> <oper_type>3</oper_type> </common> <trans> <total_meter_num>1</total_meter_num> <frame_idx>1</frame_idx> <meter_num>1</meter_num <time_node>2017-01-05 22:38:00</time_node> </trans> <row id="1"> <f_id>2375</f_id> <f_meter_type>40</f_meter_type> <f_device_id>3</f_device_id> <f_meter_address>00000000000087</f_meter_address> <f_timestamp>2017-01-05 22:38:43</f_timestamp> <f_time>2017-01-05 22:38:00</f_time> <f_pact_tot_elec>null</f_pact_tot_elec> <f_nact_tot_elec>null</f_nact_tot_elec> <f_preact_tot_elec>null</f_preact_tot_elec> <f_nreact_tot_elec>null</f_nreact_tot_elec> <f_act_tot_elec>null</f_act_tot_elec> <f_react_tot_elec>null</f_react_tot_elec> </row> </root>
6 NOTES
6.1 Meter Type
- HEATMETER 0x20
- WATERMETER 0x10
- ELECTMETER 0x40
- GASMETER 0x30
- SENSORDEV 0x50 // RTU module of sensors
6.2 ElectMeter Protocol
/* * Format:串口设置, 读取电表数据标识符, 前导符个数, 通讯类型 (0:MBUS 1:485), 通讯协议类型(0:MODBUS 1:645) */ uint16 gELEC_METER_Table[ELECMETER_PROTO_SUM][5] = { {ELEC_COMSET_1, 0x0000, 0, ELEC_RS485, ELEC_PROTO_MODBUS}, //力创电表 -----idx: -0- {ELEC_COMSET_1, 0x0000, 0, ELEC_RS485, ELEC_PROTO_MODBUS}, //acrel DDSD1352单相电表 -----idx: -1- {ELEC_COMSET_1, 0x0000, 0, ELEC_RS485, ELEC_PROTO_MODBUS}, //acrel DTSF1352三相电表 -----idx: -2- {ELEC_COMSET_1, 0x0000, 0, ELEC_RS485, ELEC_PROTO_MODBUS}, //acrel PZ80-E4C三相电表 -----idx: -3- };
6.3 Meter Channel
Only support:
- RS485_DOWN_CHANNEL 7
6.4 Meter Config in Database
sqlite> .schema t_meter_info CREATE TABLE t_meter_info ( f_id integer primary key autoincrement, f_meter_type varchar(2), f_device_id varchar(4), f_meter_address varchar(14), f_meter_channel varchar(2), f_meter_proto_type varchar(2), f_install_pos varchar(50) ); sqlite> select * from t_meter_info; 18|40|3|00000000000001|7|0|3#地下室 19|20|4|11110020160429|1|0|3#under sqlite> .dump t_meter_info PRAGMA foreign_keys=OFF; BEGIN TRANSACTION; INSERT INTO "t_meter_info" VALUES(18,'40','3','00000000000001','7','0','3#地下室'); INSERT INTO "t_meter_info" VALUES(19,'20','4','11110020160429','1','0','3#under'); COMMIT;
7 Hardware
7.1 Serial Console
- CP2102_PIN26 --- ARM9_CORE_J2_32_DRXD
- CP2102_PIN25 --- ARM9_CORE_J2_30_DTXD
7.2 RS485_1
- RS485_1_A+ --- MAX485_PIN6
- RS485_1_B- --- MAX485_PIN7
- MAX485_PIN4 --- ARM9_CORE_J2_68_TXD0
- MAX485_PIN1 --- ARM9_CORE_J2_69_RXD0
- MAX485_PIN2 & 3 --- ARM9_CORE_J1_69_PC30
7.3 RS485_2
- RS485_2_A+ --- MAX485_PIN6
- RS485_2_B- --- MAX485_PIN7
- MAX485_PIN4 --- ARM9_CORE_J2_55_CANTX1
- MAX485_PIN1 --- ARM9_CORE_J2__57_CANRX1
- MAX485_PIN2 & 3 --- ARM9_CORE_J1_68_PC31
8 Drivers
atmel_usart:
atmel_usart.0: ttyS0 at MMIO 0xfefff200 (irq = 1) is a ATMEL_SERIAL atmel_usart.1: ttyS1 at MMIO 0xf801c000 (irq = 5) is a ATMEL_SERIAL atmel_usart.2: ttyS2 at MMIO 0xf8020000 (irq = 6) is a ATMEL_SERIAL atmel_usart.3: ttyS3 at MMIO 0xf8024000 (irq = 7) is a ATMEL_SERIAL atmel_usart.5: ttyS5 at MMIO 0xf8040000 (irq = 15) is a ATMEL_SERIAL atmel_usart.6: ttyS6 at MMIO 0xf8044000 (irq = 16) is a ATMEL_SERIAL
#define DEVICE4851 "/dev/ttyS1" #define DEVICE4852 "/dev/ttyS2" #define DEVICEGPRS "/dev/ttyS3" #define DEVICEMBUS "/dev/ttyS6" #define IO_CONTROL "/dev/CONTROL_IO"
9 Boot log
RomBOOT Start AT91Bootstrap... Init DDR... Done! Loading 1-Wire info... Enumerate all roms: Done, 0x0 1-wire chips found! No 1-Wire chip found on EXID=0x0x2! MCUzone:try to load from preset area... sn: 0xa0284a4; rev: 0x248421 Downloading image... chip id: 0xecda Copy 0x50000 bytes from 0x40000 to 0x26f00000 Done! U-Boot 2010.06 (May 24 2012 - 14:30:50) DRAM: 128 MiB NAND: 256 MiB *** Warning - bad CRC or NAND, using default environment In: serial Out: serial Err: serial Net: macb0 macb0: Starting autonegotiation... macb0: Autonegotiation complete macb0: link up, 100Mbps full-duplex (lpa: 0x4de1) Hit any key to stop autoboot: 0 NAND read: device 0 offset 0x200000, size 0x250000 2424832 bytes read: OK ## Booting kernel from Legacy Image at 22000000 ... Image Name: Linux-2.6.39 Image Type: ARM Linux Kernel Image (uncompressed) Data Size: 2107352 Bytes = 2 MiB Load Address: 20008000 Entry Point: 20008000 Verifying Checksum ... OK Loading Kernel Image ... OK OK Starting kernel ... Uncompressing Linux... done, booting the kernel. Linux version 2.6.39 (root@mcuzone) (gcc version 4.5.2 (Sourcery G++ Lite 2011.03-41) ) #30 Wed Aug 28 10:47:14 CST 2013 CPU: ARM926EJ-S [41069265] revision 5 (ARMv5TEJ), cr=00053177 CPU: VIVT data cache, VIVT instruction cache Machine: Atmel AT91SAM9X5-EK Memory policy: ECC disabled, Data cache writeback Clocks: CPU 400 MHz, master 133 MHz, main 12.000 MHz Built 1 zonelists in Zone order, mobility grouping on. Total pages: 32512 Kernel command line: mem=128M console=ttyS0,115200 mtdparts=atmel_nand:8M(bootstrap/uboot/kernel)ro,-(rootfs) root=/dev/mtdblock1 rw rootfstype=ubifs ubi.mtd=1 root=ubi0:rootfs PID hash table entries: 512 (order: -1, 2048 bytes) Dentry cache hash table entries: 16384 (order: 4, 65536 bytes) Inode-cache hash table entries: 8192 (order: 3, 32768 bytes) Memory: 128MB = 128MB total Memory: 125696k/125696k available, 5376k reserved, 0K highmem Virtual kernel memory layout: vector : 0xffff0000 - 0xffff1000 ( 4 kB) fixmap : 0xfff00000 - 0xfffe0000 ( 896 kB) DMA : 0xff000000 - 0xffe00000 ( 14 MB) vmalloc : 0xc8800000 - 0xfee00000 ( 870 MB) lowmem : 0xc0000000 - 0xc8000000 ( 128 MB) modules : 0xbf000000 - 0xc0000000 ( 16 MB) .init : 0xc0008000 - 0xc002a000 ( 136 kB) .text : 0xc002a000 - 0xc03e0708 (3802 kB) .data : 0xc03e2000 - 0xc0408a40 ( 155 kB) NR_IRQS:192 AT91: 128 gpio irqs in 4 banks Console: colour dummy device 80x30 console [ttyS0] enabled Calibrating delay loop... 199.06 BogoMIPS (lpj=995328) pid_max: default: 32768 minimum: 301 Mount-cache hash table entries: 512 CPU: Testing write buffer coherency: ok NET: Registered protocol family 16 AT91: CM rev B and higher AT91: EK rev B and higher AT91: Power Management (with slow clock mode) AT91: Starting after user reset bio: create slab <bio-0> at 0 SCSI subsystem initialized usbcore: registered new interface driver usbfs usbcore: registered new interface driver hub usbcore: registered new device driver usb i2c-gpio i2c-gpio.0: using pins 62 (SDA) and 63 (SCL) at_hdmac at_hdmac.0: Atmel AHB DMA Controller ( cpy slave ), 8 channels at_hdmac at_hdmac.1: Atmel AHB DMA Controller ( cpy slave ), 8 channels cfg80211: Calling CRDA to update world regulatory domain Switching to clocksource tcb_clksrc NET: Registered protocol family 2 IP route cache hash table entries: 1024 (order: 0, 4096 bytes) TCP established hash table entries: 4096 (order: 3, 32768 bytes) TCP bind hash table entries: 4096 (order: 2, 16384 bytes) TCP: Hash tables configured (established 4096 bind 4096) TCP reno registered UDP hash table entries: 256 (order: 0, 4096 bytes) UDP-Lite hash table entries: 256 (order: 0, 4096 bytes) NET: Registered protocol family 1 RPC: Registered udp transport module. RPC: Registered tcp transport module. RPC: Registered tcp NFSv4.1 backchannel transport module. NetWinder Floating Point Emulator V0.97 (double precision) JFFS2 version 2.2. (NAND) (SUMMARY) © 2001-2006 Red Hat, Inc. msgmni has been set to 245 io scheduler noop registered (default) atmel_usart.0: ttyS0 at MMIO 0xfefff200 (irq = 1) is a ATMEL_SERIAL atmel_usart.1: ttyS1 at MMIO 0xf801c000 (irq = 5) is a ATMEL_SERIAL atmel_usart.2: ttyS2 at MMIO 0xf8020000 (irq = 6) is a ATMEL_SERIAL atmel_usart.3: ttyS3 at MMIO 0xf8024000 (irq = 7) is a ATMEL_SERIAL atmel_usart.5: ttyS5 at MMIO 0xf8040000 (irq = 15) is a ATMEL_SERIAL atmel_usart.6: ttyS6 at MMIO 0xf8044000 (irq = 16) is a ATMEL_SERIAL pioa_baseaddr is ok pioc_baseaddr is ok CONTROL_IO initialized brd: module loaded loop: module loaded ssc ssc.0: Atmel SSC device at 0xc8898000 (irq 28) atmel_nand atmel_nand: Using dma0chan0 for DMA transfers. NAND device: Manufacturer ID: 0xec, Chip ID: 0xda (Samsung NAND 256MiB 3,3V 8-bit) atmel_pmecc_init_params Scanning device for bad blocks Bad eraseblock 220 at 0x000001b80000 Bad eraseblock 590 at 0x0000049c0000 Bad eraseblock 1126 at 0x000008cc0000 Bad eraseblock 1268 at 0x000009e80000 Bad eraseblock 1313 at 0x00000a420000 2 cmdlinepart partitions found on MTD device atmel_nand Creating 2 MTD partitions on "atmel_nand": 0x000000000000-0x000000800000 : "bootstrap/uboot/kernel" 0x000000800000-0x000010000000 : "rootfs" UBI: attaching mtd1 to ubi0 UBI: physical eraseblock size: 131072 bytes (128 KiB) UBI: logical eraseblock size: 126976 bytes UBI: smallest flash I/O unit: 2048 UBI: VID header offset: 2048 (aligned 2048) UBI: data offset: 4096 UBI: max. sequence number: 88 UBI: attached mtd1 to ubi0 UBI: MTD device name: "rootfs" UBI: MTD device size: 248 MiB UBI: number of good PEBs: 1979 UBI: number of bad PEBs: 5 UBI: number of corrupted PEBs: 0 UBI: max. allowed volumes: 128 UBI: wear-leveling threshold: 4096 UBI: number of internal volumes: 1 UBI: number of user volumes: 1 UBI: available PEBs: 0 UBI: total number of reserved PEBs: 1979 UBI: number of PEBs reserved for bad PEB handling: 19 UBI: max/mean erase counter: 2/0 UBI: image sequence number: 216742870 UBI: background thread "ubi_bgt0d" started, PID 360 macb macb.0: invalid hw address, using random macb macb.0: eth0: Features changed: 0x00004800 -> 0x00004000 MACB_mii_bus: probed eth0: Atmel MACB at 0xf802c000 irq 24 (52:ac:b8:80:5f:b2) eth0: attached PHY driver [Generic PHY] (mii_bus:phy_addr=0:00, irq=-1) ehci_hcd: USB 2.0 'Enhanced' Host Controller (EHCI) Driver atmel-ehci atmel-ehci: Atmel EHCI UHP HS atmel-ehci atmel-ehci: new USB bus registered, assigned bus number 1 atmel-ehci atmel-ehci: irq 22, io mem 0x00700000 atmel-ehci atmel-ehci: USB 2.0 started, EHCI 1.00 hub 1-0:1.0: USB hub found hub 1-0:1.0: 3 ports detected ohci_hcd: USB 1.1 'Open' Host Controller (OHCI) Driver at91_ohci at91_ohci: AT91 OHCI at91_ohci at91_ohci: new USB bus registered, assigned bus number 2 at91_ohci at91_ohci: irq 22, io mem 0x00600000 hub 2-0:1.0: USB hub found hub 2-0:1.0: 3 ports detected Initializing USB Mass Storage driver... usbcore: registered new interface driver usb-storage USB Mass Storage support registered. usbcore: registered new interface driver libusual atmel_usba_udc atmel_usba_udc: MMIO registers at 0xf803c000 mapped at c88fe000 atmel_usba_udc atmel_usba_udc: FIFO at 0x00500000 mapped at d9100000 atmel_tsadcc atmel_tsadcc: Master clock is set at: 133333333 Hz atmel_tsadcc atmel_tsadcc: Prescaler is set at: 221 input: atmel touch screen controller as /devices/platform/atmel_tsadcc/input/input0 rtc-rx8025 0-0032: rtc core: registered rx8025 as rtc0 i2c /dev entries driver usbcore: registered new interface driver usbhid usbhid: USB HID core driver nf_conntrack version 0.5.0 (1964 buckets, 7856 max) ip_tables: (C) 2000-2006 Netfilter Core Team TCP cubic registered NET: Registered protocol family 17 lib80211: common routines for IEEE802.11 drivers Registering the dns_resolver key type rtc-rx8025 0-0032: setting system clock to 2017-01-06 00:38:50 UTC (1483634330) atmel_mci atmel_mci.0: Using dma0chan1 for DMA transfers atmel_mci atmel_mci.0: Atmel MCI controller at 0xf0008000 irq 12, 1 slots atmel_mci atmel_mci.1: Using dma1chan0 for DMA transfers atmel_mci atmel_mci.1: Atmel MCI controller at 0xf000c000 irq 26, 1 slots UBIFS: recovery needed UBIFS: recovery completed UBIFS: mounted UBI device 0, volume 0, name "rootfs" UBIFS: file system size: 58662912 bytes (57288 KiB, 55 MiB, 462 LEBs) UBIFS: journal size: 7872512 bytes (7688 KiB, 7 MiB, 62 LEBs) UBIFS: media format: w4/r0 (latest is w4/r0) UBIFS: default compressor: lzo UBIFS: reserved for root: 0 bytes (0 KiB) VFS: Mounted root (ubifs filesystem) on device 0:12. Freeing init memory: 136K ******************************** Exec rcS ******************************** ********mount all******** mount: according to /proc/mounts, porc is already mounted on /proc mount: mounting usbfs on /proc/bus/usb failed: No such file or directory ********Starting mdev******** This may take some time ... --------Start Local Services-------- ********Starting telnetd******** *********alsa restore*********** alsactl: load_state:1625: No soundcards found... *********touchscreen************ ******************************** 513 xi'an R&D Center Linux For Energy Monitor ******************************** ******************************************** program restart! ******************************************** mcuzone login: Creat QMSG_FILE OK. g_uiQmsgFd = 0. XMLBuf_Init OK. QueuesInit OK! open_IOControl OK! [db.c][read_meter_info][996]read meter info: select f_meter_address, f_meter_type, f_meter_channel, f_id, f_install_pos, f_device_id, f_meter_proto_type from t_meter_info order by f_meter_channel, f_id desc; [db.c][each_meter_info][1027] meter_type length : 2 [db.c][each_meter_info][1030] meter_type: 40 [db.c][each_meter_info][1052]135000000 Create RS485Up_Rec_pthreadID OK! Create UartGprs_Rec_pthreadID OK! Create UartMbus_Rec_pthreadID OK! Create UartDown485_Rec_pthreadID OK! Create pthread_GPRS_Mana OK! Create pthread_GPRS_IPD OK! Create pthread_GprsDataDeal OK! Create pthread_RS485UpDeal OK! Create pthread_ReadAllMeters OK! Create pthread_up_long_data OK! RS485Down com parameter set OK. MBUS com parameter set OK. GPRS com parameter set OK. ... ...
10 有功无功
根据《多功能电能表通信协议》DL/T645-2007的规定,我们将一个平面坐标系的横轴定义为无功功率,纵轴定义为有功功率,二个轴将一个平面划分为四个区域,左上角的为Ⅰ象限,顺时针依次为Ⅱ象限、Ⅲ象限和Ⅳ象限;Ⅰ象限和Ⅱ象限无功定义为正向无功, Ⅲ象限和Ⅳ象限无功定义为反向无功;
我们按下面的要求定义实际功率的方向:
- 正向有功功率:即输入有功功率,是电网向用户送电,是用户用电功率;
- 反向有功功率:即输出有功功率,是用户向电网送电,是用户发电功率;
- 正向无功功率:即输入无功功率,是电网向用户送无功,是用户用无功功率;
- 反向无功功率:即输出无功功率,是用户向电网送无功,是用户发无功功率;
- Ⅰ象限无功:输入有功功率,输入无功功率,用户为阻感性负载;
- Ⅱ象限无功:输出有功功率,输入无功功率,用户负荷相当于一台欠励磁发电机;
- Ⅲ象限无功:输出有功功率,输出无功功率,用户负荷相当于一台过励磁发电机;
- Ⅳ象限无功:输入有功功率,输出无功功率,用户为阻容性负载
正向无功是指系统呈感性 反向无功是指系统呈容性 ,正反向都计量无功
11 Reference
- DTSD106-M100 三相电子式电能表用户使用手册: http://www.go-gddq.com/down/2011-10/11102117032297.pdf
- ZLAN5102-3 用户使用手册l: http://www.zlmcu.com/download/ZLAN5102-3.pdf
- http://docs.grafana.org/http_api/alerting/
- http://docs.grafana.org/features/datasources/influxdb/
- https://docs.influxdata.com/influxdb/v1.2/concepts/schema_and_data_layout/
- https://docs.influxdata.com/influxdb/v1.3/guides/writing_data/