{"id":554,"date":"2017-08-03T18:38:51","date_gmt":"2017-08-03T16:38:51","guid":{"rendered":"https:\/\/arduinoforlammers.wordpress.com\/?p=554"},"modified":"2017-09-24T20:21:57","modified_gmt":"2017-09-24T20:21:57","slug":"wlaczanie-swiatla-przez-internet","status":"publish","type":"post","link":"https:\/\/arduino.net.pl\/index.php\/wlaczanie-swiatla-przez-internet\/","title":{"rendered":"W\u0142\u0105czanie \u015bwiat\u0142a przez internet"},"content":{"rendered":"<p>Przy pracy korzysta\u0142em z poradnika Ubidots:\u00a0<span id=\"eow-title\" class=\"watch-title\" dir=\"ltr\" title=\"Smart Switch Tutorial - Ubidots IoT platform\"><a href=\"https:\/\/youtu.be\/ynhJ4YhhQEM\" target=\"_blank\" rel=\"noopener\">Smart Switch Tutorial &#8211; Ubidots IoT platform<\/a><\/span><\/p>\n<h2>Biblioteki:<\/h2>\n<h4><a href=\"https:\/\/github.com\/knolleary\/pubsubclient\" target=\"_blank\" rel=\"noopener\">PubSubClient<\/a><\/h4>\n<h4><a href=\"https:\/\/github.com\/ubidots\/ubidots-mqtt-esp\" target=\"_blank\" rel=\"noopener\">UbidotsESPMQTT<\/a><\/h4>\n<p><!--more--><\/p>\n<p>Z tej drugiej wybieramy skecz <strong>subscribe.ino<\/strong><br \/>\nNale\u017cy go lekko zmodyfikowa\u0107, bo w oryginale nie ma zdefiniowanego MQTTCLIENTNAME i cz\u0119\u015bci umo\u017cliwiaj\u0105cej w\u0142\u0105czenie diody na D0 (pin16)<\/p>\n<p>Niestety nie wiem jak uruchomi\u0107 wi\u0119cej di\u00f3d.<\/p>\n<pre class=\"brush: plain; light: false; title: Kod:; toolbar: true; notranslate\" title=\"Kod:\">\r\n\r\n\/****************************************\r\n* Include Libraries\r\n****************************************\/\r\n#include &quot;UbidotsESPMQTT.h&quot;\r\n \r\n\/****************************************\r\n* Define Constants\r\n****************************************\/\r\n#define TOKEN &quot;xxxxxxxxxxxxxxx&quot; \/\/ Tw\u00f3j Ubidots TOKEN\r\n#define WIFINAME &quot;xxxx&quot; \/\/ Identyfikator Twojej sieci WiFi (SSID)\r\n#define WIFIPASS &quot;xxxx&quot; \/\/ Has\u0142o dost\u0119pu do sieci\r\n#define MQTTCLIENTNAME &quot;xxxxxx&quot; \/\/ Twoja nazwa klienta. Sami j\u0105 tworzymy i wpisujemy, powinna by\u0107 trudna do odgadni\u0119cia\r\n \r\nUbidots client(TOKEN, MQTTCLIENTNAME);\r\n \r\n\/****************************************\r\n* Auxiliar Functions\r\n****************************************\/\r\n \r\nvoid callback(char* topic, byte* payload, unsigned int length) {\r\nSerial.print(&quot;Message arrived &#x5B;&quot;);\r\nSerial.print(topic);\r\nSerial.print(&quot;] &quot;);\r\nfor (int i=0;i&amp;lt;length;i++) {\r\nSerial.print((char)payload&#x5B;i]);\r\n}\r\nSerial.println();\r\nif((char)payload&#x5B;0] == '1'){\r\ndigitalWrite(16, HIGH);\r\n}\r\nelse{\r\ndigitalWrite(16, LOW);\r\n}\r\n}\r\n \r\n\/****************************************\r\n* Main Functions\r\n****************************************\/\r\n \r\nvoid setup() {\r\n\/\/ put your setup code here, to run once:\r\nSerial.begin(115200);\r\nclient.setDebug(true); \/\/ Pass a true or false bool value to activate debug messages\r\nclient.wifiConnection(WIFINAME, WIFIPASS);\r\nclient.begin(callback);\r\npinMode(16, OUTPUT);\r\nclient.ubidotsSubscribe(&quot;switch&quot;,&quot;my-switch&quot;); \/\/Insert the dataSource and Variable's Labels\r\n}\r\n \r\nvoid loop() {\r\n\/\/ put your main code here, to run repeatedly:\r\nif(!client.connected()){\r\nclient.reconnect();\r\nclient.ubidotsSubscribe(&quot;switch&quot;,&quot;my-switch&quot;); \/\/Insert the dataSource and Variable's Labels\r\n}\r\nclient.loop();\r\n}\r\n<\/pre>\n<h2>Dodatkowe informacje:<\/h2>\n<p><b>SSID<\/b> (ang. service set identifier) \u2013 identyfikator sieci sk\u0142adaj\u0105cy si\u0119 maksymalnie z 32 znak\u00f3w, dodawany do nag\u0142\u00f3wk\u00f3w pakiet\u00f3w wysy\u0142anych przez bezprzewodow\u0105 sie\u0107 lokaln\u0105. Pe\u0142ni on rol\u0119 loginu przy pr\u00f3bie nawi\u0105zywania po\u0142\u0105cze\u0144 z punktami dost\u0119powymi.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Przy pracy korzysta\u0142em z poradnika Ubidots:\u00a0Smart Switch Tutorial &#8211; Ubidots IoT platform Biblioteki: PubSubClient UbidotsESPMQTT<\/p>\n","protected":false},"author":3,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[5],"tags":[],"class_list":["post-554","post","type-post","status-publish","format-standard","hentry","category-esp8266"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/arduino.net.pl\/index.php\/wp-json\/wp\/v2\/posts\/554","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/arduino.net.pl\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/arduino.net.pl\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/arduino.net.pl\/index.php\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/arduino.net.pl\/index.php\/wp-json\/wp\/v2\/comments?post=554"}],"version-history":[{"count":2,"href":"https:\/\/arduino.net.pl\/index.php\/wp-json\/wp\/v2\/posts\/554\/revisions"}],"predecessor-version":[{"id":659,"href":"https:\/\/arduino.net.pl\/index.php\/wp-json\/wp\/v2\/posts\/554\/revisions\/659"}],"wp:attachment":[{"href":"https:\/\/arduino.net.pl\/index.php\/wp-json\/wp\/v2\/media?parent=554"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/arduino.net.pl\/index.php\/wp-json\/wp\/v2\/categories?post=554"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/arduino.net.pl\/index.php\/wp-json\/wp\/v2\/tags?post=554"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}