| #!/usr/bin/env python | |
| from RPi_AS3935 import RPi_AS3935 | |
| import RPi.GPIO as GPIO | |
| import time | |
| from datetime import datetime | |
| GPIO.setmode(GPIO.BCM) | |
| # Rev. 1 Raspberry Pis should leave bus set at 0, while rev. 2 Pis should set | |
| # bus equal to 1. The address should be changed to match the address of the | |
| # sensor. (Common implementations are in README.md) | |
| sensor = RPi_AS3935(address=0x00, bus=0) | |
| sensor.calibrate(tun_cap=0x0F) | |
| sensor.set_indoors(True) | |
| sensor.set_noise_floor(0) | |
| def handle_interrupt(channel): | |
| time.sleep(0.003) | |
| global sensor | |
| reason = sensor.get_interrupt() | |
| if reason == 0x01: | |
| print "Noise level too high - adjusting" | |
| sensor.raise_noise_floor() | |
| elif reason == 0x04: | |
| print "Disturber detected - masking" | |
| sensor.set_mask_disturber(True) | |
| elif reason == 0x08: | |
| now = datetime.now().strftime('%H:%M:%S - %Y/%m/%d') | |
| distance = sensor.get_distance() | |
| print "We sensed lightning!" | |
| print "It was " + str(distance) + "km away. (%s)" % now | |
| print "" | |
| pin = 17 | |
| GPIO.setup(pin, GPIO.IN) | |
| GPIO.add_event_detect(pin, GPIO.RISING, callback=handle_interrupt) | |
| print "Waiting for lightning - or at least something that looks like it" | |
| while True: | |
| time.sleep(1.0) |
The demo script (below) is printing the results to the screen. I would of course like to "reroute" this output into weewx and show it on exfoliation. I searched the internet for an adaptable python script to accomplish that goal, but failed. My own python knowledge is close to zero.Could you please help me to integrate the sensor output into weewex with exfoliation?
...
print "It was " + str(<span class="n" style="box-sizing:
Hi Matt,I want to start working on the weewx service now for the lightning module. Since weewx 3.0 was just released and also installed on my system, I'm wondering whether I should I still work from your recommended snow depth template, or is there another more current file I need to use?
This sounds like fun! The sensor is quite inexpensive, so I might want to try this. Do you have the sensor indoors or out? The spec sheet says it will work indoors: this would be a great advantage to me.
Here is my attempt to this. What do you think?
Do I also need to amend the the squlite data base? That has not worked so far (I followed the instructions in the user guide / customization guide).
Here is the log that shows weewx crashing with the new lightning script :-(
Hi Matt,
I edited weewx.conf and replaced the hex numbers. It still crashes...
replace this:
def handle_interrupt(channel):
with this:
def handle_interrupt(channel):
be sure that you put all of this in a file called lightning.py, since that is the name used in the service list:data_services = user.lightning.Lightning
m
...
Any chance of making the working files available with a guide to help a simple guy like me get it going?
...
Thank your for the quick reply.
After a rush of blood, I ordered the MOD1016 annd then became worried that my better half might bury my remains under the patio for wasting money.
Hi Matt,
I tried the new script and this error:
Jun 18 15:30:12 raspberrypi weewx[2500]: as3935: detected disturber - masking
Jun 18 15:30:12 raspberrypi weewx[2500]: as3935: callback failed: global name 's ensor' is not defined
Hi Matt,
AS3935 sends data to twitter now.
However, there is a datatype mismatch in syslog showing. I guess since there is no group for lightning strikes yet, it may have to be created (by me)?
I edited as3935.py accordingly. Lightning reporting on twitter and storing to the database works now.
Adding these two lines to extensions.py, does not, so I removed them.
eewx.units.obs_group_dict['lightning_strikes'] = 'group_count'
weewx.units.obs_group_dict['avg_distance'] = 'group_distance'
First: many thanks for this piece of work, since i own an AS3935 since two months now, and only got it to work writing the data into a simple textfile on a RPi.
Living in the south of Germany near to the Alps, we have lots of lightning events during June and July.
Thanks to your code i think, i will be able to integrate it into weewx.
I will give Feedback, as soon as i tried it.
With best regards,
Erwin
1. The driver creates and writes to the lightning database and records the distance variable. I assume your approach was recording date and time of each strike and then have a a skin template do the calculation (i.e. strikes over time) in a graph. In other words: each distance reading is one strike and displaying the distance over time equals strikes over time.
2. Amending extensions with these lines still causes the system to fail. Tweitter and WeatherCloud "complain" about existing keys and groups, although none of them are present in my user.py file.
import weewx.units
weewx.units.obs_group_dict['lightning_strikes'] = 'group_count'
weewx.units.obs_group_dict['avg_distance'] = 'group_distance'
lightning_strikes and avg_distance
to each archive record. To save these in the weewx database (so that
they can be used in reports and plots), extend the database schema as
explained in the weewx customization guide. You must add two columns, lightning_strikes and avg_distance."[AS3935] data_binding = lightning_sqlite")is done in weewx.conf?
Thanks, Steve
Hello: I just received my AS3935 and am going to give it a go. A few newbie questions:
1. In the Wiki instructions, it states: "The default configuration will add the fieldslightning_strikesandavg_distanceto each archive record. To save these in the weewx database (so that they can be used in reports and plots), extend the database schema as explained in the weewx customization guide. You must add two columns,lightning_strikesandavg_distance."
Is this done by editing /bin/schemas/wview.py ?
2. The data binding ("data_binding - Specify a data binding to save lightning data to a separate lightning database. For example,[AS3935] data_binding = lightning_sqlite")is done in weewx.conf?
1. I don't have the AS3935 hooked to the Pi yet, so I assume that would throw off errors?
2. As per your instructions, I now have customschema.py (which is a copy of wview.py) under /user
I edited customschema.py by adding the lines for lightning_strikes and avg_distance. By doing that, will it add the columns of the same names to (a newly generated) weewx.sdb? If that is the case,
do I then NOT add: [AS3935]
data_binding = lightning_sqlite) and furthur references to binding?
Jul 22 16:44:22 PWS weewx[2206]: **** File "/usr/share/weewx/weewx/engine.py", line 75, in __init__Jul 22 16:44:22 PWS weewx[2206]: **** self.loadServices(config_dict)Jul 22 16:44:22 PWS weewx[2206]: **** File "/usr/share/weewx/weewx/engine.py", line 136, in loadServicesJul 22 16:44:22 PWS weewx[2206]: **** self.service_obj.append(weeutil.weeutil._get_object(svc)(self, config_dict))Jul 22 16:44:22 PWS weewx[2206]: **** File "/usr/share/weewx/weeutil/weeutil.py", line 944, in _get_objectJul 22 16:44:22 PWS weewx[2206]: **** mod = __import__(module)Jul 22 16:44:22 PWS weewx[2206]: **** File "/usr/share/weewx/user/as3935.py", line 52, in <module>Jul 22 16:44:22 PWS weewx[2206]: **** from RPi_AS3935 import RPi_AS3935Jul 22 16:44:22 PWS weewx[2206]: **** ImportError: No module named RPi_AS3935Jul 22 16:44:22 PWS weewx[2206]: **** Exiting.
4. However, after running weewx with the AS3935 this event keeps crashing weewx:Jul 21 20:34:13 raspi weewx[16186]: engine: Caught unrecoverable exception in engine:Jul 21 20:34:13 raspi weewx[16186]: **** Conflicting edge detection already enabled for this GPIO channel
if I unplug the pi and boot the system from scratch it does run for a while (hours, sometimes days). Then all of a sudden this GPIO problem occurs and weewx crashes. I believe it is related to sensing the interrupt on the GPIO. I wonder if any other linux process may access this GPIO, but afaik it is a freely assignable one?!
Hi,...I purchased and installed the MOD1016 lightning sensor module from embedded adventures (http://www.embeddedadventures.com/datasheets/MOD-1016_hw_v4_doc_v2.pdf).The module is based on the AS3935, a programmable fully integrated Lightning Sensor IC that detects the presence and approach of potentially hazardous lightning activity in the vicinity and provides an estimation on the distance to the head of the storm. The embedded lightning algorithm checks the incoming signal pattern to reject the potential man-made disturbers (http://media.digikey.com/pdf/Data%20Sheets/Austriamicrosystems%20PDFs/AS3935.pdf).I hooked the board up to my Raspberry Pi B+ through I2C. My Raspberry is generally running headless, i.e. without a monitor or keyboard, except for maintenance. Phil Fenstermacher published a python library (https://github.com/pcfens/RaspberryPi-AS3935), which I used for the installation. The demo.py script is now running and actually detecting lighning (which I verified with www.lightningmaps.org).The installation files are located in /home/pi/RaspberryPi-AS3935/
The demo script (below) is printing the results to the screen. I would of course like to "reroute" this output into weewx and show it on exfoliation. I searched the internet for an adaptable python script to accomplish that goal, but failed. My own python knowledge is close to zero.Could you please help me to integrate the sensor output into weewex with exfoliation?Minimal goal:Create an "automatic start script" that loads demo.py at the raspberry startup automatically (like weewx). Print the output into a file (txt or html) located in the the exfoliation folder containing all FTP upload data, so it's automatically uploaded with all the orher exfoliation files.Maximum goal:True integration into weewx and exfoliation. Use the distance coding (0 - 40 km) to create "perimeter" circles on a Google map within exfoliation, load a "red alam banner" to display within exfoliation and have speex exclaim the detected ligthning and distance on the homepage of the exfoliation skin.I'm sorry to bother all of you with this probably very basic stuff, but lightning detection is really exciting :-)Thanks,WH3080---This is the current demo.py code from Phil Fenstermacher:
#!/usr/bin/env python from RPi_AS3935 import RPi_AS3935 import RPi.GPIO as GPIO import time from datetime import datetime GPIO.setmode(GPIO.BCM) # Rev. 1 Raspberry Pis should leave bus set at 0, while rev. 2 Pis should set # bus equal to 1. The address should be changed to match the address of the # sensor. (Common implementations are in README.md) sensor = RPi_AS3935(address=0x00, bus=0) sensor.calibrate(tun_cap=0x0F) sensor.set_indoors(True) sensor.set_noise_floor(0) def handle_interrupt(channel): time.sleep(0.003) global sensor reason = sensor.get_interrupt() if reason == 0x01: print "Noise level too high - adjusting" sensor.raise_noise_floor() elif reason == 0x04: print "Disturber detected - masking" sensor.set_mask_disturber(True) elif reason == 0x08: now = datetime.now().strftime('%H:%M:%S - %Y/%m/%d') distance = sensor.get_distance() print "We sensed lightning!" print "It was " + str(
Jul 26 17:42:17 PWS weewx[2221]: as3935: noise level too high - adjusting
lightning_strikes and avg_distance to my schema and they are now part of weewx.sdb.Regards
Robin
Hi Matt.
my system crashed again early this morning. It has been inactive for 8 hours now. Please find attached the full log. It looks like it attempted to reboot itself and in this process the GPIO error message shows up. This confirms your assumption that this problem ist related to the boot / restart process. However, in this scenario I did not boot or restart the system myself.
What other advise could you give me / us from the syslog? As I wrote earlier, this was a complete reinstall dediacted to WeeWX only.
The line (taken from the notes in the .py file) that says calibration = 6; does that refer to the value of the tuning capacitor?
If so, I would assume I would change it to the value assigned to my particular sensor by Imbedded Adventures which is 3 in my case.
Would this be done by setting Indoors = False or do some adjustments have to be made in AS_3935.py?
I2C requires the use of pull-up resistors. The board comes with the pull-up resistors enabled. If you are connecting to an existing I2C buss that already has pull-up resistors, or you are using internal pull-ups in your microcontroller, you can disable the pull-up resistors by unsoldering the resistors R1 and R2 (the two 10K resistors nearest the MISO connection).
Robin
I too faced this delemma, but ended up (with the Imbedded Adventures board ) NOT unsoldering the resistors. When I get back home next week, I can check how the board functioned during several thunderstorms.
Steve
sensor =
RPi_AS3935(address=0x03, bus=1)
sensor.set_indoors(False)
sensor.set_noise_floor(2) It was 0, but does increasing it increase or decrease sensitivity??
sensor.calibrate(tun_cap=0x03)
Presently, I am not sure the sensor is working.
Steve
[AS3935]
address = 3
bus = 1
noise_floor = 0
calibration = 2
indoors = False
pin = 17
data_binding =
lightning_binding
[DataBindings]
[[lightning_binding]]
database = lightning_sqlite
[Databases]
[[lightning_sqlite]]
root = /home/weewx/archive
database_name = lightning.sdb
driver = weedb.sqlite
[Engine]
[[Services]]
data_services = user.as3935.AS3935
When I view the data under lightning.sdb, there are only columns for dateTime, usUnits, and distance; there are no columns for interval or lightning_strikes. There is no data under any of the columns.
Do I need a separate schema entry under [[lightning_binding]] something like this?
schema = [('dateTime', 'INTEGER NOT NULL UNIQUE PRIMARY KEY),
('usUnits', 'INTEGER
NOT NULL'),
('interval', 'INTEGER NOT NULL'),
('lightning_strikes', 'REAL'),
('avg_distance', 'REAL'),]
Thanks, Steve
# Options for extension 'as3935'
[AS3935]
bus = 1
address = 3
calibration = 4
noise_floor = 0
indoors = False
pin = 17