-1

I have a web server and 5 Raspberry Pi's connected to it via LAN. Each Pi will be wired to control two servo motors. Here are the conditions:

  • The web server hosts a web page where the user will be able to control these servos.
  • The user will select which pi to control using UI on the web page.
  • I'm considering having the web server to generate a program (perhaps in Python) to be uploaded to the Pi to execute and control the servos.

Would it be possible or practical to have the web server generate this Python code, or is there a better way to accomplish this?

  • 1
    You should think of a way to rephrase your question, it is very unclear. – Havnar Aug 11 '15 at 13:05
  • 1
    A better description of what you are trying to accomplish would help too. – Steve Robillard Aug 11 '15 at 13:40
  • 2
    Right now it sounds like you are just asking about web programming without knowing that "web programming" exists. Of course you can send data to a web server, have it do some processing, and then send data back. However, whether one of the parties is a pi or not is irrelevant; it would work exactly the same way if they were laptops, blade servers, mainframes, whatever. – goldilocks Aug 11 '15 at 14:56
  • Hi @goldilocks added few details. See if the question is clear to you. – Vijayenthiran Aug 12 '15 at 5:56
3

I don't think you need to run a web server to accomplish something as simple as uploading files to your Raspberry Pis. You can use something like sftp or rsync to copy files between your main machine and your 5 "client" Pis. If they're all on the same LAN, as long as you know the hostnames of the Pis, it should be very easy to connect to each of them and upload whatever you'd like. A bash script should suffice to perform these uploads; a python script might be more than you need.

  • It seems to me that you might be looking for some kind of REST api. You could indeed write this in python should you want this. The web server could then for instance send http://pi-nr4/servo1/move?X=15?Y=99 over http. Instead of "generating code" you then have an application listening on the PI and carrying out the commands. – Havnar Aug 12 '15 at 12:08
1

Like @Havnar said in the comment, the best way is to write the program on all the Pi's to handle different requests and not worry about uploading arbitrary programs to each of them everytime.

Here are some scenerios you can think of:

  • Remember that an RPi can be a web server itself. You can think of it as a service that your web page interface with using RESTful (or other) APIs.

  • Your web server (a service) get request from the client (your web page), and then it send a request to another service (the RPi) to move the servos.

  • Your web server is a central server, with the web page and 5 RPi's as clients like a chat application. A request from your web page can either be "broadcasted" to all other clients (the Pi's) or be "submitted" to some only.

You can also imagine 6 services--your web server and 5 other servers on the Pis communicating using a single set of API rules, with the client being the web page.

  • Thanks for the suggestion @pie-o-pah. If there is a program on all the Pi's and in later part of development if I want to add few features, then I need to change the program in each Pi right? So if we can generate and upload the program directly from the web server there won't be any need to upload the program to each Pi's manually. – Vijayenthiran Aug 13 '15 at 5:52
  • I don't see your point. Controlling the servos from the user's point of view and adding new features from the developer to the Pis are two separate issues. I don't see any reason you'll have to "live" changing your program while controlling the servos. Adding features and improving your code should be on another side using ftp or ssh, not being done via the client. – Pie 'Oh' Pah Aug 14 '15 at 4:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.