Esempio n. 1
0
from PiBlynk import Blynk
from neopixel import *

token = "---token---"
blynk = Blynk(token)

# LED strip configuration:
LED_COUNT = 1  # Number of LED pixels.
LED_PIN = 12  # GPIO pin connected to the pixels (must support PWM!).
LED_FREQ_HZ = 800000  # LED signal frequency in hertz (usually 800khz)
LED_DMA = 5  # DMA channel to use for generating signal (try 5)
LED_BRIGHTNESS = 255  # Set to 0 for darkest and 255 for brightest
LED_INVERT = False  # True to invert the signal (when using NPN transistor level shift)

# Create NeoPixel object with appropriate configuration.
strip = Adafruit_NeoPixel(LED_COUNT, LED_PIN, LED_FREQ_HZ, LED_DMA, LED_INVERT,
                          LED_BRIGHTNESS)
# Intialize the library (must be called once before other functions).
strip.begin()


def virt_in_h(val, pin, st):
    print("Incoming on VP: %d , %s" % (pin, val))
    if pin == 3:
        R = int(val[1])  # Red
        G = int(val[0])  # Green
        B = int(val[2])  # Blue
        strip.setPixelColor(0, Color(R, G, B))
        strip.show()

Esempio n. 2
0
from DHT_Python import dht22
from  oled96 import oled 
from PiBlynk import Blynk

# read data using pin 4
instance = dht22.DHT22(pin=4)

token = "---token---"
blynk = Blynk(token)
def cnct_cb():
	print ("Connected: ")
	
blynk.on_connect(cnct_cb)

def _funCb(ACT):
	result = instance.read()
	if result.is_valid():
		strTemp=("%.2f" % result.temperature)
		strHumi=("%.2f" % result.humidity)
		# Show temperature and humidity on OLED
		oled.yell2("Temp="+strTemp,"Humi="+strHumi) 
		blynk.virtual_write(1,strTemp) # User Virtual port V1
		blynk.virtual_write(2,strHumi) # User Virtual port V2
blynk.Ticker(_funCb, 140, False) # ~2 Hz

blynk.gpio_auto("button")

blynk.run()


Esempio n. 3
0
import socket

from PiBlynk import Blynk
from mytoken import *

blynk = Blynk(token)

#------------------------------------------
import time


def timeNow():
    return time.asctime()[11:19]


#------------------------------------

# rlogger

rlctr = 0


def timer3loop(s):
    # write to (terminal style) rlogger at APP on vp 18
    global rlctr
    rlctr = rlctr + 1
    blynk.virtual_write(18,
                        timeNow() + " " + str(rlctr) + "\n")


blynk.add_Task(6, timer3loop)  # for every 6 secs
Esempio n. 4
0
from PiBlynk import Blynk
from mytoken import *
blynk = Blynk(token)

#------------------------------------------
import time


def timeNow():
    return time.asctime()[11:19]


# a generic handler for incoming vpin writes from app.
# a placeholder until you code your own specific handlers
# (eg "light" could been done as a sensor_widget)


def virt_generic_h(val, pin, txt):
    print(txt, val)


blynk.add_virtual_pin(24, None, virt_generic_h,
                      "Prox: ")  # text get a ride as "state"
blynk.add_virtual_pin(20, None, virt_generic_h, "joystick: ")
blynk.add_virtual_pin(25, None, virt_generic_h, "Light: ")

#---------------------------

# app polls (V10) for time value

Esempio n. 5
0
# iPhone blynk may not have ACCELEROMETER widget?

from PiBlynk import Blynk
from mytoken import *
blynk = Blynk(token)

#------------------------------------------
import time


def timeNow():
    return time.asctime()[11:19]


axl = blynk.accel_widget(17)


def timer2loop(s):  # 2 sec repeat timer
    #print(axl.z, "z")
    print(int(axl.pitch()), int(axl.roll()))


blynk.add_Task(2, timer2loop)

#----------------------------


def cnct_cb():
    print("Connected: " + timeNow())

Esempio n. 6
0
# This example is designed to be paired with example file 31-bridge-out.py
# Run the two with DIFFERENT DEVICE TOKENS.
# (They can be either in same "project" or separate projects as set at phone. Just use different tokens.)

