Hi Gunnar, thanks for the replies.
So I pinged blynk-cloud.com from a terminal window on the same RPi and that works fine. Got a response from 139.59.206.133 in around 60ms, so that all seems OK.
By the way I am in the UK, if that makes any difference.
Here is the code I am running, it seems to run on the RPi OK and I get the “splash” screen on the console window OK. The issue I am having is that the App on my Moto E5 Android phone has the icon at the top of the screen with a red “1” on it. In the past that has always shown that Blynk wasn’t running on the RPi.
So my guess is that although the code appears to be running on the RPi maybe it isn’t communicating with the cloud server, or my phone App isn’t “seeing” the session that is running on the cloud server?
import BlynkLib, time
from gpiozero import PWMLED
import paho.mqtt.client as mqtt
red = PWMLED(21) # set up LEDs to pulse using PWM
yellow = PWMLED(20) # for 201 r=3 y=4 g=2
green = PWMLED(16) # for Pi3 r=21 y=20 g=16
BLYNK_AUTH = '7f91432283c84457822eec87592a9b63'
# old replaced 7/7/19 BLYNK_AUTH = '61cc1d16f6e0490db628c25423adba54' # Blynk code
blynk = BlynkLib.Blynk(BLYNK_AUTH) # Initialise Blynk
status = 0 # This is for the virtual read for the LED
mqttc=mqtt.Client()
#mqttc.connect("192.168.1.203", 1883,60) #sub Q on 203, port 1883, 60 sec keep alive
# These functions are called asynchonously by Blynk ....
@blynk.VIRTUAL_WRITE(1) #Register Virtual Pin
def my_write_handler(value):
global status
if int(value)==1:
red.value=1 # Switch on LED
status=255
print('ON Heating') # Print update
mqttc.connect("192.168.1.203", 1883,60) # connect
mqttc.publish("hello/world", "RED on" ,1) # Publish to MQ try QOS 1
mqttc.publish("highmount/heating", "R3on" ,1) # Publish to 199
mqttc.disconnect() # disconnect
else:
red.value=0
status=0
print('OFF Heating')
mqttc.connect("192.168.1.203", 1883,60)
mqttc.publish("hello/world", "RED off" ,1)
mqttc.publish("highmount/heating", "R3off" ,1) # Publish to 199
mqttc.disconnect()
@blynk.VIRTUAL_WRITE(2) #Register Virtual Pins
def my_write_handler(value):
if int(value)==1:
yellow.value=1
print('ON Front light')
mqttc.connect("192.168.1.203", 1883,60)
mqttc.publish("highmount/frontdoor/light", "YELLOW on")
mqttc.disconnect()
else:
yellow.value=0
print('OFF Front light')
mqttc.connect("192.168.1.203", 1883,60)
mqttc.publish("highmount/frontdoor/light", "YELLOW off")
mqttc.disconnect()
@blynk.VIRTUAL_WRITE(3) #Register Virtual Pins
def my_write_handler(value):
if int(value)==1:
green.value=1
print('ON GREEN')
mqttc.connect("192.168.1.203", 1883,60)
mqttc.publish("hello/world", "GREEN on")
mqttc.disconnect()
else:
green.value=0
print('OFF GREEN')
mqttc.connect("192.168.1.203", 1883,60)
mqttc.publish("hello/world", "GREEN off")
mqttc.disconnect()
# Now write back to the LED on V4 ...
def update_led():
global status
blynk.virtual_write(4, status)
# --- Start of MAIN programme -----------------------------------------
blynk.run() # Start Blynk (this call should never return)
Basically, the code waits for a signal from the Blynk App and generates an MQTT message to other RPi’s that do stuff like turn on my heating, a light, waters the garden. It is written in Python3.
Thanks for taking a look
Regards
Bruce