Publicidad

WordPressでIoTをはじめよう

WordPress Plugin Developer
20 de Apr de 2019
Publicidad

Más contenido relacionado

Publicidad
Publicidad

WordPressでIoTをはじめよう

  1. AQSF SGTTe Q?t jbnp CS Q? J AQSF SGTT
  2. P GSPG QH ?J PIT iw
  3. gueo 1WGS J PI QP PG QSM
  4. J N RT VG
  5. S Q 7QEM
  6. _ QRVNCS TOCNN EQORV GST Q/ AG IJ S EG
  7. A SGNGTT GEJPQNQI
  8. SQ QEQN
  9. 1 ? -
  10. A i t : : P G A FC C {"id":1,
 "date":"2017-05-23T06:25:50",
 "date_gmt":"2017-05-23T06:25:50",
 "guid":{"rendered":"http://demo.wp-api.org/?p=1"},
 "modified":"2017-05-23T06:25:50",
 "modified_gmt":"2017-05-23T06:25:50",
 "slug":"hello-world",
 "status":"publish",
 "type":"post",
 "link":"https://demo.wp-api.org/2017/05/23/hello-world/",
 "title":{"rendered":"Hello world!"},
 "content":{"rendered":"<p>Welcome to...
  11. x w i 1PFRQ P T
  12. y /VT QO G CWC NCDNG
  13. x w G GPFRQ P add_action( 'rest_api_init', function () { register_rest_route( 'anything/v1', '/get', array( 'methods' => 'GET', 'callback' => 'get_anything_awesome', ) ); } ); function get_anything_awesome() { $data = array('result' => 'great data'); return new WP_REST_Response( $data, 200 ); }
  14. - GTRQPTG http://example.net/wp-json/ anything/v1/get {"result":"great data"}
  15. 710 710 -F CPGN
  16. CSF CSG
  17. CTRDGSS 
 

  18. CTRDGSS 
 

  19. 710 C S CPGN
  20. . C S .QPPG
  21. t dg GS ECN EQPPGE NCPFTECRG RCPGN
  22. QH CSG 
 

  23. CTRD CP 7 G
  24. : G PIT
  25. .VSP :
  26. 1 EJGS
  27. -RRNG .CMGS
  28. /QPH I
  29. PT CNN CEMCIGT $ sudo apt install git libgraphicsmagick++-dev libwebp-dev
  30. . 710 C S
  31. OCMG $ git clone https://github.com/ hzeller/rpi-rgb-led-matrix $ cd rpi-rgb-led-matrix $ make -C examples-api-use $ cd utils $ make led-image-viewer
  32. 0GOQ $ cd example-api-use $ sudo ./demo 
 --led-gpio-mapping=adafruit-hat --led-no-hardware-pulse --led-chain=4 -L 
 -D 0
  33. sk 0 TRNC ACRVV
  34. sk t /QNNGE ACRVV OCIGT
  35. h lr -SSCPIG Q NCPFTECRG
  36. ESQNN 0GOQ $ sudo ./demo 
 --led-gpio-mapping=adafruit-hat --led-no-hardware-pulse --led-chain=4 -L 
 -D 1 ../../images/wapuu.ppm
  37. - -FF -
  38. A - e OCIG /JCPIG -
  39. /VT QO 1PF Q P /wp-json/wapuu/v1/set/NNN /wp-json/wapuu/v1/get
  40. x w -FF GPF RQ P add_action( 'rest_api_init', function () { register_rest_route( 'wapuu/v1', '/set/(?P<id>d+)', array( 'methods' => 'POST', 'callback' => 'set_wapuu_image', 'args' => array( 'id' => array( 'validate_callback' => function($param, $request, $key) { return is_numeric( $param ); } ), ), ) ); register_rest_route( 'wapuu/v1', '/get', array( 'methods' => 'GET', 'callback' => 'get_wapuu_image', ) ); } );
  41. t CWG& G OCIG PVODGS function set_wapuu_image( $data ) { $id = $data['id']; update_post_meta( 60, 'wapuu-image', $id ); $data = array( 'id' => $id ); return new WP_REST_Response( $data, 200 ); } function get_wapuu_image() { $id = get_post_meta( 60, 'wapuu-image'); $data = array( 'id' => $id ); return new WP_REST_Response( $data, 200 ); }
  42. - GTRQPTG http://example.net/wp-json/ wapuu/v1/get {"id":"001"}
  43. JQP EQFG QP CT
  44. - p G OCIG PVODGS api="http://example.net/wp-json/wapuu/v1/get" def img_number(): try: html = urllib.urlopen( api ).read() except: return None data = json.loads(html) return data['id']
  45. e t c G S WG OCIG D PVODGS image_dir = "~/wapuu/" viewer = "~/rpi-rgb-led-matrix/utils/led-image-viewer" opt = " --led-daemon --led-gpio-mapping=adafruit-hat" + " --led-no-hardware-pulse --led-chain=4 -L" prev = None while True: time.sleep(2) number = img_number() if number is None: continue files = glob.glob(image_dir+number+"-*.png") if len(files) < 1: continue if files[0] == prev: continue if prev is not None: kill_img() commands.getstatusoutput("sudo "+viewer+opt+files[0]) prev = files[0]
  46. j t c ?VSP QHH OCIG JGP EJCPIG pattern = r"^ *(d+) .*/led-image-viewer" def kill_img (): id = [] ps_list = commands.getoutput('ps awx') for process in ps_list.split("n"): match = re.match(pattern, process) if not match: continue id.append(match.group(1)) commands.getoutput("sudo kill "+" ".join(id))
  47. GNGE CIG <form method="post" action="/wp-json/wapuu/v1/set/001"> <div>[caption id="attachment_40" align="alignleft" width="150"] <img src="/wp-content/uploads/ 2017/09/001-original-150x150.png" alt="001" width="150" height="150" class="size-thumbnail wp-image-40" /> Original (WordCamp 2011 Fukuoka)<br> <button type="submit" value="001">
 Submit</button> [/caption]</div></form>
  48. z ?GORGSC VSG& VO F 7QIIGS
  49. GPTG -? 

  50. GPTG -? 

  51. 1PW SQ R -?
  52. 1PW SQ R -?
  53. GCTVSG GORGSC VSG&JVO F from sense_hat import SenseHat sense = SenseHat() temp = sense.get_temperature() print("Temperature: %s C" % temp) humi = sense.get_humidity() print("Humidity: %s %%rH" % humi)
  54. h /QPWGS P Q F TEQOHQS PFG 0.81Td +0.01H(0.99Td -14.3) +46.3 Td: Temp (℃) H: Humidity
  55. AQSF SGTTe 7QI J AQSF SGTT
  56. e CMG ISCRJ D
  57. AQSF SGTT CT 0C C QSG
  58. /VT QO QT ? RG J RT &&EQFG QSFRSGTT QSI&RQT B RG add_action( 'init', 'create_fever_log_type' ); function create_fever_log_type() { register_post_type( 'fever_log', array( 'labels' => array( 'name' => __( 'Fever' ), 'singular_name' => __( 'Fever' ) ), 'public' => true, 'has_archive' => true, ) ); }
  59. HGSWGSBNQI RG 

  60. /SGC G -
  61. /VT QO 1PF Q P 
 /wp-json/fever/v1/log 
 /wp-json/fever/v1/history
  62. x w -FF GPF RQ P add_action('rest_api_init', function () { register_rest_route('fever/v1', '/log/', array( 'methods' => 'POST', 'callback' => 'log_fever_value', ) ); register_rest_route('fever/v1' '/history/', array( 'methods' => 'GET', 'callback' => 'get_fever_history', ) ); } );
  63. t "( 7QI GOR JVO F function log_fever_value() { $obj = json_decode($_POST); $t = $obj['temp']; $h = $obj['humi']; $data = array(); if (! is_numeric($t) || ! is_numeric($h) ) { return new WP_REST_Response($data, 400); } $json=json_encode(array('temp'=>$t,'humi'=>$h)); $discomf = $t*0.81+$h*($t*0.99-14.3)*0.01+46.3;
  64. t ") 7QI GOR JVO F $post = array( 'post_type' => 'fever_log', 'post_name' => 'fever_log', 'post_content' => $json, 'post_title' => $discomf, ); $post_ID = wp_insert_post($post); if (! $post_ID ) { return new WP_REST_Response($data, 500); } $data['post_ID'] = $post_ID; return new WP_REST_Response($data, 200); }
  65. HGWGS NQI RQT
  66. t m a"( GCF F TEQOHQS PFG GT function get_fever_history() { $num = 360; $args = array ( 'post_type' => 'fever_log', 'numberposts' => $num, 'offset' => 0, 'orderby' => 'date', 'order' => 'ASC', ); $posts = get_posts($args);
  67. t m a") GCF F TEQOHQS PFG GT $data = array(); foreach ( $posts as $p ) { setup_postdata( $p ); $data[] = array( 'date' => get_the_date('Y/m/d H:i:s'), 'discomfort' => floatval(get_the_title()), ); } return new WP_REST_Response($data,200); }
  68. & R LTQP&HGWGS&W(&J T QS [ {"datetime":"2018/06/01 22:25:11", "discomfort":83.0214384153}, {"datetime":"2018/06/01 22:25:35", "discomfort":83.3682958288}, {"datetime":"2018/06/02 09:12:00", "discomfort":82.3637111865} ]
  69. 7QII PI QP CT
  70. t GPF GOR&JVO F #!/usr/bin/python api="http://example.net/wp-json/fever/v1/log" import requests from sense_hat import SenseHat sense = SenseHat() temp = sense.get_temperature() humi = sense.get_humidity() env = '{"temp":%f, "humi":%f}' % (temp, humi) response = requests.post(api, env, headers={'Content-Type': 'application/json'} )
  71. h GPF RGS QF ECNN $ crontab -e */5 * * * * /home/pi/log-env.py {"temp":30.190403, "humi":41.724270}
  72. CMG SCRJ
  73. SCRJ 7 DT
  74. C E ? 7 <html><head> <script type="text/javascript" src="dygraph.js"> </script> <link rel="stylesheet" src="dygraph.css" /> </head> <body> <div id="graphdiv"></div> <script type="text/javascript"> g = new Dygraph( document.getElementById("graphdiv"), // CSV data. ); </script> </body> </html>
  75. HVPE QPT RJR add_action('wp_enqueue_scripts','dygraph_styles'); function dygraph_styles() { wp_enqueue_style( 'child-style', get_stylesheet_directory_uri().'/dygraph.css'); wp_enqueue_script( 'dygraph', get_stylesheet_directory_uri().'/dygraph.js'); }
  76. RQT BEQP GP <div id="graphdiv"></div> <script type="text/javascript"> g = new Dygraph( // containing div document.getElementById("graphdiv"), // CSV or path to a CSV file. "Time,Fevern" + "2018-06-02 10:15:07,77.258414n" + "2018-06-02 10:16:08,77.554262n" + "2018-06-02 10:17:10,77.680172n" + "2018-06-02 10:18:02,77.825666n" + "2018-06-02 10:20:04,78.359325n" + "2018-06-02 10:25:03,79.242797n" ); </script>
  77. ?:0: 
 
 

  78. 2N IJ SCFCS
  79. JQ FQGT QSM
  80. CSF CSG 

  81. v
  82. QH CSG
  83. fjA e
  84. w
  85. http://www.yuriko.net/ @lilyfanjp J RT && TN FGTJCSG PG & N N HCP& QSFRSGTT Q J RT &&I JVD EQO&N N HCPLR& QSFHGT) ( TCORNG
Publicidad