文字列にテキストを出力するPythonスクリプトがあります。私はそのテキストをオンラインで入手できるようにして、Arduinoマイクロコントローラにプルダウンすることができます。言い換えれば、作業フローは次のようになります:テキストソース> Python> ??? > Arduino>最終出力。Flaskを使ってGETリクエストで利用できるものを出力するWebサーバーを作成する
私はHerokuのサンプルFlaskコードを使用して、この機能を有効にする実験を開始しました。フラスコのための彼らのコードは次のとおりです。私はHerokuのアプリ上の要求を取得するHTTPを行うにしようとすると
import os
from flask import Flask
app = Flask(__name__)
@app.route('/')
def hello():
return 'Hello World!'
if __name__ == '__main__':
# Bind to PORT if defined, otherwise default to 5000.
port = int(os.environ.get('PORT', 5000))
app.run(host='0.0.0.0', port=port)
、それは私がこのスクリプトは、本当に何も出力しないため、これがある疑いがある404を与えます。たとえば、ときに私はGETリクエストを行うためにProcessing.orgのウェブサイトからこの処理アプリを使用します。
import processing.net.*;
Client c;
String data;
void setup() {
size(200, 200);
background(50);
fill(200);
c = new Client(this, "http://freezing-stream-5123.herokuapp.com/", 80); // Connect to server on port 80
c.write("GET/HTTP/1.1\n"); // Use the HTTP "GET" command to ask for a Web page
c.write("Host: my_domain_name.com\n\n"); // Be polite and say who we are
}
void draw() {
if (c.available() > 0) { // If there's incoming data from the client...
data = c.readString(); // ...then grab it and print it
println(data);
}
}
は何が返されることはこれです:
HTTP/1.1 200 OK
Date: Sat, 31 Mar 2012 22:27:10 GMT
Server: Apache
Cache-control: no-cache, no-store
Expires: Thu, 01 Jan 1970 00:00:00 GMT
Pragma: no-cache
Content-Length: 968
Connection: close
Content-Type: text/html; charset=UTF-8
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html><head><meta http- equiv="refresh" content="0;url=http://earthlink-help.com/main?
InterceptSource=0&ClientLocation=us&ParticipantID=xj6e3468k634hy3945zg3zkhfn7zfgf6&FailureMode =1&SearchQuery=&FailedURI=http%3A%2F%2Fmy_domain_name.com%2F&AddInType=4&Version=2.1.8-1.90base&Referer=&Implementation=0"/><script type="text/javascript">url="http://earthlink-help.com/main?InterceptSource=0&ClientLocation=us&ParticipantID=xj6e3468k634hy3945zg3zkhfn7zfgf6&FailureMode=1&SearchQuery=&FailedURI=http%3A%2F%2Fmy_domain_name.com%2F&AddInType=4&Version=2.1.8-1.90base&Referer=&Implementation=0";if(top.location!=location){var w=window,d=document,e=d.documentElement,b=d.body,x=w.innerWidth||e.clientWidth||b.clientWidth,y=w.innerHeight||e.clientHeight||b.clientHeight;url+="&w="+x+"&h="+y;}window.
location.replace(url);</script></head><body></body></html>
AKA:何もありません。私がウェブページを引っ張るためにカールを使用すると、「Hello world」が表示されますが、それが何かを意味するかどうかはわかりません。
私の質問は、誰かが私の文字列を私がそれを取得することができる何かに貼り付ける何かに私を指すことができますか?私はこれがおそらく愚かな質問であることを理解していますが、私はWebサーバーの海などで完全に失われており、いくつかのガイダンスに感謝します。
ありがとうございます!