Advertisement
silver2row

Dweet.io and Maybe a PWM LED Lighting Thing?

Feb 18th, 2019
267
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.20 KB | None | 0 0
  1. import requests, psutil, os
  2. import Adafruit_BBIO.PWM as PWM
  3. import time
  4. import datetime
  5.  
  6. LED = "P8_13"
  7. PWM.start(LED, 0)
  8.  
  9. thing_name = "6d073d05-4f53-b8a2-1040318ecfbb_dote"
  10.  
  11. def dweet(thing, **vals):
  12.     url = "http://dweet.io/dweet/for/{}".format(thing)
  13.     requests.post(url, params=vals)
  14.  
  15. def get_uptime():
  16.     with open("/proc/uptime", "r") as f:
  17.         raw = f.read()
  18.     seconds = float(raw.split()[0])
  19.     return seconds
  20.  
  21. def LEDII():
  22.     try:
  23.         while True:
  24.  
  25.             for i in range(0, 100):
  26.                 PWM.set_duty_cycle(LED, i)
  27.                 time.sleep(0.2)
  28.  
  29.             for i in range(100, 0, -1):
  30.                 PWM.set_duty_cycle(LED, i)
  31.                 time.sleep(0.2)
  32.  
  33.  
  34.  
  35.         while True:
  36.  
  37.             uptime = get_uptime()
  38.             uptime_datetime = datetime.datetime.fromtimestamp(uptime)
  39.             uptime_datetime.strftime("%H:$M:$S")
  40.  
  41.             load = psutil.cpu_percent(interval=2)
  42.             mem = psutil.virtual_memory()[2]
  43.  
  44.             LEDI = LEDII()
  45.  
  46.             dweet(thing_name, uptime=uptime, cpu_load=load, memory=mem, LEDII=LEDI)
  47.  
  48.             print(os.getloadavg())
  49.  
  50.     except KeyboardInterrupt:
  51.         PWM.cleanup()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement