forked from tenstartups/ecm1240-monitor-docker
-
Notifications
You must be signed in to change notification settings - Fork 1
/
btmon.py
executable file
·4464 lines (3744 loc) · 170 KB
/
btmon.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/usr/bin/python -u
__version__ = '3.0.8'
"""Data collector/processor for Brultech monitoring devices.
Collect data from Brultech ECM-1240, ECM-1220, and GEM power monitors. Print
the data, save the data to database, or upload the data to a server.
Includes support for uploading to the following services:
* MyEnerSave * SmartEnergyGroups * xively * WattzOn
* PlotWatt * PeoplePower * thingspeak * Eragy
* emoncms * Wattvision * PVOutput * Bidgely
Thanks to:
Amit Snyderman <[email protected]>
bpwwer & tenholde from the cocoontech.com forums
Kelvin Kakugawa
brian jackson [http://fivejacksons.com/brian/]
Marc MERLIN <[email protected]> - http://marc.merlins.org/
Ben <[email protected]>
Eric Sandeen
Mark Lennox
Graham Allan
Copyright 2012-2015 Matthew Wall, all rights reserved
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 3 of the License, or 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 http://www.gnu.org/licenses/
Example Usage:
btmon.py --serial --serialport=/dev/ttyUSB0 -p
Example Output:
2010/06/07 21:48:37: ECM ID: 355555
2010/06/07 21:48:37: Volts: 120.90V
2010/06/07 21:48:37: Ch1 Amps: 0.25A
2010/06/07 21:48:37: Ch2 Amps: 3.24A
2010/06/07 21:48:37: Ch1 Watts: -124.586KWh ( 1536W)
2010/06/07 21:48:37: Ch1 Positive Watts: 210.859KWh ( 1536W)
2010/06/07 21:48:37: Ch1 Negative Watts: 335.445KWh ( 0W)
2010/06/07 21:48:37: Ch2 Watts: -503.171KWh ( 0W)
2010/06/07 21:48:37: Ch2 Positive Watts: 0.028KWh ( 0W)
2010/06/07 21:48:37: Ch2 Negative Watts: 503.199KWh ( 0W)
2010/06/07 21:48:37: Aux1 Watts: 114.854KWh ( 311W)
2010/06/07 21:48:37: Aux2 Watts: 80.328KWh ( 523W)
2010/06/07 21:48:37: Aux3 Watts: 13.014KWh ( 35W)
2010/06/07 21:48:37: Aux4 Watts: 4.850KWh ( 0W)
2010/06/07 21:48:37: Aux5 Watts: 25.523KWh ( 137W)
How to specify options:
Options can be specified via command line, in a configuration file, or by
modifying constants in this file. Use --help to see the complete list
of command-line options. The configuration file is INI format, with parameter
names corresponding to the command-line options.
Here are contents of a sample configuration file that listens for data on port
8083 then uploads only channel 1 and channel 2 data from device with serial
number 311111 to plotwatt and enersave and saves to a MySQL database:
[source]
ip_read = true
ip_port = 8083
ip_mode = server
[mysql]
mysql_out = true
mysql_host = localhost
mysql_user = ecmuser
mysql_passwd = ecmpass
[plotwatt]
plotwatt_out = true
pw_map = 311111_ch1,123,311111_ch2,124
pw_house_id = 1234
pw_api_key = 12345
[enersave]
enersave_out = true
es_map = 311111_ch1,kitchen,2,311111_ch2,solar panels,1
Data Collection:
Data can be collected by serial/usb, tcp/ip as client or server, or by polling
a database.
When collecting via serial/usb, btmon can either poll the device or block until
data appear. Polling should be used when the device is not in real-time mode,
blocking should be used when the device is in real-time mode.
When collecting via tcp/ip, btmon can act as either a server or client. When
in server mode, btmon blocks until a client connects. When in client mode,
btmon can either poll or block. When polling, btmon opens a connection to the
server, makes a request for data, then closes the connection. When blocking,
btmon opens a connection to the server then blocks until data have been read.
When collecting from a database, btmon queries the database periodically then
processes the new data as if they were generated by a brultech device.
Data Processing:
Data can be printed to standard output, saved to database, and/or sent to one
or more hosted services. Instructions for each of the services are enumerated
in the following sections.
MySQL Database Configuration:
Connections to MySQL require the pysqldb module. On debian systems install the
module using apt-get:
apt-get install python-mysqldb
Ensure a user exists and has proper permissions. For example, for the user
'ecmuser' with password 'ecmpass' connecting from 'ecmclient' to the database
'ecm', do something like this on the system hosting the database:
# mysql -u root -p
# mysql> create user ecmuser identified by 'ecmpass'
# mysql> create database ecm;
# mysql> grant usage on ecm.* to ecmuser@ecmclient identified by 'ecmpass';
# mysql> grant all privileges on ecm.* to ecmuser@ecmclient;
The user must have permission to create a database (if it does not already
exist), permission to create tables (if the table does not already exist),
and permission to modify tables.
Specify parameters in a configuration file config.txt:
[mysql]
mysql_out = true
mysql_host = localhost
mysql_user = ecmuser
mysql_passwd = ecmpass
The database and table will be created automatically, assuming that the user
has appropriate permissions.
To create the database and table explicitly, use the configure option:
btmon.py --mysql-config
Beware that the database will grow unbounded using this configuration. With
only basic data (volts, amps, watts) from 8 ECM-1240s, the mysql database is
about 450MB after 10 months of continuous operation.
If you do not want the database to grow, then do not create the 'id' primary
key, and make the serial the primary key without auto_increment. In that
case the database is used for data transfer, not data capture.
Sqlite Database Configuration:
Specify the filename in a configuration file config.txt:
[sqlite]
sqlite_out = true
sqlite_file = /var/btmon/ecm.db
The database and table will be created automatically.
To create the database and table explicitly, use the configure option:
btmon.py --sqlite-config
To create the database and table manually, do something like this:
sqlite3 /var/btmon/ecm.db
sqlite> create table ecm (id int primary key, time_created bigint, ...
With database schema 'counters' and GEM48PTBinary packets, the database will
grow by a bit less than 1K for each packet.
Round-Robin Database (RRD) Configuration:
Specify the location for RRD files in a configuration file config.txt:
[rrd]
rrd_out = true
rrd_dir = /var/btmon/rrd
RRD files are fixed size - there is no need to prune as more data are recorded.
The following parameters are used:
step - how often data will be recorded
heartbeat - how much time between samples before data are considered missing
consolidation - how samples should be combined over time
resolution - how many samples should be recorded
The step should be equal to the period at which data come from the device,
either the real-time period if the device is in real-time mode, or the polling
interval if the device is not.
The default settings result in one file per channel with the following:
4 days of 30 second samples
60 days of 5 minute averages
365 days of 30 minute averages
730 days of 1 hour averages
For a single GEM with 48 channels, 4 pulse counters, and 8 one-wire sensors,
this is a total of about 162M for 2 years of data. On an arm-based plug
computer reading/writing to a very slow usb drive, a single update takes about
45 seconds for 108 RRD files.
OpenEnergyMonitor Configuration:
1) register for an account
2) obtain the API key
Register for an account at the emoncms web site.
Obtain the API key with write access.
By default, all channels on all ECMs will be uploaded.
For example, this configuration will upload all data from all ECMs.
[openenergymonitor]
oem_out=true
oem_token=xxx
WattzOn Configuration:
1) register for an account
2) obtain an API key
3) configure devices that correspond to ECM channels
As of December 2011, it appears that WattzOn service is no longer available.
PlotWatt Configuration:
1) register for an account
2) obtain a house ID and an API key
3) configure meters that correspond to ECM channels
First register for a plotwatt account at www.plotwatt.com. You should receive
a house ID and an api key. Then configure 'meters' at the plotwatt web site
that correspond to channels on each ECM.
Using curl to create 2 meters looks something like this:
curl -d "number_of_new_meters=2" http://API_KEY:@plotwatt.com/api/v2/new_meters
Using curl to list existing meters looks something like this:
curl http://API_KEY:@plotwatt.com/api/v2/list_meters
Use the meter identifiers provided by plotwatt when uploading data, with each
meter associated with a channel/aux of an ECM. For example, to upload data
from ch1 and ch2 from ecm serial 399999 to meters 1000 and 1001, respectively,
use a configuration like this:
[plotwatt]
plotwatt_out=true
pw_house_id=XXXX
pw_api_key=XXXXXXXXXXXXXXXX
pw_map=399999_ch1,1000,399999_ch2,1001
EnerSave Configuration (deprecated as of 2014 - use Bidgley instead):
1) create an account
2) obtain a token
3) optionally indicate which channels to record and assign labels/types
Create an account at the enersave web site. Specify 'other' as the device
type, then enter ECM-1240.
To obtain the token, enter this URL in a web browser:
https://data.myenersave.com/fetcher/bind?mfg=Brultech&model=ECM-1240
Define labels for ECM channels as a comma-delimited list of tuples. Each
tuple contains an id, description, type. If no map is specified, data from
all channels will be uploaded, generic labels will be assigned, and the type
for each channel will default to net metering.
EnerSave defines the following types:
0 - load
1 - generation
2 - net metering (default)
10 - standalone load
11 - standalone generation
12 - standalone net
For example, via configuration file:
[enersave]
es_token=XXX
es_map=399999_ch1,kitchen,,399999_ch2,solar array,1,399999_aux1,,
Bidgely Configuration:
1) Choose "Get Started" at http://www.bidgely.com.
2) Select your zip code, etc.
3) Choose any monitor type during signup; "Brultech ECM-1240" is fine
4) Enter your email and password to create your accoun
5) Choose "Start Setup" then "Connect Energy Monitor"
6) Choose "I have a different Energy Monitor"
7) Choose "Bidgely API" from the list, and "Connect this monitor"
8) Choose "I have downloaded the API document"
9) Note your Upload URL and *SAVE IT* - you cant find it again
10) Add the upload URL to your config file by_url= parameter
11) Click "Connect to Bidgely" and start btmon.
Define labels for ECM channels as a comma-delimited list of tuples. Each
tuple contains an id, description, type. If no map is specified, data from
all channels will be uploaded, generic labels will be assigned, and the type
for each channel will default to "load."
Bidgely defines the following types:
0 - load (total consumption on site)
1 - generation (total generation on site)
2 - net metering (net consumption + generation for all circuits)
10 - standalone load (DFLT) (subset of total load, i.e. single circuit)
11 - standalone generation (subset of total generation, i.e. single circuit)
Note that types 0, 1, and 2 should each only be assigned to one circuit
in the map. Types 10 and 11 may be assigned to several circuits.
Although type 10 (individual circuit) is the default, you should always define
one map item with type 0, for total load, to make Bidgely happy.
For this reason, a map is required to use the Bidgely service, and it should
contain at least one channel of type 0 for total load.
For example, via configuration file:
[bidgely]
by_url=https://api.bidgely.com/v1/users/TOKEN/homes/1/gateways/1/upload
by_map=399999_ch1,mains,0,399999_ch2,solar array,1,399999_aux1,hot tub,10,
PeoplePower Configuration:
1) create an account
2) obtain an activation key
3) register a hub to obtain an authorization token for that hub
4) indicate which ECM channels should be recorded by configuring devices
associated with the hub
1) Find an iPhone or droid, run the PeoplePower app, register for an account.
2) When you register for an account, enter TED as the device type. An
activation key will be sent to the email account used during registration.
3) Use the activation key to obtain a device authorization token. Create an
XML file with the activation key, a 'hub ID', and a device type. One way to do
this is to treat the btmon script as the hub and each channel of each ECM
as a device. Use any number for the hub ID, and a device type 1004 (TED-5000).
For example, create the file req.xml with the following contents:
<request>
<hubActivation>
<activationKey>xxx:yyyyyyyyyyyyyyy</activationKey>
<hubId>1</hubId>
<deviceType>1004</deviceType>
</hubActivation>
</request>
Send the file using HTTP POST to the hub activation URL:
curl -X POST -d @req.xml http://esp.peoplepowerco.com/espapi/rest/hubActivation
You should get a response with resultCode 0 and a deviceAuthToken. The
response also contains pieces of the URL that you should use for subsequent
configuration. For example:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<response>
<resultCode>0</resultCode>
<host>esp.peoplepowerco.com</host>
<useSSL>true</useSSL>
<port>8443</port>
<uri>deviceio/ml</uri>
<deviceAuthToken>XXXXX</deviceAuthToken>
</response>
which results in this URL:
https://esp.peoplepowerco.com:8443/deviceio/ml
4) Add each channel of each ECM as a new ppco device. The btmon script
will configure the device definitions, but it requires a map of ECM channels
to device names. This map also indicates the channel(s) from which data
should be uploaded.
For example, via configuration file:
[peoplepower]
peoplepower_out=true
pp_url=https://esp.peoplepowerco.com:8443/deviceio/ml
pp_token=XXX
pp_hub_id=YYY
pp_map=399999_ch1,999c1,399999_aux2,999a2
Additional notes for PeoplePower:
Use the device type 1005, which is a generic TED MTU. Create an arbitrary
deviceId for each ECM channel that will be tracked. Apparently the deviceId
must contain hex characters, so use c1 and c2 for channels 1 and 2 and use aN
for the aux. The seq field is a monotonically increasing nonce.
<?xml version="1" encoding="UTF-8"?>
<h2s seq="1" hubId="1" ver="2">
<add deviceId="3XXXXXc1" deviceType="1005" />
<add deviceId="3XXXXXc2" deviceType="1005" />
<add deviceId="3XXXXXa1" deviceType="1005" />
<add deviceId="3XXXXXa2" deviceType="1005" />
<add deviceId="3XXXXXa3" deviceType="1005" />
</h2s>
Send the file to the URL received in the activation response.
curl -H "Content-Type: text/xml" -H "PPCAuthorization: esp token=TOKEN" -d @add.xml https://esp.peoplepowerco.com:8443/deviceio/ml
To get a list of devices that ppco recognizes:
curl https://esp.peoplepowerco.com/espapi/rest/deviceTypes
Eragy Configuration:
1) register power sensor at the eragy web site
2) obtain a token
3) create an account
The Eragy web site only knows about TED, Blueline, and eGauge devies. Register
as a TED5000 power sensor. Eragy will provide a URL and token. Use curl to
enter the registration for each ECM. Create a file req.xml with the request:
<ted5000Activation>
<Gateway>XXX</Gateway>
<Unique>TOKEN</Unique>
</ted5000Activation>
where XXX is an arbitrary gateway ID and TOKEN is the token issued by Eragy.
If you have only one ECM, use the ECM serial number as the gateway ID. If
you have multiple ECM, use one of the ECM serial numbers or just pick a number.
Send the request using curl:
curl -X POST -d @req.xml http://d.myeragy.com/energyremote.aspx
The server will respond with something like this:
<ted5000ActivationResponse>
<PostServer>d.myeragy.com</PostServer>
<UseSSL>false</UseSSL>
<PostPort>80</PostPort>
<PostURL>/energyremote.aspx</PostURL>
<SSLKey></SSLKey>
<AuthToken>TOKEN</AuthToken>
<PostRate>1</PostRate>
</ted5000ActivationResponse>
At the eragy web site, click the 'find my sensor' button. Eragy assumes that
the energy sensor will immediately start sending data to eragy, so start
running btmon.
On the eragy web site, continue and create an account. Eragy will email to
you an account password which you must enter to complete the account. Then
configure the account with a name, timezone, etc. and password.
The eragy configuration would be:
[eragy]
eragy_out=true
eg_token=TOKEN
eg_gateway_id=XXX
Smart Energy Groups Configuration:
1) create an account
2) create a site
3) obtain the site token
Create an account at the smart energy groups web site.
Create a site at the smart energy groups web site.
Obtain the site token at the smart energy groups web site.
Automatically create devices using the 'Discoveries' option in the SEG tools,
or manually create devices on the smart energy groups web site.
To use the discovery tool, start uploading data. Click the discovery tool,
then wait awhile as SEG detects the uploads. After a few minutes SEG will
list the devices and channels, then you can enter names for each channel.
The manual process is a bit more involved. Create one device per ECM/GEM.
For each device create streams - one power stream and one energy stream for
each channel. Define a node name for each device based on the following.
By default, data from all channels on all ECM/GEM will be uploaded. The node
name is the obfuscated serial number, for example XXX123 for the serial
number 355123. The stream name is p_* or e_* for each channel for power or
energy, respectively. For example, p_ch1, e_ch1, p_aux1, e_aux1
To upload only a portion of the data, or to use names other than the defaults,
specify a map via command line or configuration file. It is easiest to use the
default node names then add longer labels at the Smart Energy Groups web site.
For example, here is a configuration that uploads data only from ch1 and aux2
from ECM 399999, using stream names p_ch1, e_ch1, p_lighting, and e_lighting.
[smartenergygroups]
smartenergygroups_out=true
seg_token=XXX
seg_map=399999_ch1,,399999_aux2,lighting
ThingSpeak Configuration:
1) create an account
2) create one or more thingspeak channels
3) on each thingspeak channel, create a field for each ECM/GEM channel
Create an account at the ThingSpeak web site.
Create a ThingSpeak channel. Obtain the token (write api key) for each
channel.
Create a field for each ECM/GEM channel from which you will upload data.
Each thingspeak channel is limited to 8 fields.
By default, data from all channels on all ECM/GEM will be uploaded. The
channel ID and token must be specified for each ECM/GEM. By default, the
ECM/GEM channels will be uploaded to fields 1-8.
For example, this configuration will upload all data from ECM with serial
399999 to thingspeak channel with token 12345 and from ECM with serial
399998 to thingspeak channel with token 12348.
[thingspeak]
thingspeak_out=true
ts_tokens=399999,12345,399998,12348
This configuration will upload only ch1 from 399999 to field 3 and aux5 from
399998 to field 8:
[thingspeak]
thingspeak_out=true
ts_tokens=399999,12345,399998,12348
ts_fields=399999_ch1,3,399998_aux5,8
Xively/Pachube/COSM Configuration:
1) create an account
2) obtain API key
3) create a feed
Create an account at the Pachube web site.
Obtain the API key from the Pachube web site.
Create a feed at the Pachube web site, or using curl as described at pachube.
By default, data from every channel from every ECM will be uploaded to a single
pachube feed.
[pachube]
pachube_out=true
pbe_token=XXXXXX
pbe_feed=3000
Wattvision Configuration:
1) create an account
2) obtain API ID, API Key, and Sensor ID
Create account by linking to a google account.
Create a House at the wattvision web site.
Skip the sensor and pairing.
Get the API ID, API Key, and Sensor ID from the API Information section of
Settings.
Wattvision records only a single value - it is designed only for whole-house
monitoring. So you must specify which channel is the total energy/power
reading.
[wattvision]
wattvision_out=true
wv_api_id = XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
wv_api_key = XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
wv_sensor_id = XXXXXXXX
wv_channel = 399999_ch1
PVOutput Configuration:
1) create an account
2) obtain API Key and System ID
Create an account at the PVOutput web site.
Create a system at the PVOutput web site.
In the Settings panel, obtain the API Key and System Id.
PVOutput expects the following information for each system:
- generated power/energy
- consumed power/energy
- temperature
- voltage
You must identify which channel monitors the total generated energy/power, and
which channel monitors the total consumed energy/power. If the device is a GEM
you can identify one of the temperature sensors as the temperature to upload.
The generation and consumption channels can be identified by channel, e.g. ch1,
or by serial_channel pair, e.g. 399999_ch1. The latter is useful when
collecting data from multiple ECM/GEM devices.
[pvo]
pvo_out = true
pvo_api_key = XXXXX
pvo_system_id = XXXXX
pvo_generation_channel = 399999_ch1
pvo_consumption_channel = 399999_ch2
pvo_temperature_channel = 399999_t1
Upgrading:
Please consider the following when upgrading from ecmread.py:
* the database collectors have changed completely, so it is no longer possible
to use a database collector with the ecmread or ecmreadext schemas. only the
counters schema contains enough information to use database as collector.
* the -d option has been replaced by --mysql or --sqlite
* the db_* directives in the configuration file are now specific to the type
of database. for example, db_passwd is now mysql_passwd or sqlite_passwd.
* the default database schema is called 'counters' - it stores the values from
the counters, rather than derived values. the basic ecm1240 and extended
ecm1240 schemas are still implemented, but are useful only for storage, not
for collection.
* the default name for the database table is derived from the packet format
and the schema type.
* the packet format must be specified, either at the command line or in the
configuration file.
* uploads to people power and eragy are now correct - this means they will be
off by a factor of 1000. ecmread 2.4.4 and earlier uploaded kilowatt-hours
when it should have uploaded watt-hours.
Changelog:
- 3.1.0 07feb15 mwall
* punt old pachube/cosm url, use xively now
* ensure poll_interval is integer
* fix enersave uploader (thanks to Eric Sandeen)
* fix order of sqlite args
* miscellaneous sqlite and mysql fixes (thanks to Eric Sandeen and Marc Lennox)
* added node option for compatibility with emoncms 8.4.x
* updated support for wattvision api v0.2 (thanks to Eric Sandeen)
* added support for bidgley api v1.0.1 (thanks to Eric Sandeen)
- 3.0.7 01feb14 mwall
* use localtime for pvoutput uploads (thanks to Eric Sandeen)
* better handling of failures when connecting via socket (thanks to Ken Overly)
- 3.0.6 22jan12 mwall
* added retries for regular reads, not just polling reads
* do empty read check on each read - windows tcp/ip stack differs from linux!
* added temperature calculation to match gem firmware later than 1.61
- 3.0.5 26dec12 mwall
* fix bug in delta wh calculation when polarity is reversed
* spew less into logs when thingspeak uploads fail
- 3.0.4 26dec12 mwall
* upload both energy and power number to oem
* added reverse-polarity option
* added copyright/licensing details
* added pvoutput.org
- 3.0.3 03dec12 mwall
* revert the rrd changes. we will make the changes soon, but no need to
disrupt the brultech installations for now. testing is progressing on the
radio thermostat and eds one-wire monitoring systems, and once that is
sorted we will make the rrd changes on btmon.
- 3.0.2 03dec12 mwall
* upload pulse and sensor data to oem, seg, and pachube
* improve reporting of read errors when in polling mode
* include timestamp on thingspeak uploads
* change default rrd values to assume 10s sampling
* use 'data' as the data source name for all rrd files
* punt max/min consolidates in rrd until we sort out the graphing issues
- 3.0.1 04nov12 mwall
* force period and timeout to be int
* adjustments to default values for service upload periods
* added support for wattvision
* added 0.5 multiplier for one-wire bus (only for DS18B20?)
* added command-line and config file options for poll intervals
* added command-line and config file options for update/insert periods
* do bulk uploading for pachube/cosm
* fix off-by-one bug in thingspeak default field indexing
* do bulk uploading for seg
- 3.0.0 02oct12 mwall
* initial release, based on ecmread 2.4.5
* support for rrdtool
* refactored database support
* improved packet buffering and handling
* polling or blocking modes for serial and socket-client
* support gem, ecm1240, ecm1220
* support multiple packet types
* automatic configuration of database for mysql and sqlite
* support for multiplexed devices in polling mode
"""
__author__ = 'mwall'
__app__ = 'btmon'
# memory use
#
# The use of fixed buffer should prevent this program from growing. On a slow
# arm-based plug computer running debian6 we see the following memory use:
# VSZ RSS
# btmon 22128 8100 - startup, collecting from 4 ECM-1240 via serial
# btmon 29036 15068 - full buffer of 600, collecting from 4 ECM-1240
# btmon 49996 36184 - full buffer of 600, collecting from 1 GEM
# btmon 28200 14368 - full buffer of 120, collecting from 1 GEM
# ecmread 14540 6800 - startup, collecting from 4 ECM-1240 via serial
# ecmread 23908 8328 - collecting from 4 ECM-1240, after multiple hours
# ecmread 24412 9272 - uploading to multiple services
#
# processing of data
#
# Be sure to get the combination of buffer size, sampling time, and upload
# period correct. Packet processing happens after each read. So if the device
# is set to emit packets every 5 seconds, then processing will happen every 5
# seconds. If processing takes more than 5 seconds, one or more reads may be
# missed (depending on lower-level buffering). Note that the opportunity to
# process happens after each read, but actual processing does not always happen
# after each read. Some processors will process after each each read, others
# wait for data to collect before processing it.
#
# Ensure that no processor will take too long. If a processor takes longer
# than a sampling period, data from the next sample will probably be lost. If
# a processor waits longer than the sampling period times the buffer size, then
# some samples will not be uploaded.
#
# For example, with an ECM that emits data every 10 seconds and a mysql
# processor that saves to a database on the localhost every 60 seconds,
# the buffer size must be at least 6. Setting it to 12 or 18 accommodates
# periodic timeouts to the database.
#
# If network speeds are slow and/or hosted services are slow or unreliable,
# run a second instance of this program. Run one instance to collect data,
# and a second instance to upload data.
#
# The default values assume a sampling interval of 10 seconds.
#
# serial numbers
#
# For the green-eye, the serial number is 8 characters long - a 5 character
# serial plus a 3 character unit id.
#
# For the ecm-1240, the serial number is 6 characters long - a 5 character
# serial plus a 1 character unit id.
#
# However, the GEM unit id may be more than one character, so serials that
# a GEM generates in ECM packets may have to be longer than 6 characters.
#
# packets
#
# There are three kinds of packets: raw, compiled, and calculated.
# Raw packets are what we get from the device. They may be binary,
# they may be ascii, they may ECM-1240 format, they may be GEM format,
# or they may be any of many other formats.
#
# Compiled packets have been augmented with labels such as 'ch1_aws'. The
# labels are associated with the raw data but no calculations have been done.
# Compiling a packet requires only a raw packet.
#
# Calculated packets contain labels with derivative values such as 'ch1_w'.
# Calculating a packet requires two compiled packets, since many of the
# calculated values are differences.
#
# The GEM binary packet has 48 channels. Since only 32 of them are currently
# used (oct2012), we use only 32 of them in order to minimize memory and
# storage.
#
# calculation of watts and watt-hours
#
# The brultech devices record only a cumulative measure - the total number of
# watt-seconds, which is a measure of energy. From this there are two measures
# typically desired - average power use (e.g. in Watts), and cumulative energy
# use (e.g. in Kilowatt-Hours).
#
# Most services accept average measures of power and treat it as an
# instantaneous power level. It is, in fact, the energy use over a period
# of time divided by the period of time. The more often a device is sampled,
# the more accurate the power readings will be; sampling infrequently will miss
# spikes of energy use, but will not miss total energy use.
#
# Some services require a cumulative measure of energy. Others require a
# differential measure of energy - how much energy consumed since the last
# reading. This can be problematic when uploads fail, power goes out, or
# other situations arise where data cannot be uploaded. The cumulative
# reading is less error-prone in these situations.
#
# This implementation calculates power and energy as follows:
#
# seconds = sec_counter1 - sec_counter0
# w1 = (abs_ws1 - abs_ws0) / seconds if pw == 0 multiply by -1
# pos_w1 = (pol_ws1 - pol_ws0) / seconds
# neg_w1 = w - pw
# pos_wh1 = pol_ws1 / 3600
# neg_wh1 = (abs_ws1 - pol_ws1) / 3600
# wh1 = pos_wh1 - neg_wh1 same as (2*pws1 - aws1) / 3600
# delta_wh1 = wh1 - wh0
#
# database schemas
#
# The Configurator classes will automatically create a database and table
# with the appropriate schema. Database/table creation should happen
# automatically the first time the application is run, but the configuration
# can also be run explicitly.
# TODO: use 'data' as name for every source in the rra to facilitate graphing
# TODO: make reverse polarity the default so we match brultech convention
# TODO: adjust processing logic to retry packets if upload failed
# TODO: support both GEM and ECM on same serial or tcp/ip socket
# TODO: parameterize sample period to automatically set buffer size and step
# TODO: implement rrd as data source
# TODO: figure out how to deal robustly with counter resets
# TODO: check size of post/put/get and ensure size is not too big
# TODO: bulk uploads for openenergymonitory, thinkspeak if possible
# TODO: use row-per-sensor database schema (more future-proof)
MINUTE = 60
SpH = 3600.0
# if set to 1, print out what would be uploaded but do not do the upload.
SKIP_UPLOAD = 0
# if set to 1, trust the device's clock
TRUST_DEVICE_CLOCK = 0
# if set to 1, obfuscate any serial number before uploading
OBFUSCATE_SERIALS = 1
# brultech assumes that positive polarized watt-seconds means negative energy,
# resulting in this calculation for watt-seconds:
# ws = aws - 2*pws
# btmon assumes that positive polarized watt-seconds means positive energy,
# resulting in this calculation for watt-seconds:
# ws = 2*pws - aws
# when reverse polarity is specified, the sign is inverted for each channel
# that has a polarized watt-second counter so that the power and energy values
# match those of brultech software.
REVERSE_POLARITY = 0
# number of retries to attempt when reading device, 0 means retry forever
READ_RETRIES = 0
# how long to wait after a failure before attempting to read again, in seconds
RETRY_WAIT = 60
# number of retries to attempt when polling device
POLL_RETRIES = 3
# size of the rolling buffer into which data are cached
# should be at least max(upload_period) / sample_period
# a sample period of 10s and max upload period of 15m (900s), with contingency
# of 5m (300s) server/network downtime yields a buffer of 120
DEFAULT_BUFFER_SIZE = 120
# how long to wait before considering an upload to have failed, in seconds
DEFAULT_UPLOAD_TIMEOUT = 15
# how often to upload data, in seconds
# this may be overridden by specific services
DEFAULT_UPLOAD_PERIOD = 15 * MINUTE
# device types
DEV_ECM1220 = 'ecm1220'
DEV_ECM1240 = 'ecm1240'
DEV_GEM = 'gem'
DEVICE_TYPES = [DEV_ECM1220, DEV_ECM1240, DEV_GEM]
DEFAULT_DEVICE_TYPE = DEV_ECM1240
# packet formats
PF_ECM1220BIN = 'ecm1220bin' # ECM-1220 binary
PF_ECM1240BIN = 'ecm1240bin' # ECM-1240 binary
PF_GEM48PTBIN = 'gem48ptbin' # GEM 48-channel binary with polarity, timestamp
PF_GEM48PBIN = 'gem48pbin' # GEM 48-channel binary with polarity
PACKET_FORMATS = [PF_ECM1220BIN, PF_ECM1240BIN, PF_GEM48PTBIN, PF_GEM48PBIN]
# the database schema
DB_SCHEMA_COUNTERS = 'counters' # just the counters and sensor readings
DB_SCHEMA_ECMREAD = 'ecmread' # basic format used by ecmread
DB_SCHEMA_ECMREADEXT = 'ecmreadext' # extended format used by ecmread
DB_SCHEMAS = [DB_SCHEMA_COUNTERS, DB_SCHEMA_ECMREAD, DB_SCHEMA_ECMREADEXT]
DEFAULT_DB_SCHEMA = DB_SCHEMA_COUNTERS
# channel filters
FILTER_PE_LABELS = 'pelabels'
FILTER_POWER = 'power'
FILTER_ENERGY = 'energy'
FILTER_PULSE = 'pulse'
FILTER_SENSOR = 'sensor'
FILTER_DB_SCHEMA_COUNTERS = DB_SCHEMA_COUNTERS
FILTER_DB_SCHEMA_ECMREAD = DB_SCHEMA_ECMREAD
FILTER_DB_SCHEMA_ECMREADEXT = DB_SCHEMA_ECMREADEXT
# serial settings
# the serial port to which device is connected e.g. COM4, /dev/ttyS01
SERIAL_PORT = '/dev/ttyUSB0'
SERIAL_BAUD = 19200
SERIAL_BUFFER_SIZE = 2048
# ethernet settings
# the etherbee defaults to pushing data to port 8083
# the wiz110rs defaults to listening on port 5000
IP_SERVER_HOST = '' # bind to default
IP_SERVER_PORT = 8083
IP_CLIENT_PORT = 5000
IP_CLIENT_TIMEOUT = 60
IP_DEFAULT_MODE = 'server'
IP_BUFFER_SIZE = 2048
# database defaults
DB_HOST = 'localhost'
DB_USER = 'ecmuser'
DB_PASSWD = 'ecmpass'
DB_DATABASE = 'ecm'
DB_FILENAME = 'ecm.db' # filename for sqlite databases
DB_INSERT_PERIOD = MINUTE # how often to record to database, in seconds
DB_POLL_INTERVAL = 60 # how often to poll the database, in seconds
# rrd defaults
RRD_DIR = 'rrd' # directory in which to put the rrd files
RRD_STEP = 10 # how often we get samples from the device, in seconds
RRD_HEARTBEAT = 2 * RRD_STEP # typically twice the step, in seconds
# 10s, 5m, 30m, 1h
# 4d at 10s, 60d at 5m, 365d at 30m, 730d at 1h
# 2087836 bytes per rrd file - about 90MB for a gem or 20MB for an ecm1240
RRD_STEPS = [1, 18, 180, 360]
RRD_RESOLUTIONS = [34560, 17280, 17520, 17520]
# 10s, 1m, 10m, 20m
# 32h at 10s, 12d at 1m, 121.6d at 10m, 243.3d at 20m
# 30s, 5m, 30m, 1h
# 4d at 30s, 60d at 5m, 365d at 30m, 730d at 1h
# 1534876 bytes per rrd file - about 75MB for a gem or 15MB for an ecm1240
#RRD_STEPS = [1,6,60,120]
#RRD_RESOLUTIONS = [11520, 17280, 17520, 17520]
RRD_UPDATE_PERIOD = 60 # how often to update the rrd files, in seconds
RRD_POLL_INTERVAL = 120 # how often to poll when rrd is source, in seconds
# WattzOn defaults
# the map is a comma-delimited list of channel,meter pairs. for example:
# 311111_ch1,living room,311112_ch1,parlor,311112_aux4,kitchen
WATTZON_API_URL = 'http://www.wattzon.com/api/2009-01-27/3'
WATTZON_UPLOAD_PERIOD = 5 * MINUTE
WATTZON_TIMEOUT = 15 # seconds
WATTZON_MAP = ''
WATTZON_API_KEY = 'apw6v977dl204wrcojdoyyykr'
WATTZON_USER = ''
WATTZON_PASS = ''
# PlotWatt defaults
# https://plotwatt.com/docs/api
# Recommended upload period is one minute to a few minutes. Recommended
# sampling as often as possible, no faster than once per second.
# the map is a comma-delimited list of channel,meter pairs. for example:
# 311111_ch1,1234,311112_ch1,1235,311112_aux4,1236
PLOTWATT_BASE_URL = 'http://plotwatt.com'
PLOTWATT_UPLOAD_URL = '/api/v2/push_readings'
PLOTWATT_UPLOAD_PERIOD = MINUTE