# This "in" bridge receives data directly from other RPi.
# Our display shows incoming messages.
# Our LED on gpio 21 is controlled by button at other end.

import gpiozero as GPIO

from PiBlynk import Blynk
from mytoken import *
blynk = Blynk(
    token2)  # <<<<<<<<<<<<<<<<<<<<   USE DIFFERENT TOKED FROM OTHER END !!!

#-----------------------------------------------
# gpio (incoming) write


def gpioOut_h(val, pin, gpioObj):
    gpioObj.value = val  # control the LED
    print("Incoming GPIO OUT command:", pin, val)


# set up the RPi LED or other outputs and connect to generic gpioOut function above
ledR = GPIO.LED(21)  # gpiozero led objects
blynk.add_digital_hw_pin(21, None, gpioOut_h, ledR)


#-----------------------------------------
# Listen for anything coming in V61. Just print it
Esempio n. 7
0
import time

from PiBlynk import Blynk
from mytoken import *
blynk = Blynk(token)

#------------------------------------------
import time


def timeNow():
    return time.asctime()[11:19]


#------------------------------------


def cnct_cb():
    print("Connected: " + timeNow())

    blynk.email("*****@*****.**", "subject 44",
                "Test.  Body")  ###<<<<<<<<<<<<<<<<<<<< FIX ME
    print(
        "sent email via blynk server. nothing more to do in this demo. Exit!")
    time.sleep(3)
    exit()


blynk.on_connect(cnct_cb)

######################################################################################
Esempio n. 8
0
# This example is designed to be paired with D1 Mini ESP8266
# Run the two with DIFFERENT DEVICE TOKENS.
# (They can be either in same "project" or separate projects as set at phone. Just use different tokens.)

# This "out" bridge speaks (via server) to other "in" device.
# It repeatedly uses our Button4 (our gpio 19) to display on the D1's GPIO 4.

# 1. Create bridge widget
# 2. After getting connected to server, register other end's token
# 3. Send digital commands to D1

from PiBlynk import Blynk
from mytoken import *

blynk = Blynk(token)
import gpiozero as GPIO

#------------------------------------------
import time


def timeNow():
    return time.asctime()[11:19]


#----------------------------------

bridge_to_D1 = blynk.bridge_widget(
    40)  # using our vpin 40 as our outgoing channel

#------------------------------------
Esempio n. 9
0
from PiBlynk import Blynk
from mytoken import *
blynk = Blynk(token)

#------------------------------------------
import time


def timeNow():
    return time.asctime()[11:19]


lcd = blynk.lcd_widget(33)


def timer2loop(s):  # 2 sec repeat timer

    # write time message to LCD at APP on V33
    print("lcd")
    #lcd.cls()
    lcd.Print(0, 0, timeNow())
    lcd.Print(0, 1, "RPI")


blynk.add_Task(2, timer2loop)

######################################################################################

blynk.run()

######################################################################################
Esempio n. 10
0
# This file has ALL the examples rolled into one.

import os, socket
import gpiozero as GPIO
#  http://gpiozero.readthedocs.io/en/v1.3.1/index.html

#import logging
#logging.basicConfig(level=logging.WARNING)
# NOTE: setting logging level here can override the default in PiBlynk library
# Refer __init__.py in the library

from PiBlynk import Blynk
from mytoken import *
blynk = Blynk(token)

#------------------------------------------
import time


def timeNow():
    return time.asctime()[11:19]


# A handy utility used in several places below

#------------------------------------

# Buttons or other inputs by manual coding. Direct GPIO (not Vpin) settings at app.
# Flexible. can make Button, InputDevice etc pulldown etc as desired.
# Slower latency
Esempio n. 11
0
import gpiozero as GPIO

from PiBlynk import Blynk
from mytoken import *
blynk = Blynk(token)

# PWM


# generic gpio read by POLL from app
def gpioRead_h(pin, gpioObj):
    v = gpioObj.value
    if type(v) == type(True):  # on/off gpio
        return (1 if v else 0)
    else:  # gpio led pwm
        return v


def gpioOutPwm_h(val, pin, gpioObj):  # generic pwm write scaled 0-100
    gpioObj.value = int(val[0]) / 100.0  # gpiozero pwm uses 0.0- 1.0


