I am having an issue with the following code of Python 3 (the line at 5th position from bottom count=count+1):
import base64
import json
from google.cloud import iot_v1
import os
from twilio.rest import Client
account_sid = os.environ['TWILIO_ACCOUNT_SID']
auth_token = os.environ['TWILIO_AUTH_TOKEN']
client = Client(account_sid, auth_token)
count = 0
def device_config(config):
client = iot_v1.DeviceManagerClient()
name = client.device_path(<project_ID>,
<Region>, <Registry>, <Device_ID>)
binary_data = bytes(config, 'utf-8')
client.modify_cloud_to_device_config(name, binary_data)
def hello_pubsub(event, context):
if 'data' in event:
data = event['data']
data = base64.b64decode(data)
data = data.decode('utf-8')
data = json.loads(data)
temperature = float(data['temperature'])
if temperature > 25.0:
device_config("ledon")
if count < 1:
client.calls.create( \
url=<URL>,
to=os.environ['TWILIO_TO'],
from_=os.environ['TWILIO_FROM'])
count = count+1
else:
device_config("ledoff")
else:
print("Data is not present!")
This function will be called continuously (imagine like an infinite loop will call this function). I want to update count by 1 when first time temperature goes above 25 and for later calls, how high it may go, LED should be on, but calling shouldnot be done