Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Smoke detector + send email
#1
At my work I am trying to make a smoke detector with a raspberry pi that will send a email to whom ever I nominate if there is a fire. I already have the 2 scrips made for each of the tasks I want it to do, but im having trouble with putting them together.

Here are the 2 scripts.

Smoke detector:
import time
import board
import busio
from adafruit_ads1x15.single_ended import ADS1115
 
# Create the I2C bus
i2c = busio.I2C(board.SCL, board.SDA)
 
# Create the ADC object using the I2C bus
adc = ADS1115(i2c)
 
# Print header
print("    CHAN 0          CHAN 1          CHAN 2          CHAN 3")
print("{:>5}\t{:>5}\t{:>5}\t{:>5}\t{:>5}\t{:>5}\t{:>5}\t{:>5}"
      .format('raw', 'v', 'raw', 'v', 'raw', 'v', 'raw', 'v'))
 
while True:
    # Get raw readings for each channel
    r0 = adc[0].value
    r1 = adc[1].value
    r2 = adc[2].value
    r3 = adc[3].value
 
    # Get voltage readings for each channel
    v0 = adc[0].volts
    v1 = adc[1].volts
    v2 = adc[2].volts
    v3 = adc[3].volts
 
    # Print results
    print("{:>5}\t{:>5.3f}\t{:>5}\t{:>5.3f}\t{:>5}\t{:>5.3f}\t{:>5}\t{:>5.3f}"
          .format(r0, v0, r1, v1, r2, v2, r3, v3))
 
    # Sleep for a bit
    time.sleep(0.5)  
Email :
import smtplib
server = smtplib.SMTP('smtp.gmail.com', 587)
server.starttls()
#Next, log in to the server
server.login("[email protected]", "password")

#Send the mail
msg = "Message" # The /n separates the message from the headers
server.sendmail("[email protected]", "[email protected]", msg)
Reply
#2
What do you mean having trouble putting the two scripts together? The simplest approach would be to put the email code inside the smoke detector code and just run a function when whatever is defined as a fire trigger, send the email. If you have to keep them separate, you could just import the email module whenever the trigger is confirmed. The more pythonic approach of the latter would be to make a function in the email module to actually send the mail, and then just execute that modules function when the fire is trigger (whatever those values might be). You could do it lots of ways.
Recommended Tutorials:
Reply
#3
(Sep-11-2018, 12:06 AM)metulburr Wrote: What do you mean having trouble putting the two scripts together? The simplest approach would be to put the email code inside the smoke detector code and just run a function when whatever is defined as a fire trigger, send the email. If you have to keep them separate, you could just import the email module whenever the trigger is confirmed. The more pythonic approach of the latter would be to make a function in the email module to actually send the mail, and then just execute that modules function when the fire is trigger (whatever those values might be). You could do it lots of ways.

Thanks for the reply.

Im only very new to using python so im not sure how to do something like this. I was talking with a work college about using if and else statements and he said that could work but again im not really sure on how to put that in.
Reply
#4
trigger = 'whatever triggers a fire code'
if trigger:
    server.sendmail(...)
Recommended Tutorials:
Reply
#5
(Sep-12-2018, 01:28 AM)metulburr Wrote:
 trigger = 'whatever triggers a fire code' if trigger: server.sendmail(...) 
Thanks I will give it a try.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Prime number detector Mark17 5 818 Nov-27-2023, 12:53 PM
Last Post: deanhystad
  Send email with smtp without using Mimetext mgallotti 0 718 Feb-01-2023, 04:43 AM
Last Post: mgallotti
  email Library: properly send message as quoted-printable malonn 3 1,345 Nov-14-2022, 09:31 PM
Last Post: malonn
  Unable to send email attachments cosmarchy 7 2,592 Mar-09-2022, 09:29 PM
Last Post: bowlofred
  How to make scraper send email notification just once themech25 0 1,392 Nov-08-2021, 01:51 PM
Last Post: themech25
  send email smtp rwahdan 0 1,802 Jun-19-2021, 01:28 AM
Last Post: rwahdan
  Face detector project? korenron 2 2,122 Mar-24-2021, 03:43 PM
Last Post: korenron
  Need Outlook send email code using python srikanthpython 3 8,278 Feb-28-2021, 01:53 PM
Last Post: asyswow64
  qrcode detector not in cv2 Pedroski55 2 5,155 Sep-16-2020, 03:22 AM
Last Post: Pedroski55
  How to send email using python? Gigux 2 2,872 Jul-04-2020, 07:53 AM
Last Post: Gigux

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020