I'm trying to write an app that simply passes a variable to the sketch from main via the bridge and prints it in the sketch console, and also prints the value passed from the main in it's console. I got that working (see code below).
But what I am having a problem with and need help with is passing generated data from a sketch through the bridge backup to the main while printing the values generated in both consoles, to see if it is passed properly.
I will try to get that new non-working code up to the forum when I get it formatted for viewing. Help and suggestions would be appreciated. K
# SPDX-FileCopyrightText: Copyright (C) ARDUINO SRL (http://www.arduino.cc)
#
# SPDX-License-Identifier: MPL-2.0
from arduino.app_utils import *
import time
# Init varible states
led_state = False
com_loop = 0
def loop():
# Make the variables available to everyone
global led_state
global com_loop
time.sleep(1)
led_state = not led_state
# Value of data sent to sketch
com_loop = com_loop + 1
print("main loop count: ")
print(com_loop)
# Send the data to the sketch
Bridge.call("set_led_state", led_state, com_loop)
App.run(user_loop=loop)
Python Console Output
Activating python virtual environment
======== App is starting ============================
2026-02-15 03:22:11.337 INFO - [MainThread] App: App started
main loop count:
1
main loop count:
2
main loop count:
3
main loop count:
4
// SPDX-FileCopyrightText: Copyright (C) ARDUINO SRL (http://www.arduino.cc)
//
// SPDX-License-Identifier: MPL-2.0
#include "Arduino_RouterBridge.h"
void setup() {
pinMode(LED_BUILTIN, OUTPUT);
Bridge.begin();
// Get data from main
Bridge.provide("set_led_state", set_led_state);
}
void loop() {
}
// Getting and printing data from main python
// com_loop has the int data to print from main
void set_led_state(bool state, int com_loop) {
// LOW state means LED is ON
digitalWrite(LED_BUILTIN, state ? LOW : HIGH);
Monitor.println(com_loop);
if(com_loop == 1) {
Monitor.println("First data passed");
}
}
Sketch Console Output:
1
First data passed
2
3
4


