{"id":689,"date":"2015-05-09T16:30:04","date_gmt":"2015-05-09T07:30:04","guid":{"rendered":"https:\/\/hack.gpl.jp\/?p=689"},"modified":"2015-05-09T16:30:04","modified_gmt":"2015-05-09T07:30:04","slug":"post-689","status":"publish","type":"post","link":"https:\/\/hack.gpl.jp\/2015\/05\/09\/post-689.html","title":{"rendered":"ESP12\u5358\u4f53\u3067wifi connection"},"content":{"rendered":"
\u5358\u4f53\u3067Wifi \u306b\u63a5\u7d9a\u3057\u3066\u3001\u30c7\u30fc\u30bf\u3092ThingSpeak \u306b\u6295\u3052\u308b\u30c6\u30b9\u30c8\u3092\u3057\u3066\u307f\u307e\u3057\u305f\u3002<\/p>\n
<\/p>\n
<\/p>\n
\u914d\u7dda\u306f\u3053\u3093\u306a\u611f\u3058\u3067\u3001GPIO12 \u3068 13 \u306bLED\u3092\u304f\u3063\u4ed8\u3051\u3066\u307f\u307e\u3057\u305f\u3002\u30a2\u30af\u30bb\u30b9\u30dd\u30a4\u30f3\u30c8\u306b\u30b3\u30cd\u30af\u30b7\u30e7\u30f3\u3057\u305f\u3068\u304d\u306b\u30c0\u30d6\u30eb\u30d6\u30ea\u30f3\u30af\u3001WEB\u306b\u30b3\u30cd\u30af\u30b7\u30e7\u30f3\u3057\u3066\u3044\u308b\u3068\u304d\u306f\u3001\u70b9\u706f\u3059\u308b\u611f\u3058\u3067\u3059\u3002<\/p>\n
<\/p>\n
\u307e\u3060\u3001\u30bb\u30f3\u30b5\u30fc\u3068\u304b\u306f\u3064\u3051\u3066\u3044\u306a\u3044\u306e\u3067\u30ab\u30a6\u30f3\u30bf\u30fc\u5024\u3092\u4e0a\u3052\u3066\u307f\u307e\u3057\u305f\u3002<\/p>\n
<\/a>\u307b\u307b\u30fc\u3001\u7c21\u5358\u3067\u3059\u306d\u3002<\/p>\n <\/p>\n \u30b3\u30fc\u30c9\u306f\u3053\u3093\u306a\u611f\u3058\u3067\u3059\u3002<\/p>\n ArduinoIDE \u306e\u30b7\u30ea\u30a2\u30eb\u30e2\u30cb\u30bf\u30fc\u3067\u3082\u898b\u308c\u307e\u3059\u304c\u3001osx \u306eCoolTerm\u3067\u306f\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u898b\u308c\u307e\u3059\u3002<\/p>\n <\/p>\n <\/p>\n <\/p>\n <\/p>\n <\/p>\n <\/p>\n <\/p>\n<\/p>\n<\/p>\n<\/p>\n <\/p>\n \u53c2\u8003\u306b\u3055\u305b\u3066\u9802\u3044\u305f\u30da\u30fc\u30b8<\/p>\n ESP8266\u30e2\u30b8\u30e5\u30fc\u30eb\u3092Arduino\u3068\u3057\u3066\u4f7f\u3046<\/p>\n http:\/\/ehbtj.com\/electronics\/esp8266-as-arduino<\/a><\/p>\n <\/p>\n ESP8266\u3092USB-TTL\u30b7\u30ea\u30a2\u30eb\u5909\u63db\u3057\u3066Wi-Fi\u306e\u78ba\u8a8d\u3059\u308b<\/p>\n\/*\n ESP8266 HTTP get webclient test.\n https:\/\/thingspeak.com\/channels\/37124\n Arduino-compatible IDE with ESP8266\n arduino-1.6.1-macosx-java-latest-signed.zip\n https:\/\/github.com\/esp8266\/Arduino\n JunkHack 2015.05.09\n *\/\n \n#include <ESP8266WiFi.h>\n \nconst char* ssid = "JunkHack";\nconst char* password = "testtest";\n \nconst char* host = "184.106.153.149";\n \nvoid setup() {\n pinMode(13, OUTPUT);\n pinMode(12, OUTPUT);\n Serial.begin(115200);\n delay(10);\n \n \/\/ We start by connecting to a WiFi network\n \n Serial.println();\n Serial.println();\n Serial.print("Connecting to ");\n Serial.println(ssid);\n \n WiFi.begin(ssid, password);\n \n while (WiFi.status() != WL_CONNECTED) {\n delay(500);\n Serial.print(".");\n digitalWrite(13, HIGH);\n delay(400);\n digitalWrite(13, LOW);\n delay(100);\n }\n \n Serial.println("");\n Serial.println("WiFi connected");\n Serial.println("IP address: ");\n Serial.println(WiFi.localIP());\n}\n \nint value = 0;\nint count = 0;\n \nvoid loop() {\n delay(5000);\n ++value;\n \n Serial.print("connecting to ");\n Serial.println(host);\n \n \/\/ Use WiFiClient class to create TCP connections\n WiFiClient client;\n const int httpPort = 80;\n if (!client.connect(host, httpPort)) {\n Serial.println("connection failed");\n return;\n }\n \n digitalWrite(12, HIGH);\n delay(1000);\n count += 1;\n\n \n \/\/ We now create a URI for the request\n String url = "\/update?key=5GPL7J7EVNB5R8GE&field1=";\n url += count;\n Serial.print("Requesting URL: ");\n Serial.println(url);\n \n \/\/ This will send the request to the server\n client.print(String("GET ") + url + " HTTP\/1.1\\r\\n" +\n "Host: " + host + "\\r\\n" +\n "Connection: close\\r\\n\\r\\n");\n delay(10);\n \n \/\/ Read all the lines of the reply from server and print them to Serial\n while(client.available()){\n String line = client.readStringUntil('\\r');\n Serial.print(line);\n }\n \n \/\/ Close connection\n Serial.println();\n Serial.println("closing connection");\n digitalWrite(12, LOW);\n}<\/pre>\n
\n