Giter Club home page Giter Club logo

Comments (13)

jackw01 avatar jackw01 commented on July 28, 2024

Didn't have time to test it, but this should work. Just send a request to /resettimer.

from led-control.

javl avatar javl commented on July 28, 2024

Thanks for the quick answer and solution! I don't have access to the Pi's at the moment, but I'll let you know as soon as I'm able to test this.

from led-control.

javl avatar javl commented on July 28, 2024

Just tested the update with 3 devices and it works great! Thanks again.
I'll close this issue.

from led-control.

Fitipalek avatar Fitipalek commented on July 28, 2024

Thank you for this great tool. I've added a webpage to use as a simple controller, with buttons that use GET requests to so I can easily switch between specific settings. For example: Button A might set the brightness to 0.2, speed to 0.1 and select the 'fire' color palette, while button B will set the brightness to 1.0, speed to 1.0 and enable a custom movement pattern. This works great, and by sending the same GET request to multiple IP addresses I can control a couple of Raspberry Pi's at the same time.

The only problem I have is the cycle on the Pi's not being in sync. When I press button B to start a wiping movement on all Pi's they will switch to the pattern at (pretty much) the same time, but the position might be different as their current cycle positions are not the same.

I've been checking the code, but it doesn't seem to be an endpoint to reset the cycle, or am I missing something? If there isn't, do you have any suggestions on how to implement this?

(I hope my question is clear, feel free to let me know if it isn't).

Can you give me an example of this GET request on another pi ?

Tkanks a lot

from led-control.

javl avatar javl commented on July 28, 2024

hi @Fitipalek

This isn't the most sophisticated way to do things, but it worked for the quick fix I needed. In my case I have 5 devices I wanted to sync, so I added a button in HTML:

    <button onclick="sync()">Sync</button>

Then in the javascript I defined a list of IP addresses for all my devices (I made them static in the router so they never change):

const endpoints = [
    'http://192.168.1.201',
    'http://192.168.1.202',
    'http://192.168.1.203',
    'http://192.168.1.204',
    'http://192.168.1.205',
];

Lastly, the sync() function simply iterates over this list and requests the resettimer endpoint from all of them. Technically there might be a small delay between the calls, but in practise this seems to work fine and you can always hit the sync button again.

function sync(){
    for (let i=0; i<endpoints.length;i++) {
        fetch(`${endpoints[i]}/resettimer`)
    }
}

(Fetch is a command build into modern browsers, and we're ignoring whatever it might return)

from led-control.

Fitipalek avatar Fitipalek commented on July 28, 2024

@javl thanks a lot, it works, do you have also example of usage of /updatesettings parameter........ i tried but not succeeded

from led-control.

Javi avatar Javi commented on July 28, 2024

I don't, but you probably didn't mean me ;)

from led-control.

Fitipalek avatar Fitipalek commented on July 28, 2024

I don't, but you probably didn't mean me ;)

sorry :)

from led-control.

javl avatar javl commented on July 28, 2024

@Fitipalek I haven't used it but judging by the code here you need to send it a json object with the values you want to change, something like:

{
'setting1': 'value1',
'setting2': 'value2'
}

from led-control.

Fitipalek avatar Fitipalek commented on July 28, 2024

@javl I found in java this piece of code:

   async set(path, value) {
       _.set(this.settings, path, value);
       console.log('Store set:', path, value);
       const delta = {};
       _.set(delta, path, value);
       await axios.post('/updatesettings', delta);
    }

when i run it like this :

   async set(path, value) {
       _.set(this.settings, path, value);
      console.log('Store set:', path, value);
      const delta = {};
      _.set(delta, path, value);
      //fetch('http://10.23.24.12:8001/updatesettings',delta);
      axios.post('http://10.23.24.13:8001/updatesettings',delta);
      axios.post('http://10.23.24.12:8001/updatesettings',delta);
   }

it is working for local raspberry but not for the other
when i use postman tool from chrome and send post request, that way i can control both raspberries

Is there something what is blocking post requests but not get requests ?

Thanks :)

from led-control.

Fitipalek avatar Fitipalek commented on July 28, 2024

I edited this piece of code in Python on one of the rasperries and now it is working for me :)
@app.post('/updatesettings') def update_settings(): 'Update settings' new_settings = request.json x = requests.post('http://10.23.24.12:8001/updatesettings', json = new_settings ) controller.update_settings(new_settings) return jsonify(result='')

Thanks :)

from led-control.

jackw01 avatar jackw01 commented on July 28, 2024

@javl I found in java this piece of code:

   async set(path, value) {
       _.set(this.settings, path, value);
       console.log('Store set:', path, value);
       const delta = {};
       _.set(delta, path, value);
       await axios.post('/updatesettings', delta);
    }

when i run it like this :

   async set(path, value) {
       _.set(this.settings, path, value);
      console.log('Store set:', path, value);
      const delta = {};
      _.set(delta, path, value);
      //fetch('http://10.23.24.12:8001/updatesettings',delta);
      axios.post('http://10.23.24.13:8001/updatesettings',delta);
      axios.post('http://10.23.24.12:8001/updatesettings',delta);
   }

it is working for local raspberry but not for the other when i use postman tool from chrome and send post request, that way i can control both raspberries

Is there something what is blocking post requests but not get requests ?

Thanks :)

This doesn't work because you can't send cross-origin requests from Javascript code running inside of a website. This is a security feature. If you were to send these POST requests from Javascript code running in Node.js or from a program written in any other language, they would work.

from led-control.

javl avatar javl commented on July 28, 2024

@jackw01 Not necessarily. By default cross-origin requests are not allowed, but I've added flask-cors in my fork to allow these requests.
javl@489ec91

Note: opening up your server this way can be a very bad idea. Imagine someone turning on all of your LEDs to full brightness while your power supply is not rated for full power / long durations of such power delivery.
I needed this so I can control my setup from a phone, but the router I'm using is NOT connected to the internet, it's just for a local network.

from led-control.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.