Trying to figure this one out. I'm trying to send an OSC style message to a lighting console to trigger an event. I'm using a Raspberry Pi Pico W and coding in Micropython. The Wi-Fi connects and gives positive feedback. Should be fairly simple but no data seems to be getting through.
Here is the code I am using:
import network
import machine
import usocket as socket
from time import sleep
import config
#set up onboard led to turn on when connected
led = machine.Pin('LED', machine.Pin.OUT)
led.on()
sleep(.1)
led.off()
sleep(.1)
# Wi-Fi configuration
SSID = config.wifi
PASSWORD = config.password
# Static IP address configuration
ip_address = config.picoIP
subnet_mask = "255.0.0.0"
gateway = "192.168.1.1" # Replace with your gateway IP
# HOG4 OSC settings
hog4_ip = config.hogIP # Replace with your HOG4's IP address
hog4_port = config.hogport # Replace with the HOG4's OSC port
# GPIO pin configuration
gpio_pin = machine.Pin(7, machine.Pin.IN, machine.Pin.PULL_UP)
# Connect to Wi-Fi
def connect_to_wifi(SSID, PASSWORD):
wlan = network.WLAN(network.STA_IF)
if not wlan.isconnected():
print("Connecting to WiFi...")
wlan.active(True)
led.off()
wlan.ifconfig((ip_address, subnet_mask, gateway, "8.8.8.8")) # Set static IP
wlan.connect(SSID, PASSWORD)
while not wlan.isconnected():
sleep(5) # Add a delay of 5 seconds
print("Connected to WiFi")
print("IP Address:", wlan.ifconfig()[0])
# LED on for wifi connected
led.on()
def send_osc_message():
# create UDP socket
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
# Construct the OSC message
address = "/hog/hardware/go/1"
data = b",i" + bytearray([1]) # OSC argument for integer (1)
message = address.encode() + data
# send message
s.sendto(message, (hog4_ip, 7001))
print("Sent OSC message to HOG4")
print(message)
s.close()
# Main program loop
def main():
connect_to_wifi(SSID, PASSWORD)
while True:
if gpio_pin.value() == 0: # GPIO 7 is LOW
send_osc_message()
sleep(0.5) # debounce the button
sleep(0.1)
if __name__ == "__main__":
main()