-ãŠã§ãããŒãžã®ãã¶ã€ã³ãªã
-åžžã«1ã€ã®Webã¯ã©ã€ã¢ã³ãã®ã¿ãããŒã¿ãåä¿¡ããŸã
-ã¢ã¯ã»ã¹ã§ãããã©ãŠã¶ã®éåžžã«éãããã»ããã ããšãã°ãInternet Explorer 8ãŸãã¯Android 2.3.5ã®ãã©ãŠã¶ãŒã§ã¯æ©èœããŸããã
-Pythonã®ã€ã³ã¹ããŒã«ãå¿ èŠ
ãã°ããããŠãç§ã¯ãã®ãã©ãŒã ããã®ãŸãŸã«ããŠå€æŽããªãããšã«ããŸããã ã«ããã®äžã§ãæ¹èšã®çµæãšãããããã¹ãŠã®æ¬ ç¹ãã©ã®ããã«æé€ãããã«ã€ããŠã®èª¬æã
æçµçµæãããã«è¡šç€ºããŸãã
ãã®ãããªã¯ãArduinoãã¹ããŒããã©ã³ã«æ¥ç¶ãããŠããåãã³ã³ãã¥ãŒã¿ãŒäžã®FirefoxãšIE 8ã§ãCOMããŒãããã®è¡ã3ã€ã®ãã©ãŠã¶ãŒã«åæã«è¡šç€ºãããããšã瀺ããŠããŸãã
Arduinoèªäœã¯ãTemperatureïŒXXXXXXããšããè¡ãæž¡ããæ¥æãšè¡çªå·ãæã€è¡ã¯ããã¯ãšã³ãã®äžéšã®1ã€ã§ãã
次ã«ãæ¬ ç¹ã解æ¶ããæ¹æ³ã«ã€ããŠèª¬æããŸãã ä»åã¯ãããŸãéå±ã«ãªãããã³ãŒãã®ãã¹ãŠã®è¡ã説æããã®ã§ã¯ãªããäž»èŠãªç¹ã®ã¿ã衚瀺ããããã«ããŸãã 質åãããå Žåã¯ãã³ã¡ã³ãã§è³ªåããŠãã ããã
æªãWebããŒãžã®ãã¶ã€ã³ã
åã®èšäºã§ãWebããã³ããšã³ãã®äœæã§ãæ¹æ³ããªãããšããèšèãç解ããŠãããããéåžžã®WebããŒãžãäœæããããšã¯ç§ã«ãšã£ãŠæãé£ãããšæžããŸããã 幞ããªããšã«ãç§ã¯ã»ãšãã©ããã«w3schools.comãçºèŠããããã§BootstrapãçºèŠããAjaxãšjQueryã®åªãããã¥ãŒããªã¢ã«ãèŠã€ããŸããã çµéšè±å¯ãªããã³ããšã³ãéçºè ã«ãšã£ãŠããã®ãµã€ãã§çŽ¹ä»ãããã¥ãŒããªã¢ã«ã¯ããããç¬é¡ã«ãªãã ãã§ãããç§ã®ãããªåå¿è ã«ãšã£ãŠã¯ãŸãã«ãããå¿ èŠãªãã®ã§ãã
ãããã®æç§æžã®æ倧ã®å©ç¹ã¯ãéåžžã«å°ãããŠéåžžã«å å®ããŠããããšã§ãã ãplateããã¬ãŒãã«å¡ããªãã§ãã ããã ååãšããŠãäœããå§ããã«ã¯äžæ©å匷ããã ãã§ååã§ãã
Bootstrapã䜿çšããŠãå€å°ãªããšãåãå ¥ãå¯èœãªWebããŒãžã®ãã¶ã€ã³ãèšèšããããšã¯ããã»ã©é£ãããªãããšãå€æããŸããã ãã¡ããã圌ã¯Artemy Lebedevãããªãããè¿œãåºãããšã¯ãããŸãããããã®äžã§éåžžã«è¿ éã«ãŠãŒã¶ãŒã€ã³ã¿ãŒãã§ã€ã¹ãããã°ã©ã ã§ããŸãã
ç§ãç解ã§ããªãã£ãå¯äžã®ããšã¯ãããã䜿çšããŠããŒãžã2ã€ã®éšåã«åå²ããæ¹æ³ã§ããã ãããããã®åŸãèšäºãCSSã®åçŽæ¹åã®ã»ã³ã¿ãªã³ã°ããå©ãã«ãªããŸããã ãã®çµæãWebããŒãžã§ã¯ãã®ãããªç©ºçœã«ãªããŸãã
<!-- Vertical aligment of text from "Vertical Centering in CSS" at http://www.jakpsatweb.cz/css/css-vertical-center-solution.html --> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"> <html> <head> <style type="text/css"> html, body { height: 100%; margin: 0px; } </style> </head> <body> <div style="display: table; height: 90%; width: 100%; overflow: hidden;"> <div style=" display: table-cell; vertical-align: middle;"> <div style="text-align: center"> data place<br> </div> </div> </div> <div style="display: table; height: 10%; width: 100%; overflow: hidden;"> <div style=" display: table-cell; vertical-align: middle;"> <div style="text-align: right;"> buttons </div> </div> </div> </body> </html>
æ®ãã®ããŒãžã³ãŒãã®ã»ãšãã©ã¯ãBootstrapããã³JavaScriptãã¥ãŒããªã¢ã«ïŒJS HTML DOMã»ã¯ã·ã§ã³ïŒãèªãã åŸã®ãã®ã§ãã äŸå€ã¯jQueryã³ãŒãã§ãããŒãžäžã®ããŒã¿ãæŽæ°ããŸãã ããããããã«ã€ããŠã¯åŸã§ã
ãµããŒãããããã©ãŠã¶ãŒã®éãããç¯å²
以åã®ãããã¿ã€ãã«å¯Ÿãããã©ãŠã¶ãŒã®åŒ±ããµããŒãã¯ãæ å ±ã®æŽæ°ãé ä¿¡ããããã«éžæããããã¯ãããžãŒã§ãããµãŒããŒéä¿¡ã€ãã³ãã«ãããã®ã§ããã ããã§ä»åã¯ãå€ãããå®çžŸã®ããAjaxãã¯ãããžãŒã䜿çšããããšã«ããŸããã Ajaxã䜿çšãããšWebãã©ãã£ãã¯ãå¢å ããŸãããç§ã®æèŠã§ã¯ãæ倧æ°ã®ãã©ãŠã¶ãŒã§æ©èœããã¯ãã§ãã
Ajaxã®ãã1ã€ã®æ¬ ç¹ã¯ãç¹å¥ãªæªçœ®ãè¬ããªãå ŽåãCOMããŒãçµç±ã§éä¿¡ãããè¡ãã¹ãããã§ããããšã§ããã€ãŸããè¡ãã·ãªã¢ã«ããŒãã«éåžžã«æ©ãå°çããAjaxèŠæ±ãããŸãé »ç¹ã«å±ããªãå Žåããªã¯ãšã¹ãéã®ãã¹ãŠã®è¡ã¯ã¯ã©ã€ã¢ã³ãã«è¡šç€ºãããŸããã ããããããšãã°çŸåšã®æž©åºŠã衚瀺ããã¿ã¹ã¯ã®å Žåãããã¯ãŸã£ããæãããšã§ã¯ãããŸããã
ããããWebSocketsãã¯ãããžãŒã䜿çšã§ããŸãããIEã§ç解ããŠããããã«ãIEã§ã¯10çªç®ã®ããŒãžã§ã³ãããããµããŒããããŠããããIE 8ãæã£ãŠããã®ã§ããã®æ¹åãèãåºãããšããããŸããã§ããã
å æ¥ãHabrãŸãã¯Giktaymsã®èšäºã®1ã€ã§ãWebSocketã®äžè¶³ãåé¿ã§ããããã«æãããSockJSã©ã€ãã©ãªãŒã«ã€ããŠèšåããŸãããããŸããç¹å¥ãªã©ã€ãã©ãªãŒãå¿ èŠã§ãã ãµããŒãã¯ãµãŒããŒåŽã§è¡ãããŸãã2çªç®ã«ããã®æç¹ã§Ajaxã¯æ£åžžã«æ©èœããŠãããããæ°ä»ãããªããŸãŸã§ããã
ããã§ãAjaxã ãããããããç§ã¯ãã®æè¡ãåŠãŒããšããŸããã ããããç§ã«åºäŒã£ããã¹ãŠã®çŽã®æç§æžã¯ããŸãã«ãéå±ã§ãããç§ã¯ããã«ãã®ããžãã¹ãäžéããŸããã ãããããã§ã«è¿°ã¹ãw3schools.comã§ã¯ããã¥ãŒããªã¢ã«ã¯éåžžã«åªããŠããããšãå€æããŸããã ãã®çµæã次ã®ã³ãŒãã¯ããã«å€æããŸããã
function get_data() { var xmlhttp; xmlhttp=new XMLHttpRequest(); xmlhttp.open("GET","/get_serial?r=" + Math.random(),true); xmlhttp.onreadystatechange=function() { if (xmlhttp.readyState==4 && xmlhttp.status==200) { document.getElementById("data").innerHTML=xmlhttp.responseText; get_data(); } } xmlhttp.send(); }
ããŒãžãããŒãããããšãã«åŒã³åºãããŸããïŒ
<body onload="get_data()">
ãã®ã³ãŒãã§ã¯ããããã2ã€ã®ç¹ã«æ³šæããå¿ èŠããããŸãã ãŸããã©ã€ã³ãž
xmlhttp.open("GET","/get_serial?r=" + Math.random(),true);
ãã®äžã§ãCOMããŒããã次ã®è¡ã§WebãµãŒããŒã«ã¢ã¯ã»ã¹ããŸãã è£è¶³
r=" + Math.random()
Internet Explorerãå¿çããã£ãã·ã¥ããªãããã«ããããã«å¿ èŠã§ãã ãã以å€ã®å Žåã¯ãAjaxèŠæ±ã1ã€ã ãéä¿¡ããå¿çãåä¿¡ããŠââããµãŒããŒã«ã¢ã¯ã»ã¹ããªããªããŸãã ã€ã³ã¿ãŒãããã§ã¯ããµãŒããŒåŽããç¹å¥ãªHTTPããããŒãéä¿¡ããããšã§ããã£ãã·ã¥ã®åé¡ã®è§£æ±ºçãèŠãŸãã
response.headers['Last-Modified'] = datetime.now() response.headers['Cache-Control'] = 'no-store, no-cache, must-revalidate, post-check=0, pre-check=0, max-age=0' response.headers['Pragma'] = 'no-cache' response.headers['Expires'] = '-1'
ããããäœããã®çç±ã§ããã¯ç§ã«ã¯ããŸããããŸããã§ããã
å¥ã®æ¹æ³ã¯ãGETã®ä»£ããã«POSTã䜿çšããããšã§ãã IEã¯ãã®ãããªãªã¯ãšã¹ãããã£ãã·ã¥ããªããšèšã£ãŠããŸãããç§ã¯ãã§ãã¯ããŸããã§ããã
ãšããã§ãjQueryã¯ãã£ãã·ã¥ãšæŠãããã«ãŸã£ããåãæ¹æ³ã䜿çšããŸã-ãŸããURLã«ã©ã³ãã ãªæååãè¿œå ããŸãã å°ãéã£ãŠèŠããŸãã
2çªç®ã®ãã€ã³ãã¯äžé£ã®è¡ã§ã
xmlhttp.open("GET","/get_serial?r=" + Math.random(),true);
ãããŠ
xmlhttp.onreadystatechange=function() ...
åœåã圌ãã¯ç°ãªãé åºã§ç«ã£ãŠããŸããã ãŸããInternet Explorerã§ã¯ãããã«ããå¥åŠãªåé¡ãçºçããŸãã-圌ã¯å©çšå¯èœãªã¡ã¢ãªããã¹ãŠäœ¿ãæãããŠããŸããã ãããŠãã®åŸãããŒã¿ãæŽæ°ããŸããã 圌ã¯åœŒã®ä»äºãçµããã
XmlHttpRequest.ruã®ãµã€ãã§ã®ã¿ãXMLHttpRequestãªããžã§ã¯ããåå©çšãããšãã«ãæåã«openïŒïŒã¡ãœãããåŒã³åºããŠãããonreadystatechangeããããã£ãå€æŽããããšããå§ãããŸãã
IEã§å€ãã®åé¡ãçªç¶çºçããããããã®ãããªãã¥ã¢ã³ã¹ãèæ ®ãããå¯èœæ§ãæãé«ãã©ã€ãã©ãªã䜿çšããããšã«ããŸããã jQueryã¯ãã§ã«Bootstrapã®ããŒãžã«ããŒããããŠãããã
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
ãã®ã©ã€ãã©ãªã«çµã¿èŸŒãŸããAjaxãµããŒãã䜿çšããããšã¯æ³šç®ã«å€ããªããšå€æããŸããã ãããã£ãŠãããŒã¿æŽæ°ã³ãŒãã¯æ¬¡ã®ããã«å€æãããŸããã
function on_load(responseTxt, statusTxt, xhr){ if( statusTxt == "success" ){ $("#data").load("/get_serial?r=" + Math.random(), on_load ) } else { $("#data").text( "Error: " + xhr.status + ": " + xhr.statusText ); } } $(document).ready(function(){ on_load("", "success", 3); });
äžåºŠã«1人ã®ã¯ã©ã€ã¢ã³ã
åã®èšäºã§ããã®åé¡ã解決ããå¯èœãªæ¹æ³ã«ã€ããŠæ¢ã«æžããŠããŸããããã¯ãšã³ãã2ã€ã®éšåã«åå²ããZMQã䜿çšããŠããããéä¿¡ãã2çªç®ã®éšåãšããŠãã«ããŠãŒã¶ãŒhttpãµãŒããŒã䜿çšããŸãã ãã®ãããªãµãŒããŒãšããŠFlaskãéžæããŸããã ç§ã¯ä»£æ¿æ¡ãæ¯èŒããŸããã§ããã圌ã¯æåã«ç§ã«çããŸããã http-requestsã®äžŠååŠçã¢ãŒãã§èµ·åã§ããããšãå€æããããã§ååã§ããããšãå€æããŸããã ãã®ã¢ãŒããéå§ããã«ã¯ããã©ã¡ãŒã¿ãæž¡ãã ãã§ã
threaded = TrueïŒ stackoverflow.com/questions/14672753/handling-multiple-requests-in-flaskãåç §ïŒïŒ
app.run(host='0.0.0.0', debug=False, threaded=True)
ãã«ãã¹ã¬ããã«å ããŠãFlaskã¯éåžžã«äŸ¿å©ãªã«ãŒãã£ã³ã°ã¡ã«ããºã ãæäŸããŸãã ç¹å®ã®httpãªã¯ãšã¹ããžã®åã ã®æé ã®å¯Ÿå¿ã ãããã£ãŠãã·ã³ãã«ãªWebã¢ããªã±ãŒã·ã§ã³ãäœæããããã«ãFlaskã¯éåžžã«äŸ¿å©ã§ãã
ããããäœãããZMQã©ã€ãã©ãªã«ã€ããŠã話ãããããšæããŸã-ãã®é©ãã¹ãæ©èœãå®èšŒããããã«ã
ãã¢ZMQãµãŒããŒã®ã³ãŒãã¯æ¬¡ã®ãšããã§ãã
import zmq import time context = zmq.Context.instance() pub_sock = context.socket(zmq.PUB) pub_sock.bind( 'tcp://*:12345' ) count = 0 def get_full_line_from_serial(): global count count += 1 return time.strftime( '%Y.%m.%d %H:%M:%S' ) + ': string N %d' % count while True: line = get_full_line_from_serial() print line pub_sock.send( line ) time.sleep(1)
COMããŒãããã®èªã¿åããã·ãã¥ã¬ãŒãããŸãã å®éã圌ã¯1ç§ããšã«æ°ããè¡ãçæããããããå ¬éãïŒã€ãŸãããµãã¹ã¯ã©ã€ãããããã¹ãŠã®ã¯ã©ã€ã¢ã³ãã«éä¿¡ïŒãããããã°çšã«åºåããŸãã
æ°Žã¯ã©ã€ã¢ã³ãã³ãŒãïŒ
import zmq context = zmq.Context.instance() zmq_sub_sock = context.socket(zmq.SUB) zmq_sub_sock.setsockopt(zmq.SUBSCRIBE, '') zmq_sub_sock.connect( 'tcp://localhost:12345' ) poller = zmq.Poller() poller.register( zmq_sub_sock, zmq.POLLIN ) while True: socks = dict(poller.poll(timeout=5000)) if zmq_sub_sock in socks: print zmq_sub_sock.recv() else: print 'No data within 5 sec'
ZMQãœã±ãããéããèãããããã¹ãŠã®ã¡ãã»ãŒãžããµãã¹ã¯ã©ã€ããããµãŒããŒã«æ¥ç¶ããŸãã 次ã«ãç¡éã«ãŒãã§æ°ããããŒã¿ãäºæããŠè¡šç€ºããŸãã
ãããŠãããã«åœŒãã®ã³ã©ãã¬ãŒã·ã§ã³ã®ãã¢ããããŸãïŒ
泚ç®ãããããšã ãŸãããµãŒããŒãèµ·åããåã«ã¯ã©ã€ã¢ã³ããèµ·åã§ããŸãã ãããŠãããã¯ããã©ãŒãã³ã¹ã«åœ±é¿ããŸããã 第äºã«ããµãŒããŒãã¯ã©ãã·ã¥ããŠãã¯ã©ã€ã¢ã³ãã¯ã¯ã©ãã·ã¥ããŸããããµãŒããŒãåèµ·åãããšããã«ãã¯ã©ã€ã¢ã³ãã¯ãµãŒããŒããã¡ãã»ãŒãžãåä¿¡ãå§ããŸãã çŽ æŽãããã§ãã ãããŠãããã«ã¯ãã¯ã©ã€ã¢ã³ããšãµãŒããŒã®ãœãŒã¹ã³ãŒãã«ç¹å¥ãªæ瀺ããŸã£ãããããŸããã éåžžã®TCP / IPãœã±ããã䜿çšããå Žåããã®ãããªæ©èœãå®è£ ããããã«èªåã§èšè¿°ããå¿ èŠãããã³ãŒãã¯ã©ããããã§ããïŒ
ãããŠãããã¯ZMQã©ã€ãã©ãªãã§ããããšã®ã»ãã®äžéšã§ãã ç¹°ãè¿ãã«ãªããŸããããã®ã©ã€ãã©ãªãããèŠãããšã匷ããå§ãããŸãã
ã¹ã¿ã³ãã¢ãã³ã¢ããª
ç§ã¯ãPythonãã¹ã¿ã³ãã¢ãã³ã®ã¢ããªã±ãŒã·ã§ã³ãäœæããã®ã«ããŸãé©å¿ããŠããªãããšããã§ã«è¿°ã¹ãããã§ãã ããã¯ã€ã³ã¿ããªã¿èšèªã§ãããã€ã³ã¿ããªã¿ããã°ã©ã ãæ£åžžã«æ©èœããå¿ èŠããããŸãã 圌ã«ãšã£ãŠæ®å¿µãªããšã«ããã€ãã£ããã€ããªã³ãŒããçæã§ããã³ã³ãã€ã©ã¯ãããŸããã ã¹ã¯ãªããããäžçš®ã®ç¬ç«ããã¢ããªã±ãŒã·ã§ã³ãäœæã§ãã2ã€ã®ããã°ã©ã ãpy2exeãšpyInstallerãç¥ã£ãŠããŸãã ç§èªèº«ã¯2çªç®ã®ãã®ããã䜿çšããããããã®ãããžã§ã¯ãã§äœ¿çšããããšã«ããŸããã
pyInstallerã¯Pythonã¹ã¯ãªãããååŸããäŸåãããã¹ãŠã®ãã¡ã€ã«ãåæãïŒã€ã³ããŒãããããã¹ãŠã®ã¢ãžã¥ãŒã«ãšãã©ã°ã€ã³ã®åçã©ã€ãã©ãªã決å®ããŸãïŒããããããã¹ãŠåå¥ã®ãã©ã«ããŒã«åéããããèªå·±è§£åã¢ãŒã«ã€ãã®é¡äŒŒç©ã«ããã¯ããŸãã ã€ã³ã¿ãŒããªã¿ãŒèªäœã®ã³ãŒããšãèµ·åæã«ã©ã³ã¿ã€ã ãæºåããŠã¿ãŒã²ããã¹ã¯ãªããã®è§£éãéå§ããå°ããªéå§éšåãè¿œå ãããŸãã
Pythonã®äœæè ãã©ã€ãã©ãªã®äœæè ããPythonã®ãã®ãããªäœ¿çšã®å¯èœæ§ã«ã€ããŠèããŠããªãã£ãããããã¹ãŠã¯ãåãæ ªããããä»ããŠãæ©èœããŸãã äž»ãªåé¡ã¯ãå¿ èŠãªãã¹ãŠã®ã©ã€ãã©ãªãšã¢ãžã¥ãŒã«ã®ãªã¹ããæºåããããšã§ãã å€ãã®ã©ã€ãã©ãªäœæè ãæé»çãªã€ã³ããŒãã䜿çšããŠãããããã©ã®ã¢ãžã¥ãŒã«ãã¹ã¯ãªãããŸãã¯å¥ã®ã¢ãžã¥ãŒã«ã«ã€ã³ããŒããããããæ瀺çã«ç€ºãããšã¯ãããŸããã ãããã£ãŠãå€ãã®å ŽåãpyInstallerã«ããã¹ã¯ãªããã®èªååæã®åŸãè¿œå ã®ã¢ãžã¥ãŒã«ã®ååããã³/ãŸãã¯ããããæ€çŽ¢ãããã¹ãæ§æãã¡ã€ã«ïŒæ¡åŒµå.specïŒã«æåã§è¿œå ããå¿ èŠããããŸãã pyInstallerãšäžç·ã«ããã®ãããªã©ã€ãã©ãªã®ããã®æ¢è£œã®é¢æ°ã®å€§èŠæš¡ãªã»ããããããŸããã人çã¯ãŸã ãããŸããã ç¹ã«ãããã¯ZMQã®çŸåšã®ããŒãžã§ã³ã§èµ·ãããŸãã-pyZMQïŒPythonãžã®ZMQãã€ã³ãã£ã³ã°ïŒã®éçºè ã¯ãè£å©ã©ã€ãã©ãªã®ã€ã³ããŒãã¡ã«ããºã ãå€æŽããŸããããã®çµæãpyInstallerã«ãã£ãŠæ§ç¯ãããã¢ããªã±ãŒã·ã§ã³ã¯èµ·åããŸããã 人ã ã¯ãã§ã«ãã®åé¡ã«å¯ŸåŠããŠãããpyInstallerã«å¯Ÿå¿ããããããæºåããŠããŸãã ãã®ãããã¯æ©èœããŠããŸãããå ¬åŒãªãªãŒã¹ã«ã¯ãŸã å«ãŸããŠããªããããpyInstallerã«èªåã®æã§ããããé©çšããå¿ èŠããããŸããã github.com/pyinstaller/pyinstaller/pull/110/filesã«ãããããã³ãŒããåç §ããŠãã ããã
ãã ããã¹ã¿ã³ãã¢ãã³ã¢ããªã±ãŒã·ã§ã³ããã©ã«ããŒå šäœã§ã¯ãªã1ã€ã®å®è¡å¯èœãã¡ã€ã«ã®ã¿ã§æ§æãããå Žåããã®ãããã§ããååã§ã¯ãããŸããã§ããã .exeãã¡ã€ã«ã解åãããšãã«ZMQãã£ã¹ããªãã¥ãŒã·ã§ã³ã®libsodium.pydã©ã€ãã©ãªãæ£ããå Žæã«æ¥ãããã«ãæåã§.specãã¡ã€ã«ãä¿®æ£ããå¿ èŠããããŸããã
2çªç®ã®åé¡ã¯ããã«ãããã»ãã·ã³ã°ã¢ãžã¥ãŒã«ã§ããã ããã¯ãšã³ãã2ã€ã®éšåã«åå²ããŸããããããã¯äžŠè¡ããŠåäœããã¯ãã§ãã ããã¯ãšã³ããå®è¡ããããã«2ã€ã®å¥åã®ããã°ã©ã ãå®è¡ããå¿ èŠãããå Žåãããã¯ééã£ãŠããããã«æããŸããã ãŸãããã«ãã¹ã¬ããã䜿çšããããšã¯ãGILïŒGlobal Interpretation LockïŒã®ååšã®ããã«ééã£ãŠããããã«æãããŸããã èµ·åæã«åçŽã«2ã€ã®æ°ããããã»ã¹ãçæããåçŽãªã¹ã¯ãªãããäœæããæ¹ãç°¡åã«æããŸãã1ã€ã¯COMããŒãããããŒã¿ãèªã¿åãZMQãµãŒããŒçšããã1ã€ã¯Webã¯ã©ã€ã¢ã³ãããã®ãªã¯ãšã¹ãã«å¿çããHTTPãµãŒããŒçšã§ãã å®éãéåžžã¢ãŒãã§äœæ¥ãããšãïŒã€ãŸããã€ã³ã¿ãŒããªã¿ãŒããæåã§ãéå§ããããšãïŒã次ã®ã¹ã¯ãªããã¯æ£åžžã«æ©èœããŸãã
# -*- coding: utf-8 -*- from multiprocessing import Process import serial_to_zmq import zmq2web_using_flask import time def main(): args = get_command_line_params() p1 = Process( target=serial_to_zmq.work, args=(args.serial_port_name, args.serial_port_speed, args.zmq_pub_addr) ) p1.start() p2 = Process(target=zmq2web_using_flask.work, args=(args.zmq_sub_addr,)) p2.start() print 'Press Ctrl+C to stop...', while True: time.sleep(10) def get_command_line_params(): ... if __name__ == '__main__': main()
ããããpyInstallerã§åŠçããåŸãçµæã®.exeã¯æ£åžžã«æ©èœããŸããã§ããã ããã€ãã®ZMQãµãŒããŒãšFlaskã¢ããªã±ãŒã·ã§ã³ããããœã±ããããã§ã«äœ¿çšãããŠããŸãããšããã¡ãã»ãŒãžãšãã®ä»ã®å¥åŠãªã¡ãã»ãŒãžãšãšãã«èµ·åãããŸããã Flaskã¢ããªã±ãŒã·ã§ã³ãèµ·åãããšãã«ãdebug = Falseãã©ã¡ãŒã¿ãŒãæž¡ãå¿ èŠãããããšãå€æããŸããã
app.run(host='0.0.0.0', debug=False, threaded=True)
ãŸãããã«ãããã»ãã·ã³ã°ã¢ãžã¥ãŒã«ã®å ŽåãpyInstallerã§äœæãããã¹ã¿ã³ãã¢ãã³ã¢ããªã±ãŒã·ã§ã³ã®å Žåã«ã¹ã¯ãªããã解éããããšãã«äœæãããããã®ã¢ãŒãïŒfroozenïŒã§å¿ èŠãªç¹æ®é¢æ°freeze_supportïŒïŒãåŒã³åºãå¿ èŠããããŸãã
äžè¬çã«ããã®é ç®ã®çµæã¯æ¬¡ã®ãšããã§ããPythonã¹ã¯ãªããããã¹ã¿ã³ãã¢ãã³ã¢ããªã±ãŒã·ã§ã³ãäœæã§ããŸãããç°¡åã§ã¯ãããŸããã
ãã¹ãŠã®ãœãŒã¹ã³ãŒãã¯githubã§ååŸã§ããŸãïŒ github.com/alguryanow/serial2web-2
PS Another Bootstrapãã¥ãŒããªã¢ã«ïŒ www.tutorialrepublic.com/twitter-bootstrap-2.3.2-tutorial