Multiple Raspberry Pi Clients Talk to Pi Server with Python Socket.IO

Поделиться
HTML-код
  • Опубликовано: 26 окт 2024

Комментарии • 32

  • @MarkHankinson
    @MarkHankinson 2 года назад +1

    Great work Kevin, I am creating a time track and attendance system using RFID and Barcode over multiple clients. This gives me the confidence to proceed as I can now see a way to grasp the data. Thank you.

  • @emilyhaigh1244
    @emilyhaigh1244 2 года назад

    Kevin, thanks for this video! I am making a simple distributed system with 4 rasp pis for my graduate OS class. This is a great intro to sockets in python. Do you have more videos on this topic?

    • @KevinSidwar
      @KevinSidwar  2 года назад

      Thanks so much for watching Emily. Glad you found it helpful. I don't really have any other videos around Pi to Pi communication or sockets. Sorry. Good luck on your class project!

  • @lahiruwelagedara3694
    @lahiruwelagedara3694 3 года назад +1

    Hello Kevin ! This demo was very helpful for a project that I am working on right now. I have the same setup but with another additional angular web application component to display the data in real time as well. At the moment I am using a flask server with socketio. So I can communicate with both Pi and Web app using websockets. Do you have any suggestion for any alternate or better way ?

    • @KevinSidwar
      @KevinSidwar  3 года назад +1

      Hey Lahiru, thanks for watching. That sounds like a cool project. One of the nice things about socketio is that you can add additional listening clients easily. Sounds like you're on the right track to me by just having that angular app get it's data via socketio as well like the Pis and server. If you wanted you could have the app get data by calling endpoints you create on the flask server but it's really just a matter of preference. Good luck on your project.

    • @lahiruwelagedara3694
      @lahiruwelagedara3694 3 года назад +1

      @@KevinSidwar Thank you for the feedback. Appreciate it !

  • @grezz247
    @grezz247 3 года назад +1

    Hey Kevin. Great video. Is it possible to have multiple clients connected, then use the server to select just one to send a message or file to?

    • @KevinSidwar
      @KevinSidwar  3 года назад +1

      Thanks for watching Grezz. Socketio is a broadcast messaging system so it sends the message to all of the clients but you can do things within the messages to target specific clients. Using unique ids for example in the message so that other clients can ignore it. But as far as I understand you have to add that functionality yourself in code.

  • @ranariad
    @ranariad Год назад +1

    Hi Kevin, thank you for this helpful tutorial.
    Would you plz tell me how I could send from server to client

    • @KevinSidwar
      @KevinSidwar  Год назад +1

      Socketio is a broadcast messaging system so it sends the message to all of the clients but you can do things within the messages to target specific clients. Using unique ids for example in the message so that other clients can ignore it. But as far as I understand you have to add that functionality yourself in code. So you would just emit the message from the server and all clients would see it.

    • @ranariad
      @ranariad Год назад +1

      @@KevinSidwar Thank you very much for your clarification. I am trying to emit a message from the server, but no message has been received by any client, would you plz help me in solving this matter!

    • @KevinSidwar
      @KevinSidwar  Год назад +1

      @@ranariad If you can post of Gist of your code I could take a look.

  • @navidshahbazi7338
    @navidshahbazi7338 2 года назад +1

    Hello
    Thank you for this great tutorial
    How can I connect a Raspberry Pi to every room in Django Channel chat app?
    Thank you very much for your tutorial

    • @KevinSidwar
      @KevinSidwar  2 года назад

      Sorry, I'm not familiar with Django but you should be able to use the same approach and make connections for each room and just send that information along.

  • @bhuvansharma2364
    @bhuvansharma2364 4 года назад +1

    This would be a good solution if you only need a passive server receiving the requests. What if we want to send and receive some data from both sides (maybe using hostname or whatever)?

    • @KevinSidwar
      @KevinSidwar  4 года назад +2

      You can go both ways with socketIO although it gets a little involved. You just emit from the clients but you could also use raw sockets (TCP or UDP) and have the clients connect directly to the server with a two-way pipe.

  • @amitnair92
    @amitnair92 4 года назад +2

    Insterd of Deleting "threading.current_thread() == threading.main_thread()" you could update it to threading.current_thread().__class__.__name__ == '_MainThread'

    • @KevinSidwar
      @KevinSidwar  4 года назад

      Thanks for sharing that here Amit. Hopefully it will help those that see the video.

  • @gvbvwockee
    @gvbvwockee 4 года назад +1

    Thank you for this tutorial, I really appreciate it. Just exploring the world of MQTT and IoT and this provided me with the guidance I was looking for! However, I am having trouble when going to run my server.py script. I have an issue like the bug you showed above, but mine is a ModuleNotFoundError for the import of _ssl. I am running Python 3.7.0 and I have tried everything I have been able to find online and nothing has worked. Any ideas?

    • @KevinSidwar
      @KevinSidwar  4 года назад

      Hey Gabriella, thanks for watching. That sounds like an issue with missing a system library. If you are on the Raspberry Pi try install the SSL stuff with sudo apt-get install libssl-dev. Let me know if you're still stuck.

  • @BryanAsael
    @BryanAsael 3 года назад +1

    can i use socket.io to communicate between multiple RPi zeros and my computer?

    • @KevinSidwar
      @KevinSidwar  3 года назад

      Yeah, absolutely. Just remember that with socket.io the messages are broadcast to all clients but you can certainly have clients on RPi zeros as well as on your computer.

  • @thePeras
    @thePeras 3 года назад +1

    Hi, thanks for the video!
    Is there any way when my server goes down and then start again of my raspberryPi connects automatically? For example, if Pi lost connection to the server, it will tries to connect to it in 5 seconds interval

    • @KevinSidwar
      @KevinSidwar  3 года назад +1

      Thanks for watching the video. You could use cron to automatically start the process when the Pi boots up. The WiFi issue might be a little trickier. You might just add something within the Python program that checks for connectivity. I'm not really sure how the socket.io library handles interruptions to network service. You'd have to look into that to come up with a plan to deal with it.

  • @agent2130
    @agent2130 4 года назад +1

    Is there a way to log the response or information return by the server on the client?

    • @KevinSidwar
      @KevinSidwar  4 года назад

      So socketio isn't really a request/response scenario. It is event driven with a broadcast approach. For example, when the server gets the "mymessage" event you could send a message back out to the clients using "emit" on the server. That is a way to emulate a request/response flow. Beware, however, that when you emit from the server all clients will get the message so you will want to add some metadate to identify the client so only the appropriate client processes the message. Hopefully that helps.

    • @agent2130
      @agent2130 4 года назад +1

      @@KevinSidwar Absolutely thank you and great video.

  • @vmgobinath
    @vmgobinath 4 года назад +1

    Hi,
    Thanks a lot. Really Good video and able to understand and connect the RPi's . I want to connect server Pi with remote client PI and need to send and receive the data. Could you please help me to solve this?

    • @KevinSidwar
      @KevinSidwar  4 года назад

      I think there is a way to do this that involves router settings and DNS services but I'm not sure how to do it. Sorry that's not more helpful.