entropybit / slaprinter

A combinaton of an app and server for a sla 3d printer
0 stars 2 forks source link

implement: data sending to raspberry #9

Open Aslan0 opened 9 years ago

Aslan0 commented 9 years ago

has to send:

  1. .stl
  2. slice-stack
  3. conf-file
  4. start/pause/stop signals
Aslan0 commented 9 years ago

and all the options in the printing settings too!

entropybit commented 9 years ago

Since we do not need realtime transfer rates we could simply used requests, so data sending via http. Which also has the benefit of not collidig with any firewall settings, since everything is send the same way as webpages. So if surfing works so will data sending to our py.

The sending of data is really relatively straightforward in python, see here http://docs.python-requests.org/en/latest/user/quickstart/#json-response-content.

Aslan0 commented 9 years ago

Ive implemented data sending via requests. There needs to be an html server on the raspberry end that listens. I dont know how to do that.

entropybit commented 9 years ago

First of all it could be that html data sending is not the adequate method here. Another simpler method, yet only in terms of the protocol simpler, would be using the TCP/IP protocol. This is however a bit more messy since you have to bother will all kinds of error handling involved. However a simple tutorial how to establish a server and a client is given here http://pymotw.com/2/socket/tcp.html.

To now come back to what you haver already implemented. Html requests are usally processed by an so called web api. Which means at the server end you have a web server which can process requests based on url. For example a web api interface for printing a given text with some assigned id would have per example the following adress

http://domain.de/echo/1/

where the text is given via ajax as an array (like you have implemented with the printer conf).

In flask you would implement the handling of this url as follows

from flask import Flask
app = Flask(__name__)

@app.route("/echo/<pid>")
def echo_string_with_id():
    data = json.loads(request.data)
    text  = data["text"]
    return text

if __name__ == "__main__":
    app.run(host='0.0.0.0')

if you run this you will have an webserver capable of parsing only the subpath /echo/ acessable from anywhere at port 5000. So if you are connected to the pi network 10.0.0.1:5000 should give you access to the webserver. However, sometimes using the adresse with an specified port makes trouble. If this is the case we have to install a webserver for direct serving via the ip. A leighweight webserver which should be installable on the pi without any problems is nginx, which is much more leightweight than apache. I have done this recently on my laptop for work and will give you my nginx configuration as follow

server {

        listen 80 default_server;
        server_name 10.0.0.1;

        location / {
                proxy_pass  http://127.0.0.1:5000/;
                proxy_set_header    Host    $host;
                proxy_set_header    X-Real-IP   $remote_addr;
        }

}

Simply after installing nginx replace /etc/nginx/sites-available/default with above. Then do a sudo service nginx restart and start the python script with flusk and you should have the webserver accesible via the ip 10.0.0.1.

entropybit commented 9 years ago

Do you still have problems with this ? If so how can I help ? Was something unclear or hadn't you just had the oppurtunity to try it again with the PI ?

Aslan0 commented 9 years ago

I was working on the slicing algorithm the past weeks. now you posted one that works just like that. i dont know if i should be happy or angry.

i didnt try to establish a server connection again....

whenever im in the lab, i cant code because everyone wants me to look at something. it really is no environment to work in. i tried cloning the software to another raspberry to be able to experiment at home, but failed when copying the files to another sd-card. I have my biggest exam on thursday and cant spend all my day with the 3D printer.

2015-07-15 1:57 GMT+02:00 mithrawnuruodo notifications@github.com:

Assigned #9 https://github.com/mithrawnuruodo/slaprinter/issues/9 to @Aslan0 https://github.com/Aslan0.

— Reply to this email directly or view it on GitHub https://github.com/mithrawnuruodo/slaprinter/issues/9#event-355939803.

entropybit commented 9 years ago

But I also used the idea of your implementation, I only coded it in a more abstract way so that we can also code other more intelligent slicers as the naive one later.

Also the biggest part was the correct displaying. Which is mainly meant to verify how good the algorithm works (as the slices can easily be evaluated by visual examination ..) Also my code is very inefficient and does not really work yet. (If you load one of the models from the link I posted it will take a while to slice them this way)

Regarding the exam I wish you a success as well as luck ^^ (both are usually good to have xD). As I said I am in a similar situation so I understand completely.

Maybe we should talk with Michael about some alternative locations for programming ? Or we really have to "restart" regular meetings between us both for "pair programming" with the PI ^^ As soon as my tests are done this should be possible. (so for t >= 01.08. :D )

entropybit commented 9 years ago

... I think i meant chris btw xD not you -.-