{"id":146,"date":"2017-05-24T14:40:29","date_gmt":"2017-05-24T12:40:29","guid":{"rendered":"https:\/\/dev.drun.net\/?p=146"},"modified":"2017-05-24T14:40:29","modified_gmt":"2017-05-24T12:40:29","slug":"simple-onoff-app-for-sonoff-ios","status":"publish","type":"post","link":"https:\/\/dev.krasi.net\/?p=146","title":{"rendered":"Simple iOS On\/Off app for SonOff"},"content":{"rendered":"<p>I had some time, so I decided to make an on\/off program for my SonOff switch that I want to use to turn on \/ off the boiler heating at my house ( I use the stronger one, that has support for 16A load). My SonOff is <a href=\"\/2017\/04\/27\/customizing-sonoff-esp-switch-to-work-with-anything\/\">pre-configured already with ESPEasy and rules<\/a>.<\/p>\n<p>What I will be making\u00a0is a very simple iOS app that has a toggle button on it. First, some basics:<\/p>\n<p>Reading the current state:<\/p>\n<pre>http:\/\/192.168.88.171\/control?cmd=status,gpio,12<\/pre>\n<p>Changing the current state:<\/p>\n<pre>http:\/\/192.168.88.171\/control?cmd=event,TurnOn<\/pre>\n<p>and<\/p>\n<pre>http:\/\/192.168.88.171\/control?cmd=event,TurnOff<\/pre>\n<p>So, what I need is a simple app that will need to:<\/p>\n<p>a) Manually set \/ change the IP address of the controller.<br \/>\nb) Read the state of the GPIO from the controller ( JSON output ).<br \/>\nc) Visually change the button state to reflect the on\/off state.<br \/>\nd) Send the new state to the controller when the button is pressed.<\/p>\n<p>Well, the app creation itself took around 1 hour. I will not go into details, if you want &#8211; <a href=\"https:\/\/github.com\/kkazakov\/EasyControl\">you can check it out yourself from GitHub<\/a>. I&#8217;ve used SwiftyJSON and Alamofire &#8211; two wonderful libraries, to handle JSON result from the controller and to send requests.<\/p>\n<p>That&#8217;s the primary screen of the app:<\/p>\n<pre><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-151 size-large\" src=\"https:\/\/dev.krasi.net\/wp-content\/uploads\/2017\/05\/Screenshot1-576x1024.png\" alt=\"\" width=\"576\" height=\"1024\" \/><\/pre>\n<p>As you can see, it&#8217;s very simple, but gets the job done \ud83d\ude42 You can tweak it as you wish, just checkout the GitHub repository.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I had some time, so I decided to make an on\/off program for my SonOff switch that I want to use to turn on \/ off the boiler heating at my house ( I use the stronger one, that has support for 16A load). My SonOff is pre-configured already with ESPEasy and rules. What I will be making\u00a0is a very simple iOS app that has a toggle button on it. First, some basics: Reading the current state: http:\/\/192.168.88.171\/control?cmd=status,gpio,12 Changing the current state: http:\/\/192.168.88.171\/control?cmd=event,TurnOn and http:\/\/192.168.88.171\/control?cmd=event,TurnOff So, what I need is a simple app that will need to: a) Manually set \/ change the IP address of the controller. b) Read the state of the GPIO from the controller ( JSON output ). c) Visually change the button state to reflect the on\/off state. d) Send the new state to the controller when the button is pressed. Well, the app creation itself took around 1 hour. I will not go into details, if you want &#8211; you can check it out yourself from GitHub. I&#8217;ve used SwiftyJSON and Alamofire &#8211; two wonderful libraries, to handle JSON result from the controller and to send requests. That&#8217;s the primary screen of the app: [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5],"tags":[],"class_list":["post-146","post","type-post","status-publish","format-standard","hentry","category-software"],"_links":{"self":[{"href":"https:\/\/dev.krasi.net\/index.php?rest_route=\/wp\/v2\/posts\/146","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/dev.krasi.net\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/dev.krasi.net\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/dev.krasi.net\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/dev.krasi.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=146"}],"version-history":[{"count":0,"href":"https:\/\/dev.krasi.net\/index.php?rest_route=\/wp\/v2\/posts\/146\/revisions"}],"wp:attachment":[{"href":"https:\/\/dev.krasi.net\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=146"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/dev.krasi.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=146"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/dev.krasi.net\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=146"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}