Calling a web address from Volumio

I would like to call the web pages of the various esp32s that control my HiFi. For example 192.168.1.1xx/P

I’m thinking of writing a small plugin to do this. The plugin bit is ok - but I lack the knowledge of how to actually send the call.

I’m hoping that there is something simple that I’ve missed in my explorations.

Has anyone any pointers for me?

Thanks in advance.

Do you want to access and load a webpage within Volumio, as that is what I understood?
Or just perform a webcall without any interaction?

No interaction, just get the micro controllers to do their stuff.

Aha, that makes it a lot easier.
For example via Bash and GPIO (this is just an untested piece of code, but gives you an idea):

#!/bin/bash

# Define GPIO pin
GPIO_PIN=17

# Set GPIO pin as input
gpio mode $GPIO_PIN in

# Function to make HTTP request to URL
make_request() {
    URL="$1"
    # Make HTTP request using curl
    curl -s "$URL" >/dev/null
    echo "Request sent to $URL"
}

# Main loop
while true; do
    # Read GPIO pin value
    PIN_VALUE=$(gpio read $GPIO_PIN)
    
    # Check if pin value is low (button pressed)
    if [ "$PIN_VALUE" -eq 0 ]; then
        # URL to call when button is pressed
        REQUEST_URL="http://example.com/api"
        make_request "$REQUEST_URL"
        sleep 1  # Sleep to debounce button press
    fi
    
    # Sleep to avoid high CPU usage
    sleep 0.1
done

Bash script runs as a service and every time you press a button connected to GPIO 17, it fires.

Something similar using Python3:

import requests
import time

playlist_name = "Radio"
playlist_url = "http://localhost:3000/api/v1/commands/?cmd=playplaylist&name=" + playlist_name

response = requests.get(playlist_url)
print(response.json())

Here you need a 2nd script that monitors the event for which you want this to run. For example with a rotaty encoder or switch. (this one does work as I use it to load some preselected radio channels)

Thank you. Will investigate……

your making a cheap command sender :slight_smile:
i use pc / streamdeck for it, you can do it to on pc / rainmeter

Trying. Just attempting to work out how to do it in JavaScript….

something like this:

const Gpio = require('onoff').Gpio;
const axios = require('axios');

// Define GPIO pin (change this to the appropriate pin)
const gpioPin = 17;

// Define the URL to call when the button is pressed
const apiUrl = 'https://example.com/api';

// Initialize the GPIO pin as an input with pull-up resistor
const button = new Gpio(gpioPin, 'in', 'rising', { debounceTimeout: 10 });

// Function to be executed when the button is pressed
const handleButtonPress = async () => {
  try {
    // Make an HTTP request to the specified URL
    const response = await axios.post(apiUrl, { message: 'Button pressed' });
    console.log('HTTP request successful:', response.data);
  } catch (error) {
    console.error('Error making HTTP request:', error.message);
  }
};

// Attach the button press event listener
button.watch(handleButtonPress);

// Handle program termination (cleanup GPIO)
process.on('SIGINT', () => {
  button.unexport();
  console.log('GPIO cleanup complete');
  process.exit();
});

console.log('GPIO script is running. Press the button to make an HTTP request.');

Also just some scribble, not tested. Not a big JS fan …