New to App Lab and trying to get to grips with it. I am unable to update a gauge on a dashboard. I have played with CloudBlink and read lots on this forum (only one closed post seems to address the issue RobertvdBerg).
So consider two dashboard widgets:-
-
A slider that sets a value (setVal)
-
A gauge to select that value (getVal)
My code gets the value from the slider OK and I can print it in the Python log. But I can't update the Gauge. Online searches suggest the gauge can only be updated from the .ino file as the .py file can't send values to the dashboard. But in the .ino file the variable associated with the gauge is not recognised.
Any help appreciated.
The .ino file:-
// SPDX-FileCopyrightText: Copyright (C) Arduino s.r.l. and/or its affiliated companies
//
// SPDX-License-Identifier: MPL-2.0
#include <Arduino_RouterBridge.h>
int getVal;
void setup() {
pinMode(LED_BUILTIN, OUTPUT);
Serial.begin(9600);
Serial.println("setUp executing...");
Bridge.begin();
Bridge.provide("set_led_state", set_led_state);
//Bridge.provide("get_slider_value", get_slider_value);
Bridge.provide("set_gauge_value", set_gauge_value);
}
void loop() {}
void set_led_state(bool state) {
// LOW state means LED is ON
digitalWrite(LED_BUILTIN, state ? LOW : HIGH);
}
int set_gauge_value(int aValue) {
getVal = aValue; //This variable can't be linked to the dashboard as far as I can tell.
}
The .py file:-
# SPDX-FileCopyrightText: Copyright (C) Arduino s.r.l. and/or its affiliated companies
#
# SPDX-License-Identifier: MPL-2.0
#
# EXAMPLE_NAME = "Arduino Cloud LED Blink Example"
from arduino.app_bricks.arduino_cloud import ArduinoCloud
from arduino.app_utils import App, Bridge
# If secrets are not provided in the class initialization, they will be read from environment variables
iot_cloud = ArduinoCloud()
iot_cloud.register("getVal")
def update_getVal_cloud(aValue: int):
iot_cloud.getVal = aValue
def hello():
print("Hi")
return
def update_gauge_value(aValue):
print(f"gauge on dash: {aValue}")
# ArduinoCloud.update()
return
Bridge.provide("update_getVal_cloud", update_getVal_cloud)
def led_callback(client: object, value: bool):
"""Callback function to handle LED blink updates from cloud."""
print(f"LED blink value updated from cloud: {value}")
# Call a function in the sketch, using the Bridge helper library, to control the state of the LED connected to the microcontroller.
# This performs a RPC call and allows the Python code and the Sketch code to communicate.
Bridge.call("set_led_state", value)
return
iot_cloud.register("led", value=False, on_write=led_callback)
def getVal_callback(client: object, value: int):
"""Callback function to handle integer updates from cloud."""
hello()
print(f"slider on dash: {value}")
# Call a function in the sketch, using the Bridge helper library, to control the position of the slider connected to the microcontroller.
# This performs a RPC call and allows the Python code and the Sketch code to communicate.
Bridge.call("set_gauge_value", value)
return
iot_cloud.register("setVal", value=0, on_write=getVal_callback)
App.run()