{"id":962,"date":"2015-08-16T03:34:06","date_gmt":"2015-08-15T18:34:06","guid":{"rendered":"https:\/\/hack.gpl.jp\/?p=962"},"modified":"2015-08-16T03:34:06","modified_gmt":"2015-08-15T18:34:06","slug":"post-962","status":"publish","type":"post","link":"https:\/\/hack.gpl.jp\/2015\/08\/16\/post-962.html","title":{"rendered":"ESP-12\u3067raspi2\u306e\u30b7\u30ea\u30a2\u30eb\u30b3\u30f3\u30bd\u30fc\u30eb\u3092WiFi\u5316"},"content":{"rendered":"

\u524d\u304b\u3089\u3001\u8208\u5473\u304c\u3042\u3063\u305f\u900f\u904e\u578b\u306eUART\u30fcWiFI\u30d6\u30ea\u30c3\u30b8\u7684\u306b\u4f7f\u3046\u65b9\u6cd5\u3092\u3042\u308c\u3053\u308c\u8a66\u3057\u3066\u3044\u307e\u3057\u305f\u3002<\/p>\n

\u7d50\u8ad6\u304b\u3089\u8a00\u3048\u3070\u3001\u51fa\u6765\u307e\u3057\u305f\u3002<\/p>\n

\u3053\u3093\u306a\u611f\u3058\u3067\u3001\u96fb\u6e90\u306fRasPi2 \u304b\u3089\u53d6\u3063\u3066\u3044\u307e\u3059\u306e\u3067\u84cb\u306e\u4e2d\u306b\u53ce\u3081\u3089\u308c\u305d\u3046\u3067\u3059\u3002<\/p>\n

\"uart-wifi\" <\/p>\n

ESP-12 \u306b\u53ce\u3081\u308b\u30d7\u30ed\u30b0\u30e9\u30e0\u306f\u3001\u306a\u3093\u3068\u30b5\u30f3\u30d7\u30eb\u30b9\u30b1\u30c3\u30c1\u306e\u4e2d\u306b\u3042\u308a\u307e\u3057\u305f\u3002WiFiTelnetToSerial \u3067\u3059\u3002 <\/p>\n

\/*\nWiFiTelnetToSerial - Example Transparent UART to Telnet Server for esp8266<\/p>\n

Copyright (c) 2015 Hristo Gochkov. All rights reserved.\nThis file is part of the ESP8266WiFi library for Arduino environment.<\/p>\n

This library is free software; you can redistribute it and\/or\nmodify it under the terms of the GNU Lesser General Public\nLicense as published by the Free Software Foundation; either\nversion 2.1 of the License, or (at your option) any later version.<\/p>\n

This library is distributed in the hope that it will be useful,\nbut WITHOUT ANY WARRANTY; without even the implied warranty of\nMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\nLesser General Public License for more details.<\/p>\n

You should have received a copy of the GNU Lesser General Public\nLicense along with this library; if not, write to the Free Software\nFoundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA\n*\/<\/p>\n

include <ESP8266WiFi.h><\/h1>\n

\/\/how many clients should be able to telnet to this ESP8266<\/p>\n

define MAX_SRV_CLIENTS 1<\/h1>\n

const char ssid = "yyyyy";\nconst char<\/em> password = "xxxxx";<\/p>\n

WiFiServer server(23);\nWiFiClient serverClients[MAX_SRV_CLIENTS];<\/p>\n

void setup() {\nSerial1.begin(115200);\nWiFi.begin(ssid, password);\nSerial1.print("\\nConnecting to "); Serial1.println(ssid);\nuint8_t i = 0;\nwhile (WiFi.status() != WL_CONNECTED && i++ < 20) delay(500);\nif(i == 21){\nSerial1.print("Could not connect to"); Serial1.println(ssid);\nwhile(1) delay(500);\n}\n\/\/start UART and the server\nSerial.begin(115200);\nserver.begin();\nserver.setNoDelay(true);<\/p>\n

Serial1.print("Ready! Use 'telnet ");\nSerial1.print(WiFi.localIP());\nSerial1.println(" 23' to connect");\n}<\/p>\n

void loop() {\nuint8_t i;\n\/\/check if there are any new clients\nif (server.hasClient()){\nfor(i = 0; i < MAX_SRV_CLIENTS; i++){\n\/\/find free\/disconnected spot\nif (!serverClients[i] || !serverClients[i].connected()){\nif(serverClients[i]) serverClients[i].stop();\nserverClients[i] = server.available();\nSerial1.print("New client: "); Serial1.print(i);\ncontinue;\n}\n}\n\/\/no free\/disconnected spot so reject\nWiFiClient serverClient = server.available();\nserverClient.stop();\n}\n\/\/check clients for data\nfor(i = 0; i < MAX_SRV_CLIENTS; i++){\nif (serverClients[i] && serverClients[i].connected()){\nif(serverClients[i].available()){\n\/\/get data from the telnet client and push it to the UART\nwhile(serverClients[i].available()) Serial.write(serverClients[i].read());\n}\n}\n}\n\/\/check UART for data\nif(Serial.available()){\nsize_t len = Serial.available();\nuint8_t sbuf[len];\nSerial.readBytes(sbuf, len);\n\/\/push UART data to all connected telnet clients\nfor(i = 0; i < MAX_SRV_CLIENTS; i++){\nif (serverClients[i] && serverClients[i].connected()){\nserverClients[i].write(sbuf, len);\ndelay(1);\n}\n}\n}\n}<\/pre>\n<\/p>\n

ArduinoIDE \u3078\u3001ESP8266 Arduino Core \u306e\u6700\u65b0\uff08ver. 1.6.5-1044-g170995a, built on Aug 10, 2015\uff09\u3092\u53ce\u3081\u307e\u3057\u305f\u3002<\/p>\n

SDK1.3 \u304c\u53ce\u307e\u3063\u305f\u3082\u306e\u306f\u3001\u4ee5\u4e0b\u306eStaging version\u304b\u3089\u5165\u308c\u307e\u3057\u305f\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"

\u524d\u304b\u3089\u3001\u8208\u5473\u304c\u3042\u3063\u305f\u900f\u904e\u578b\u306eUART\u30fcWiFI\u30d6\u30ea\u30c3\u30b8\u7684\u306b\u4f7f\u3046\u65b9\u6cd5\u3092\u3042\u308c\u3053\u308c\u8a66\u3057\u3066\u3044\u307e\u3057\u305f\u3002 \u7d50\u8ad6\u304b\u3089\u8a00\u3048\u3070\u3001\u51fa\u6765\u307e\u3057\u305f\u3002 \u3053\u3093\u306a\u611f\u3058\u3067\u3001\u96fb\u6e90\u306fRasPi2 \u304b\u3089\u53d6\u3063\u3066\u3044\u307e\u3059\u306e\u3067\u84cb\u306e\u4e2d\u306b\u53ce\u3081\u3089\u308c\u305d\u3046\u3067\u3059\u3002 ESP-12 […]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"_uag_custom_page_level_css":"","footnotes":""},"categories":[30,69],"tags":[],"acf":[],"uagb_featured_image_src":{"full":false,"thumbnail":false,"medium":false,"medium_large":false,"large":false,"1536x1536":false,"2048x2048":false,"post-thumbnail":false},"uagb_author_info":{"display_name":"JunkHack","author_link":"https:\/\/hack.gpl.jp\/author\/junkhack\/"},"uagb_comment_info":0,"uagb_excerpt":"\u524d\u304b\u3089\u3001\u8208\u5473\u304c\u3042\u3063\u305f\u900f\u904e\u578b\u306eUART\u30fcWiFI\u30d6\u30ea\u30c3\u30b8\u7684\u306b\u4f7f\u3046\u65b9\u6cd5\u3092\u3042\u308c\u3053\u308c\u8a66\u3057\u3066\u3044\u307e\u3057\u305f\u3002 \u7d50\u8ad6\u304b\u3089\u8a00\u3048\u3070\u3001…","_links":{"self":[{"href":"https:\/\/hack.gpl.jp\/wp-json\/wp\/v2\/posts\/962"}],"collection":[{"href":"https:\/\/hack.gpl.jp\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/hack.gpl.jp\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/hack.gpl.jp\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/hack.gpl.jp\/wp-json\/wp\/v2\/comments?post=962"}],"version-history":[{"count":0,"href":"https:\/\/hack.gpl.jp\/wp-json\/wp\/v2\/posts\/962\/revisions"}],"wp:attachment":[{"href":"https:\/\/hack.gpl.jp\/wp-json\/wp\/v2\/media?parent=962"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/hack.gpl.jp\/wp-json\/wp\/v2\/categories?post=962"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/hack.gpl.jp\/wp-json\/wp\/v2\/tags?post=962"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}