{"id":44,"date":"2024-10-26T13:43:24","date_gmt":"2024-10-26T11:43:24","guid":{"rendered":"https:\/\/rcv.news\/?p=44"},"modified":"2024-10-26T13:43:26","modified_gmt":"2024-10-26T11:43:26","slug":"using-dns-to-save-and-read-my-cars-data-worldwide","status":"publish","type":"post","link":"https:\/\/rcv.news\/?p=44","title":{"rendered":"Using DNS to save and read my cars data worldwide"},"content":{"rendered":"\n<p>When I wrote the <a href=\"https:\/\/rcv.news\/?p=1\">simple code<\/a> to stop loading my cars battery at 80%, I was looking for a way to save relevant car data to use it for further purposes. Relevant data was the cars battery state in percent, the charging target (80% in my case) and the mileage left on battery. In order to access this data from different devices worldwide I decided to store it in a DNS record.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Get a free DNS record<\/h2>\n\n\n\n<p>I created a free DNS zone at <a href=\"https:\/\/dynv6.com\/\">dynv6.com<\/a>. Next step was to create a security token to update my DNS entry via API and then append a new line to my python code.<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p>bimmerhtml = requests.get(&#8220;https:\/\/ipv4.dynv6.com\/api\/update?token=&lt;your token goes here>&amp;zone=&lt;your DNS zone goes here>&amp;ipv4=&#8221; + percent + &#8220;.&#8221; + target + &#8220;.&#8221; + range + &#8220;.0&#8221;)<\/p>\n<\/blockquote>\n\n\n\n<p>In order to make HTTP requests work in the python script another library is neccessary to add in the head of the script.<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p>import requests<\/p>\n<\/blockquote>\n\n\n\n<p>That&#8217;s all and now you are able to read this data from other devices really simple.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">An iPhone widget<\/h2>\n\n\n\n<p>My first use case was to display mileage left and battery state on my iPhones home screen.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"613\" height=\"564\" src=\"https:\/\/rcv.news\/wp-content\/uploads\/2024\/10\/image-2.png\" alt=\"\" class=\"wp-image-45\" srcset=\"https:\/\/rcv.news\/wp-content\/uploads\/2024\/10\/image-2.png 613w, https:\/\/rcv.news\/wp-content\/uploads\/2024\/10\/image-2-300x276.png 300w\" sizes=\"auto, (max-width: 613px) 100vw, 613px\" \/><\/figure>\n\n\n\n<p>Within the <a href=\"https:\/\/apps.apple.com\/de\/app\/scriptable\/id1405459188?l=en-GB\">scriptable<\/a> app I wrote a small script to accomplish that:<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p>\/\/timestamp<br>let date = new Date();<br>let hours = date.getHours();<br>let minutes = date.getMinutes() &lt; 10 ? &#8220;0&#8221; + date.getMinutes() : date.getMinutes();<br>let datum = hours + &#8220;:&#8221; + minutes;<\/p>\n<\/blockquote>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p>url = &#8220;https:\/\/dns.google\/resolve?name=&lt;your DNS zone goes here>&#8221;;<br>req = new Request(url);<br>let answer = await req.loadJSON();<br>let dns = answer.Answer[0].data;<br>let octets = dns.split(&#8220;.&#8221;, 4);<br>percent = octets[0];<br>target = octets[1];<br>range = octets[2];<\/p>\n<\/blockquote>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p>let widget = new ListWidget();<br>widget.backgroundColor = Color.black();<\/p>\n<\/blockquote>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p>let stack = widget.addStack();<br>stack.bottomAlignContent();<br>let wpercent = stack.addText(percent);<br>wpercent.font = Font.mediumRoundedSystemFont(48)<br>wpercent.textColor = Color.red();<\/p>\n<\/blockquote>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p>let wpercentsign = stack.addText(&#8220;%&#8221;);<br>wpercentsign.font = Font.mediumRoundedSystemFont(28)<br>wpercentsign.textColor = Color.red();<\/p>\n<\/blockquote>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p>let wRange = widget.addText(range+&#8221;km&#8221;);<br>wRange.font = Font.mediumRoundedSystemFont(18)<br>wRange.textColor = Color.white();<br>wRange.leftAlignText();<\/p>\n<\/blockquote>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p>widget.addSpacer();<\/p>\n<\/blockquote>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p>let wDate = widget.addText(datum);<br>wDate.font = Font.mediumRoundedSystemFont(14)<br>wDate.textColor = Color.gray();<br>wDate.leftAlignText();<\/p>\n<\/blockquote>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p>Script.setWidget(widget);<br>Script.complete();<br>App.close();<\/p>\n<\/blockquote>\n\n\n\n<p>Have fun.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>When I wrote the simple code to stop loading my cars battery at 80%, I was looking for a way to save relevant car data to use it for further purposes. Relevant data was the cars battery state in percent, <a href=\"https:\/\/rcv.news\/?p=44\"> Read more&#8230;<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[8,10],"tags":[],"class_list":["post-44","post","type-post","status-publish","format-standard","hentry","category-programming","category-tutorial"],"_links":{"self":[{"href":"https:\/\/rcv.news\/index.php?rest_route=\/wp\/v2\/posts\/44","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/rcv.news\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/rcv.news\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/rcv.news\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/rcv.news\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=44"}],"version-history":[{"count":1,"href":"https:\/\/rcv.news\/index.php?rest_route=\/wp\/v2\/posts\/44\/revisions"}],"predecessor-version":[{"id":46,"href":"https:\/\/rcv.news\/index.php?rest_route=\/wp\/v2\/posts\/44\/revisions\/46"}],"wp:attachment":[{"href":"https:\/\/rcv.news\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=44"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/rcv.news\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=44"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/rcv.news\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=44"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}