ledB = GPIO.PWMLED(16)  # blue led  controlled from 0-100 slider at app
blynk.add_virtual_pin(8, None, gpioOutPwm_h, ledB)

# ... and the blue PWMLED pwm value is read & sent back to gauge on vpin 9 (0.0 -1.0)
blynk.add_virtual_pin(9, gpioRead_h, None, ledB)

#------------------------------

Esempio n. 12
0
import os

from PiBlynk import Blynk
from mytoken import *
blynk = Blynk(token)


#------------------------------------------
import time
def timeNow():
    return time.asctime()[11:19]

#------------------------------------

# terminal from APP into python interpreter
_last_cmd = ""
def pyterminal_h(value, pin, st):
        global _last_cmd
        cmd = value[0]
        if cmd == ".":
            cmd = _last_cmd
            blynk.virtual_write(pin, "> "+cmd+"\n")
        else:
            _last_cmd = cmd
        try:
            out = eval(cmd)
            if out != None:
                outstr = "= "+repr(out)
        except:
            try:
Esempio n. 13
0
# (They can be either in same "project" or separate projects as set at phone. Just use different tokens.)


# This "out" bridge speaks (via server) to other "in" device.
# It repeatedly sends OUR time to other RPi for display there,
# and uses our Button4 (our gpio 19) to display on the other RPi's GPIO 21.



# 1. Create bridge widget 
# 2. After getting connected to server, register other end's token
# 3. Send virtual & digital commands to other RPi

from PiBlynk import Blynk
from mytoken import *
blynk = Blynk(token)


#------------------------------------------
import time
def timeNow():
    return time.asctime()[11:19]

#----------------------------------

bridge_to_otherpi = blynk.bridge_widget(40)   # using our vpin 40 as our outgoing channel

#------------------------------------
# our button -> their LED 
our_button4 = GPIO.Button(19) 
other_rpi_redled_gpio = 21
Esempio n. 14
0
from gpiozero import Button
from PiBlynk import Blynk
import time
token = "---token---"
blynk = Blynk(token)

SW_pin = 13
button = Button(SW_pin)


def cnct_cb():
    print("Connected: ")


blynk.on_connect(cnct_cb)


def fun_notify():
    print("alert")
    blynk.notify("Alert")  # beep the smartphone


button.when_pressed = fun_notify

blynk.gpio_auto("button")

blynk.run()
Esempio n. 15
0
from PiBlynk import Blynk
from mytoken import *
blynk = Blynk(token)

#------------------------------------------
import time


def timeNow():
    return time.asctime()[11:19]


#------------------------------------------

# NOTE: this crashes if oled library or oled hardware display not found !!!

from oled96 import oled
oled.yell2(" Hello")


def jlog(val, pin, st):
    oled.jnl(val[0])
    print(val[0])


blynk.add_virtual_pin(19, write=jlog)

######################################################################################

blynk.run()
Esempio n. 16
0
# Camera function with (fixed) preview


import os


from PiBlynk import Blynk
from mytoken import *
blynk = Blynk(token)

#------------------------------------------
import time
def timeNow():
    return time.asctime()[11:19].replace(":", ".")


#  CAMERA 
#  with optional preview to HDMI screen (but not to VNC screen!)

# http://picamera.readthedocs.io/en/release-1.10/index.html
# https://www.raspberrypi.org/documentation/usage/camera/python/README.md


import picamera


imageDir = "images"
if not os.path.exists(imageDir):
    os.makedirs(imageDir)
    
Esempio n. 17
0
# manually configured GPIOs

import gpiozero as GPIO

from PiBlynk import Blynk
from mytoken import *
blynk = Blynk(token)

######################################################################################

#  Button1 poll mode
# Buttons or other inputs by manual coding. Direct GPIO (not Vpin) settings at app.
# Flexible. can make Button, InputDevice etc pulldown etc as desired.
# Slower latency

# generic gpio read by POLL from app


def gpioRead_h(pin, gpioObj):
    v = gpioObj.value
    if type(v) == type(True):  # on/off gpio
        return (1 if v else 0)
    else:  # gpio led pwm
        return v


# set up any buttons (or whatever) and connect to gpioRead_h
button1 = GPIO.Button(13)
blynk.add_digital_hw_pin(
    13, gpioRead_h, None,
    button1)  # note the gpiozero button object is payload as "state"