Kway
Published

Liquid Leak Alarm with Python

This item helps users solve liquid leakage problems.Once the probe senses a liquid leak, it will send an email to your email through Python.

BeginnerWork in progress173
Liquid Leak Alarm with Python

Things used in this project

Hardware components

SenseCAP S2100 LoRaWAN Data Logger
Seeed Studio SenseCAP S2100 LoRaWAN Data Logger
×1
Seeed Studio Water Leak Detector
×1
SenseCAP M1 LoRaWAN Indoor Gateway - EU868
Seeed Studio SenseCAP M1 LoRaWAN Indoor Gateway - EU868
×1

Software apps and online services

SenseCraft Mate App
Seeed Studio SenseCraft Mate App
SenseCAP Portal
Seeed Studio SenseCAP Portal

Hand tools and fabrication machines

Multitool, Screwdriver
Multitool, Screwdriver

Story

Read more

Code

water leak alarm.py

Python
import requests
import json
import smtplib                 # SMTP
from email.mime.text import MIMEText   # 
from email.header import Header
import datetime                # 
import schedule

def run():
    url = "https://sensecap.seeed.cc/openapi/view_latest_telemetry_data?device_eui=2CF7F1C043400087&measurement_id=4165&channel_index=1"
    headers = {'Authorization': 'Basic U1RLTU9SWEFHR1RKMVdGTjozQTJDRjZBQUJBNTA0RjM0QjMzQTE5NUQxOEM2N0YyNjJFMTczMzNGRkQ2NTRBMjI4MDkwMjQzQTQ4QjU0RjQ2'}
    r = requests.get(url, headers=headers)
    Value = json.loads(r.content)
    print(r.status_code)
    print(Value)
    print(r)
    Signal = Value.get('data')[0].get('points')[0].get('measurement_value') #list
    print(Signal)
    if Signal > 0:
        time = datetime.datetime.now()
        with open('alerttime.csv', 'a') as f:   # /
            f.write(str(time))                  # 
            f.write('\n')
def sendmail():
    smtpserver = 'smtp.qq.com'
    username = '826696169@qq.com'
    password = 'xawnqxttgznxbdjf'               # smtp
    sender = '826696169@qq.com'
    receiver = 'kewei.li@seeed.cc'

    msg = MIMEText("warning", 'plain', 'utf-8')  # 
    msg['From'] = sender
    msg['To'] = receiver
    msg['Subject'] = Header("Attention", 'utf-8')      # 
    smtp = smtplib.SMTP()
    try:
        smtp.connect(smtpserver)                # smtp
        smtp.login(username, password)
        smtp.sendmail(sender, receiver, msg.as_string())
        print("")
    except smtplib.SMTPException:
        print("")
if __name__ == '__main__':
    run()
schedule.every(1).minutes.do(run)
while True:
    schedule.run_pending()       # 

Credits

Kway
5 projects • 2 followers
Contact

Comments

Please log in or sign up to comment.