<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Jan Bertrand on Medium]]></title>
        <description><![CDATA[Stories by Jan Bertrand on Medium]]></description>
        <link>https://medium.com/@bertrand.jan?source=rss-14c8d196ddc0------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*LprI4KpetId1zgz1no_DDg.jpeg</url>
            <title>Stories by Jan Bertrand on Medium</title>
            <link>https://medium.com/@bertrand.jan?source=rss-14c8d196ddc0------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 29 Nov 2026 05:46:19 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@bertrand.jan/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Tell me more Internet of Things — Part 6— Google Cloud — User input & push subscription]]></title>
            <link>https://medium.com/@bertrand.jan/tell-me-more-internet-of-things-part-6-google-cloud-user-input-push-subscription-aa39ebc4a348?source=rss-14c8d196ddc0------2</link>
            <guid isPermaLink="false">https://medium.com/p/aa39ebc4a348</guid>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[push-notification]]></category>
            <category><![CDATA[google-cloud-platform]]></category>
            <dc:creator><![CDATA[Jan Bertrand]]></dc:creator>
            <pubDate>Sat, 21 Sep 2019 09:45:24 GMT</pubDate>
            <atom:updated>2019-09-21T09:45:24.667Z</atom:updated>
            <content:encoded><![CDATA[<h3>Tell me more Internet of Things — Part 6— Google Cloud — User input &amp; push subscription</h3><h4>How to push notification to the users using <strong>webpush</strong> package. Changing the app engine app and adding a separate cloud function</h4><p><a href="https://medium.com/@bertrand.jan/tell-me-more-internet-of-things-part-1-iot-platform-cost-and-value-comparison-558ce8966767">Part 1</a> <strong>| </strong><a href="https://medium.com/coinmonks/tell-me-more-internet-of-things-part-2-google-cloud-iot-cost-and-value-comparison-38bfb20d94e1">Part 2<strong><em> </em></strong></a><em>| </em><a href="https://medium.com/@bertrand.jan/tell-me-more-internet-of-things-part-3-mindsphere-cost-and-value-comparison-b333ebfb872a">Part 3</a><em> | </em><a href="https://medium.com/@bertrand.jan/tell-me-more-internet-of-things-part-4-iota-cost-and-value-comparison-381008495d1d">Part 4</a><em>| </em><a href="https://medium.com/@bertrand.jan/tell-me-more-internet-of-things-part-5-google-cloud-user-handling-ae285e7e34b2">Part 5</a> <em>|</em><a href="https://medium.com/@bertrand.jan/tell-me-more-internet-of-things-part-6-google-cloud-user-input-push-subscription-aa39ebc4a348"><strong>Part 6</strong></a><strong> </strong><em>| … | Part n</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*EXtInLtMnT4sHJbH79LiqQ.png" /><figcaption>Implementation Overview. Extending a webpush warning and feedback route</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*EZwzgvJGUy_TdwI_VVzidg.png" /><figcaption>Milestone overview</figcaption></figure><p>We want our app to recognise interesting or certain limits from the device sensors and the ability to send them as notification to us. As we have only developed a web application we need to have the browser (in our case chrome) listen in the background for any messages from the device. In addition, we won’t have them send from our device directly to us, this will be done in the cloud function. To make things even more complicated we could potentially open the app on different devices which could lead to the users decision to get notified on different devices.</p><p>In our implementation we will limit that to one subscription for every registered device. Example — I open the app on my mobile and want to get notified there. Then I open it on my laptop and the subscription will change to the laptop if I activate it there.</p><p>Further we may like to get some feedback over the event from the user</p><blockquote><em>For later implementation: This logged data should be used later in an system identification or diagnostic identification to predict or suggest events. This maybe done with simple linear interpolation or up to machine learning of highly nonlinear models</em>.</blockquote><h3>Implementation summary</h3><p>In our implementation we are creating a new</p><ul><li>Cloud function — which subscribed to the pub/sub from all registered devices. Once the</li><li>Threshold — for a particular device is exceeded the cloud function looks into datastore for the subscription details from this device and pushes a notification via</li><li>Webpush package — to the dedicated service worker of the dedictated browser.</li><li>The app engine — has a new route which once the notification is clicked the user can enter feedback about the event</li><li>The datastore — contains the subscription details and is as mentioned connected to the registered deice KIND from datastore.</li><li>You can subscribe — to a and device event by simply opt in via the chart button.</li></ul><p><a href="https://github.com/jhab82/gce-tmmiot-app">jhab82/gce-tmmiot-app</a></p><h3>Cloud function</h3><p><em>For trigger detection and webpush</em></p><p>Only for better serviceability and in order not to overload the existing pubsub triggered cloud function we create a new one. But we could have used the existing one and extending this function.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/960/0*j49Ne6NV5IIA5QGC" /><figcaption>Separate cloud function for webpush subscription</figcaption></figure><p>This would be our trigger backend function only pushing this notification to the dedicated browser (Chrome) if certain thresholds are surpassed.</p><p>The entire concept of notification push delivery is based on service workers implemented in the frontend browser working even in the frontend device without the need to open the browser. Chrome supports this quite some time and we are building on this excellent tutorial</p><p><a href="https://codelabs.developers.google.com/codelabs/push-notifications/#0">https://codelabs.developers.google.com/codelabs/push-notifications/#0</a></p><p>In order not just repeat this tutorial I try to explain the concept with my own words. You might have noticed recently an increase in those tiny notification request which you can either block or allow (depending on your site settings). Once you allow the side to send you notification it can do it without you opening the browser. On a mobile device that would mean you could get all the notification (without having an android app service but just the browser).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/960/0*r2vESKmdiGgn8hT3" /><figcaption>Webpush notification and front-end logs</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/960/0*1Bt0rso9bOPYLMXl" /><figcaption>Front-end logs when subsribing</figcaption></figure><p>As seen in the second screen I just allowed the service to be added and in the console some logging can be seen. Even before the allowance was given the service worker was registered and the executable javascript here sw.js has been added to our front-end repro. Then once an event get routed to the service worker we can see a pop up notification as below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/360/0*9-NJOrYNjBoNUCTN" /></figure><p>Once we click this notification we get redirected to a page where we can leave the events feedback:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/960/0*R46VT1I4rUQDFEtj" /></figure><p>Which then should be written to Big Query and Datastore databases for storage (and later data analytics). Beside our new cloud function just triggering the push in case of exceeding our threshold we need to add a few lines and files to our app engine app. We like to add the notification enabling and disabling entry on the chart page. Here we just add a few lines and load our main-push.js javascript for handling the subscription. In order that our javascript file can be loaded in pug we need to add in app.js a public place for our files in the back end. That let us reference our front end javascripts to be loaded once pug renders the views.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/960/0*LTLay8tI792Ammd0" /><figcaption>Extending the chart.pug for subscription</figcaption></figure><p>So we trigger our notification service by opt in using a button on the chart page. Above the pug code. The only text changes once we disable or enable the service clicking the button.</p><p>We could create a seperate subscription KIND (database) as every subscription to every seperate browser on different devices (OS) can get seperate subscription. We just add the subscription details to our registration (tmmiot_device) device kind.</p><p>So everytime the browser subscribes to the notification it will override the old subscription details which leads to the new device will get the notification.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*8ZXenDautHSyYkJA" /><figcaption>Datastore KIND for registering a subscription</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*6KzcHcexiVPdFOcn" /></figure><p>We added a new route “/subscribe” for adding the subscription information to the existing KIND for device registration to users.</p><p>Inside the cloud function once a threshold is exceeded the function checks whether there is a subscription for this device and if successful send via web-push the notification to this device / browser service worker.</p><p>In this implementation it is only possible to have one subscription per device. Which means you could either get the notification on your mobile device or your laptop but not both.</p><p>I like your comments, corrections and suggestions 👌.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=aa39ebc4a348" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Tell me more Internet of Things — Part 5 — Google Cloud — User handling]]></title>
            <link>https://medium.com/@bertrand.jan/tell-me-more-internet-of-things-part-5-google-cloud-user-handling-ae285e7e34b2?source=rss-14c8d196ddc0------2</link>
            <guid isPermaLink="false">https://medium.com/p/ae285e7e34b2</guid>
            <category><![CDATA[google-cloud-platform]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[iot]]></category>
            <category><![CDATA[nodejs]]></category>
            <dc:creator><![CDATA[Jan Bertrand]]></dc:creator>
            <pubDate>Mon, 13 May 2019 17:44:26 GMT</pubDate>
            <atom:updated>2019-09-22T05:28:54.818Z</atom:updated>
            <content:encoded><![CDATA[<h3>Tell me more Internet of Things — Part 5 — Google Cloud — User handling</h3><h4>How to build a web application for our ingested IoT Core data. How to implement individual, secure data visualization and device registration. Using Nodejs with App Engine, Datastore, OAuth2 and Cron jobs.</h4><p><a href="https://medium.com/@bertrand.jan/tell-me-more-internet-of-things-part-1-iot-platform-cost-and-value-comparison-558ce8966767">Part 1</a> <strong>| </strong><a href="https://medium.com/coinmonks/tell-me-more-internet-of-things-part-2-google-cloud-iot-cost-and-value-comparison-38bfb20d94e1">Part 2<strong><em> </em></strong></a><em>| </em><a href="https://medium.com/@bertrand.jan/tell-me-more-internet-of-things-part-3-mindsphere-cost-and-value-comparison-b333ebfb872a">Part 3</a><em> | </em><a href="https://medium.com/@bertrand.jan/tell-me-more-internet-of-things-part-4-iota-cost-and-value-comparison-381008495d1d">Part 4</a><em>| </em><a href="https://medium.com/@bertrand.jan/tell-me-more-internet-of-things-part-5-google-cloud-user-handling-ae285e7e34b2"><strong>Part 5</strong></a><strong> </strong><em>|</em><a href="https://medium.com/@bertrand.jan/tell-me-more-internet-of-things-part-6-google-cloud-user-input-push-subscription-aa39ebc4a348">Part 6</a> <em>| … | Part n</em></p><p>With Google Cloud Engine (GCE) we start continuing the story. In the last articles it was all about how to get the data securely into the cloud (or in case of IOTA into the distributed Database… kind of a cloud at the moment anyways) — in a robust and scalable manner.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/279/1*H4pCLV31Z5ZtmI8ltQMhFg.png" /></figure><p>This article deep dives on the User Interaction (UI). We will explore how to get data into a faster query-able database (here Datastore — predecessor of Firestore) and build a web application on Google Cloud App Engine for the user to visualize their device data. As we did in the last parts of this series , we will try to estimate the introduced cost with the added functionality.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/688/1*P96YL262To1mb-Vskuco4g.png" /><figcaption>Milestones: It’s just M4 this time (well, a bit of M3 for the user)</figcaption></figure><p>This article will implement a way of how a users can register their devices (hopefully securely) to their accounts and visualize its data. As Big Query is not as fast nor designed for fast user interaction we use Google Datastore to store the past days of data. We deploy a web application written in node.js (express,..) on Google App engine with build in SSL (HTTPS) and full OAuth2 authentication. The user should be able authenticate himself with a google account and register a device by entering their devices ID. The devices ID has been registered by us (the manufacturer of the device after creation of the device). The user can then visualize the measurements from any browser (mobile support is added by using stylesheets bootstrapcdn together with PUG)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/596/1*O6mknj29QmrpeYkgKGbPCg.png" /><figcaption>Overview of the Implementation: Google Cloud Service architecture with changed code in Cloud functions, added Datastore and App Engine for the web app</figcaption></figure><p>We will touch three services which increases our costs of the solution.</p><ul><li><strong>Cloud Functions:</strong> We just push our IoT Core registered Pub/Sub beside to Big Query as well to Datastore.</li><li><strong>Datastore:</strong> We store the past one day data for every device. CRON job deletes old data every day</li><li><strong>App Engine:</strong> We create a web application which serves as the base user interaction and visualization.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/603/1*THiriWQD9oPQkoL2uAyqMg.png" /><figcaption>Data flow and extension to user interface (web-app)</figcaption></figure><p>The impact on the cost is the temporary data added to Datastore (which comes with reasonable high free quota) and the Standard App engine environment (which actually with the chosen F2 hardware architecture will cost you money even for one user if it runs all day). But it most prob. won’t as you only access the web app once in a while. Bear in mind that the engine spins up for 15 minutes minimum and that this time adds up if you even occasionally access the endpoint / URL.</p><p>Some of the cost goes away by the always free allowance <a href="https://cloud.google.com/free/docs/gcp-free-tier">https://cloud.google.com/free/docs/gcp-free-tier</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/783/1*6wB6TQrtDQYu0BiFfp0V_g.png" /><figcaption>Always free usage limits from Google FAQ for App Engine and (Cloud Firestore ~Datastore)</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/664/1*yVnk8qf5kEm6_5v1YDgbWQ.png" /><figcaption>Rough estimation of cost increase by introducing an App Engine and Datastore operations. Assuming 3 instances of F2 24h necessary for the 10.000 device (user) option. In addition the Datastore is approximated to store for every device only one day data (data storage is then for all scenarios for free as below 1GB)</figcaption></figure><blockquote>The cost jumps to ~10 € per device/ year for the 100 device scenario — This is due to the high app engine costs which can be optimized with a lower powered compute engine or just not opt in for the stronger F2 architecture. I didn’t really looked into that to be honest but would like to give you a possible explanation and emphasize that this approximation has several assumption and can be optimized.</blockquote><p>This article only introduces the user management and the base for all sorts of web-based provided user configurations and visualizations. App Engine is a very easy to deploy out of the box secure (HTTPS) offer. The beauty of this product is that it scales in its standard environment up and down (adding further F2 instances or deleting them) to always provide the best performance for the current load. We established routes for handling data which we stored in the fast queryable database Datastore.</p><blockquote>When I started the project <em>tell-me-more-iot</em> a couple of month ago I decided to opt in for Datastore. There is currently no possibility to have in the same project Datastore and Firestore running — as well not to switch from one to the other. At least I am not aware of. This is not a big deal but explains my decision for using Datastore here.</blockquote><p>I found it especially nice to have SSL and OAuth relatively easy to add to the web-app. With that improving the web apps security. I am not sure whether my chosen design for the authorization of the measurement content (by asking for the user.id of the google account information) is fit for all sort of attacks and I would be glad if someone could leave a comment if she/he thinks it should be changed or could be improved.</p><h4>Cloud Function: From Pub/Sub to Datastore</h4><p>I always think of Cloud Functions as a single paged app engine deploy. As we use node.js this contains one application file (index.js) containing the execution logic and one package file (package.json) which is the “header” file containing the information of which modules we need for our Cloud Function.</p><p>Last time we used node.js 6.0 (this was the default engine) now I switched to node.js 8.0. It took me a whole day to figure out that in node.js 8.0 the syntax for creation of objects has changed. The logging wasn’t really helpful and I did not know how to debug it in Cloud Functions — quite frustrating.<br>I think I “brute forced”-style trial and error until hitting version number 19 :-) before it worked.</p><p>Below the entire code now extended to push data to Datastore once available</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/6c326a7819b0e0fb16590d259ab5a3a2/href">https://medium.com/media/6c326a7819b0e0fb16590d259ab5a3a2/href</a></iframe><p>This function automatically writes the incoming data into the Kind tmmiot_datastore_2 to the appropriate columns. No need to create a new DB or a blank schema. As Datastore will be most likely soon replaced entirely by Firestore the syntax would be a bit different using Firestore.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Q0wwzYn0o_y_NZCoAewoMA.png" /><figcaption>Datastore: Kind and entity in details</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/0*CxBB4wL8XY-RMtRh" /><figcaption>Cloud Function web representation</figcaption></figure><h3>App Engine: Web application for device registration, user handling and more</h3><p>The web application is written entirely again in javascript. On the back-end we have node.js and the front we use PUG (a HTML template engine).</p><p>The application architecture is derived from googles own node.js end-2-end Bookshelf example app: <a href="https://cloud.google.com/nodejs/getting-started/tutorial-app">https://cloud.google.com/nodejs/getting-started/tutorial-app</a></p><p>In addition we use for user authentication and authorization OAuth with google OAuth 2.0 client IDs (you need to authorize yourself with your google account to enter the app)</p><p>Further we enable logging from the start for better debugging.</p><h4>The general setup</h4><p>I do directly coding inside the cloud shell and using the editor functionality as seen the pic below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*AUyzGPPVmf1tfw8Aj2Yl1A.png" /><figcaption>Cloud Shell — my development setup.</figcaption></figure><p>Its an ephemeral docker container spinning up once you hit the cloud shell symbol and it comes with all the required software (git, node, npm,…) and sure you can add to the standard deploy in a docker format.</p><p>In order to prepare our project form the scratch first create a project folder. In this folder I like to add the freely chosen sub-folders and start the node.js project.</p><pre><strong>(tell-me-more-iot)$</strong><br>npm init<br>mkdir router<br>mkdir router/private<br>mkdir model<br>mkdir views<br>mkdir views/private<br>mkdir lib<br>npm install --save @google-cloud/datastore<br>npm install --save express<br>npm install --save express-session<br>npm install --save pug</pre><pre>touch app.js<br>....</pre><pre>npm install</pre><p>A quick walk through for the beginning npm init initiates the package file with information about the project. Withmkdir all folders will be created. Where in router/private we intend to store the express router (which is the endpoints of our URL base web-app). In the sub-folder modelI like to store the handler to our Datastore. In views its all PUG (HTML) code for the front-end. With npm install --save ... we save the dedicated module to our newly created package.json file. Finally we create the first file app.js and after adding all the code install the app with npm install . Just afterwards the node_modules folder is getting filled up with all code requested in package.json</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/0*GAkU_1Z7jjSZXOfa" /><figcaption>npm init executed from google cloud shell</figcaption></figure><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/9d9d36dd56206a917099765b435c0045/href">https://medium.com/media/9d9d36dd56206a917099765b435c0045/href</a></iframe><p>The above Gists show the simplest implementation of this architecture. We won’t deploy that to the app engine just yet. We can simply start the application “locally” (actually in the cloud on a spun up app engine) without deploying it by altering the package.json file</p><pre>...<br>&quot;main&quot;: &quot;app.js&quot;,<br>&quot;scripts&quot;: {<br>&quot;test&quot;: &quot;echo \&quot;Error: no test specified\&quot; &amp;&amp; exit 1&quot;,<br>&quot;start&quot;: &quot;node ${SCRIPT:-app.js}&quot;<br>},<br>...</pre><p>Lets start the application by npm start and opening the browser with the little browser sign.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/689/1*oGVaTvVMBiw40v7eIkloMg.png" /><figcaption>(marked yellow) starting the URL with the “locally” deployed app</figcaption></figure><p>You can see that this is an ephemeral app engine with a static link (8080-dot-4015961-dot-devshell-appspot.com) this URL we need to add later for our OAuth registered endpoints.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/0*ZCEUPdkDAuLWrZm1" /><figcaption>Its not much but its a web-app</figcaption></figure><p>Next we need to add</p><ul><li>Datastore routes (model/datastore-device.js)</li><li>Authentication via OAuth (lib/passport.js)</li><li>Logging (lib/logging.js)</li><li>a few more views and a body-parser for POST requests</li></ul><p>You can find the code in its final version here if you like:</p><p><a href="https://github.com/jhab82/gce-tmmiot-app">jhab82/gce-tmmiot-app</a></p><h4>Adding Datastore communication</h4><p>We like to fetch the measurement data from device from Datastore. In order to do so we need to add the communication model to Datastore. This is half happening in /model/datastore-device.js and the URL which routes to the functionality is added in /router/private/device.js (why did I chose the subfolder private ? because I like to add later OAuth and make it private at the moment its terrible public though).</p><p>I won’t go into all the details but the easiest route will be a data list presentation. The function which queries all the measurement data by a given deviceId stays below (in /model/datastore-device.js ):</p><pre>function listDataByDeviceId(deviceId, limit, token, cb) {<br>  const q = ds<br>    .createQuery([kind_data])<br>    .filter(&#39;id&#39;, &#39;=&#39;, deviceId)<br>    .order(&#39;time&#39;, {descending: true})<br>    .limit(limit)<br>    .start(token);</pre><pre>ds.runQuery(q, (err, entities, nextQuery) =&gt; {<br>    if (err) {<br>      cb(err);<br>      return;<br>    }<br>    const hasMore =<br>      nextQuery.moreResults !== Datastore.NO_MORE_RESULTS<br>        ? nextQuery.endCursor<br>        : false;<br>    cb(null, entities.map(fromDatastore), hasMore);<br>  });<br>}</pre><p>The function and exposed endpoint (URL: …/list/tmmiot-device-4) which triggers this function is the router here (in /router/device.js ):</p><pre>router.get(&#39;/list/:deviceId&#39;, oauth2.required, (req, res, next) =&gt; {<br>  //check the deviceId requested is registered to the owner<br>  getModelDevice().isDeviceIdRegistered(req.params.deviceId, (err, device) =&gt; {<br>        if (err) { console.log(&quot;err: &quot; + err) }<br>        else if (device[0].userId == req.user.id) {<br>                  <br>        getModelDevice().listDataByDeviceId(<br>            req.params.deviceId, <br>            10,<br>            req.query.pageToken, <br>            (err, measurements, cursor) =&gt; {<br>            if (err) {<br>                <br>                res.redirect(&quot;/device&quot;);<br>                } else {<br>                    <br>                    res.render(&#39;private/measurementList.pug&#39;, {<br>                        measurements: measurements,<br>                        nextPageToken: cursor,<br>                    });<br>                }<br>            });<br>        } else {<br>            res.redirect(`${req.baseUrl}/`);<br>        }<br>    });<br>});</pre><p>The function takes into account only querying the last 10 measurements and has a link to the next 10. The result in combination with the front end pug presentation private/measurementList.pug</p><pre>extends ./base.pug</pre><pre>block content <br>  h3 Data from #{measurements[0].id}<br>    <br>  each measurement in measurements<br>    .media<br>      pre<br>        span Date: #{measurement.date} <br>        span Temperature: #{measurement.Temp}°C <br>        span Humidity: #{measurement.Hum}% <br>        span PM2.5: #{measurement.pm2p5} mug/m^3 <br>        span PM10: #{measurement.pm10} mug/m^3</pre><pre>if !measurements.length<br>    p No measurements found.</pre><pre>if nextPageToken<br>    nav<br>      ul.pager<br>        li<br>          a(href=`?&amp;pageToken=${encodeURIComponent(nextPageToken)}`) More</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/0*NqOoZDBxIqH8mY5L" /><figcaption>Web app with list of measurement..</figcaption></figure><p>One thing which comes with the high performing database is that you can only do single queries (and no *like queries) but as seen above we like to have them sorted by the time and filtered by Id that means we need to create an index for this:</p><pre>//index.yaml<br><strong>indexes</strong>:<br>- <strong>kind</strong>: tmmiot_datastore_2<br> <strong>properties</strong>:<br> - <strong>name</strong>: id<br> - <strong>name</strong>: time</pre><p>The index.yaml file can be deployed to Datastore with gcloud datastore indexes create index.yaml straight from the cloud shell</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*Ad-RPkg-D9bCCnIFouUYKA.png" /><figcaption>Datastore Indexes</figcaption></figure><p>As a list is probably the worst representation when it comes to time-series we need to extend the front and back-end to use charts.</p><p>I will only show here the new PUG /views/measurementChart.pug the routes and model changes you can review in the git repro. Here we use google charts java-script packages which we pass all the measurement while rendering a stringified object list var measurements = !{measurements}; . I am sure that there are nicer ways to do such things (Would be great if you could leave a comment about other ways of doing that).</p><pre>extends ./base.pug</pre><pre>block content<br>  h3 Chart from #{deviceId}<br>  script(type=&#39;text/javascript&#39;).<br>        google.charts.load(&#39;current&#39;, {&#39;packages&#39;:[&#39;corechart&#39;], callback: drawChart});<br>        var measurements = !{measurements};<br>        function drawChart() {<br>                var dataLine = new google.visualization.DataTable();<br>                dataLine.addColumn(&#39;datetime&#39;, &#39;Date&#39;);<br>                dataLine.addColumn(&#39;number&#39;, &#39;Temp&#39;);<br>                dataLine.addColumn(&#39;number&#39;, &#39;Humidity&#39;);<br>                dataLine.addColumn(&#39;number&#39;, &#39;pm2p5&#39;);<br>                dataLine.addColumn(&#39;number&#39;, &#39;pm10&#39;);</pre><pre>for (var i = 0; i &lt; measurements.length; i++) {<br>                    var d = new Date();<br>                    d.setTime(measurements[i].time);<br>                    dataLine.addRow([d, parseFloat(measurements[i].Temp), parseFloat(measurements[i].Hum), parseFloat(measurements[i].pm2p5), parseFloat(measurements[i].pm10)]);<br>                }</pre><pre>var chartLine = new google.visualization.LineChart(document.getElementById(&#39;div_LineChart&#39;));<br>                chartLine.draw(dataLine, { width: &#39;400&#39;, height: &#39;600&#39;, legend: {position: &#39;top&#39;}});<br>            }</pre><pre>if measurements.length &lt; 3<br>    p No measurements found. <br>  else<br>    #div_LineChart</pre><pre>if nextPageToken<br>    nav<br>      ul.pager<br>        li<br>          a(href=`?&amp;pageToken=${encodeURIComponent(nextPageToken)}`) More</pre><p>The result is the colorful time-series presentation of our measurement data</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/0*ATHUDi0aj3tW99Xq" /><figcaption>/views/measurementChart.pug</figcaption></figure><h4>Deploying the app to App Engine</h4><p>This is quite to easy for an own chapter but needs some explanation. The only thing really is necessary to go from local (testing env.) to production to decide on the name of the service (here: gce-tmmiot-app) and whether we like to deploy in a flexible or standard environment. We chose the standard environment with the instance power dedicated to F2 machine. All this information just need to get squeezed into the app.yaml file</p><pre>//app.yaml<br>service: gce-tmmiot-app<br>runtime: nodejs10<br>instance_class: F2</pre><p>The web page will get by default HTTPS access and the URL is the following <a href="https://gce-tmmiot-app-dot-tell-me-more-iot.appspot.com/">https://gce-tmmiot-app-dot-tell-me-more-iot.appspot.com</a></p><p>constructed from <a href="https://[service-name]-dot-[project-id].appspot.com">https://[service-name]-dot-[project-id].appspot.com</a></p><p>So after deploying you can see the live stats</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*jYxSA0SAox9n5ViEpO11-Q.png" /></figure><p>I would recommend to set the Quotas max allowance per day to 0$ for the beginning — that saves you from paying if you mess up things or a bot army crashes your site. Navigate to Settings:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*VxFf_Kyoa1ODE8mBqf0HsQ.png" /></figure><p>Well after doing all that you can enjoy your app from your phone form your wife’s laptop from your works laptop or anywhere else you have an internet connection.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*fYxWAHaCXRuzxcScT5qp6w.png" /><figcaption>Spoiler alert: This is how the application looks like when you integrate OAuth and a few more below steps.</figcaption></figure><h4>Adding Authentication</h4><p>As mentioned before. The past exercise was all public accessible. But I am sure that especially going fwd. not everyone would like to share his device measurement with the world. This is why we introduce authentication. Despite a common misunderstanding that this will hold others from stealing your data (which can be solved using authorization concepts) its just enabling getting your google account id your name and your profile picture to our application in a secure way (OAuth is safe — at least for now).</p><p>In order to check which data is handed over to which user. The user needs to register his device to his google account id. This id is then saved to the device-id and we query always that the authenticated user only can access this data only. Sounds easy — well it kind of is — with GCE.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/637/1*3om16OFjF84kDBC2s4pO5g.png" /><figcaption>API &amp; Services — OAuth setup</figcaption></figure><p>As shown above we need to add our URLs (test and production) to the authorized ones. With that we get a client ID and a secret — both we need to setup in our node.js application.</p><p>The magic happens in lib/oauth.js where we read our config.json file which holds the above mentioned client ID secret and OAtuh callback link</p><p>Make sure that you have one config.json for your testing enviroment (“local”) and one for production — both files only differ in the OAUTH2_CALLBACK link.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*s9zQXLQqiPq_GW4ZnWKU2A.png" /><figcaption>config.json for the production app engine deploy</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*k2GtQus_FRB9qYvzgL6Cqg.png" /><figcaption>lib/oauth.js where we read in the config.json file</figcaption></figure><p>After getting all the routes private by adding OAuth to the handler i have designed the back-end Datastore to hold one Kind as the “produced devices”. Once the customer get his device he can register it using the id of the device to his account.</p><pre>...<br>router.post(&#39;/register&#39;, <strong>oauth2.required</strong>, (req, res) =&gt; {<br>...</pre><p>From here we have pretty much everything in place for accessing the streamed data from a web interface. Bearing in mind that the device would need to have been manually added with its public key to the IoT Core and configured to pub/sub (manufacturer). In addition the device name would have to be added manually (after production) to the database.</p><p>Once that is done any user can log into the web page and register the device just entering the name of the device (the device id, should be chosen as not guessable — maybe 81 trytes ;-9.</p><p>We will for sure need to make that process a bit more automated going fwd. Next its scheduling a recurring deletion of all data which is older than 7 (or 1) days from the Datastore.</p><h4>Deleting the old data from Datastore</h4><p>GCE app engine provides the so called cron job within its interface. Which just executes a publicly accessible URL of your app (the public can be omitted and this is what we would really need to do). Anyways this time I just use a very unique non guessable URL (“/deleteAllOldData123456789”)and connect to the cron job. My cron.yaml looks like that</p><pre>cron:<br>- description: &quot;delete every 24h data which is older than 1 day&quot;<br> url: <strong>/private/</strong>device/deleteAllOldData123456789<br> schedule: every 24 hours<br> target: gce-tmmiot-app</pre><p>In my router (device.js) I have added the route</p><pre>router.get(&#39;/deleteAllOldData123456789&#39;, (req, res, next) =&gt; {<br>     getModelDevice().deleteAllOldData(null, (err, response) =&gt; {<br>         <strong>if</strong> (err) { console.log(&quot;err: &quot; + err)}<br>         <strong>else</strong> {<br>             res.status(200).send(&#39;Done&#39;);<br>         }<br>     });<br>});</pre><p>And the datamodel handling with Datastore uses this (in /model/datastore-device.js ):</p><pre><strong>function</strong> <strong>_delete</strong>(id, cb) {<br> <strong>const</strong> key = ds.key([kind_data, parseInt(id, 10)]);<br> /** <strong>TODO:</strong> only allow deleting parts with no children */<br> ds.delete(key, cb);<br>}</pre><pre><strong>function</strong> <strong>deleteAllOldData</strong>(option, cb) {<br>   time7Days = Math.floor(<strong>new</strong> Date() ) - 1*86400*1000;<br>   //console.log(&quot;time7Days: &quot; + time7Days)</pre><pre>   <strong>const</strong> q = ds<br>   .createQuery([kind_data])<br>   .filter(&#39;time&#39;, &#39;&lt;&#39;, time7Days)<br>   .select(&#39;__key__&#39;);</pre><pre> ds.runQuery(q, (err, entities) =&gt; {<br>   <strong>if</strong> (err) {<br>     cb(err);<br>     <strong>return</strong>;<br>   } <strong>else</strong> {<br>       <strong>for</strong> (i <strong>in</strong> entities) {<br>         //console.log(&quot;entity: &quot;+ JSON.stringify(entities[i][ds.KEY][&#39;id&#39;]));<br>         _delete(entities[i][ds.KEY][&#39;id&#39;], (err, success) =&gt; {<br>             <strong>if</strong>(err) {}<br>             <strong>else</strong> {<br>                 cb(null, &quot;done&quot;)<br>             }<br>         });<br>       }<br>   }<br> });<br>}</pre><p>Strange that even without extending the index.yaml by the code seems to work. The above model is not very robust apparently, assuming massive amount of new data in Datastore, deleting them, should be handled via Cloud Flow (another Google service) — which is actually quite good at big data and uses strategies like map reduce to stay robust and in sync.</p><pre>//maybe to be added to indey.yaml<br>- kind: tmmiot_datastore_2<br>properties:<br>- name: time<br>- name: __key__</pre><p>In this example we will just leave the past 1 day data in Datastore. Honestly I don’t know what is more expensive to execute the delete or store the data — as always a function of how many devices ingest the data I suppose. For the moment we leave it like that an bear in mind that the customer like to maybe skim older data as well. Knowing that we might compress this data in Datastore in a mean value per day representation…</p><p>Or a second way would be to let the user query BigQuery directly for older data accepting the worse latency.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/968/1*1e-TcWE4JLG3PpUVA-IENw.png" /><figcaption>Final application up until here with chart representation of measurement and device registration page</figcaption></figure><p>I like your comments, corrections and suggestions 👌.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ae285e7e34b2" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Tell me more Internet of Things — Part 4— IOTA cost and value comparison]]></title>
            <link>https://medium.com/coinmonks/tell-me-more-internet-of-things-part-4-iota-cost-and-value-comparison-381008495d1d?source=rss-14c8d196ddc0------2</link>
            <guid isPermaLink="false">https://medium.com/p/381008495d1d</guid>
            <category><![CDATA[blockchain]]></category>
            <category><![CDATA[iot]]></category>
            <category><![CDATA[cloud]]></category>
            <category><![CDATA[technology]]></category>
            <category><![CDATA[iota]]></category>
            <dc:creator><![CDATA[Jan Bertrand]]></dc:creator>
            <pubDate>Mon, 04 Mar 2019 19:57:46 GMT</pubDate>
            <atom:updated>2020-08-26T14:06:24.572Z</atom:updated>
            <content:encoded><![CDATA[<h4>IOTA— How to stream your device data via IOTA (MAM) messages to the distributed immutable Tangle and visualize its content.</h4><p><a href="https://medium.com/@bertrand.jan/tell-me-more-internet-of-things-part-1-iot-platform-cost-and-value-comparison-558ce8966767">Part 1</a> <strong>| </strong><a href="https://medium.com/coinmonks/tell-me-more-internet-of-things-part-2-google-cloud-iot-cost-and-value-comparison-38bfb20d94e1">Part 2<strong><em> </em></strong></a><em>| </em><a href="https://medium.com/@bertrand.jan/tell-me-more-internet-of-things-part-3-mindsphere-cost-and-value-comparison-b333ebfb872a">Part 3</a><em> | </em><a href="https://medium.com/@bertrand.jan/tell-me-more-internet-of-things-part-4-iota-cost-and-value-comparison-381008495d1d"><strong>Part 4</strong></a><em>| </em><a href="https://medium.com/@bertrand.jan/tell-me-more-internet-of-things-part-5-google-cloud-user-handling-ae285e7e34b2">Part 5</a><strong> </strong><em>|</em><a href="https://medium.com/@bertrand.jan/tell-me-more-internet-of-things-part-6-google-cloud-user-input-push-subscription-aa39ebc4a348">Part 6</a> <em>| … | Part n</em></p><p>In <a href="https://medium.com/@bertrand.jan/tell-me-more-internet-of-things-part-1-iot-platform-cost-and-value-comparison-558ce8966767">Part 1</a> we introduced the targets and hardware in <a href="https://medium.com/coinmonks/tell-me-more-internet-of-things-part-2-google-cloud-iot-cost-and-value-comparison-38bfb20d94e1">Part 2</a> Google IoT and <a href="https://medium.com/@bertrand.jan/tell-me-more-internet-of-things-part-3-mindsphere-cost-and-value-comparison-b333ebfb872a">Part 3</a> MindSphere.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/315/1*iqJR08LDh3q3wqcNM0av6w.png" /></figure><p>This article compares IOTA and uses its protocols for our specific business / use case and compares it to the selected IoT platform solutions.</p><p>I send measurement data to the Tangle (IOTA’s immutable database network) and explore how to visualize it for our scaled, hopefully successful environmental sensor business case. The questions on how expensive will be this implementation per device and what is in for the user. Bearing in mind that the current network and protocol is under constant development and that the future importance and advantages of IOTA maybe only fully unfold when moving from Internet based to mesh IoT network based architectures. Furthermore for our use-case in my opinion a combination of cloud based and IOTA based features would be more appropriate for the moment anyways.</p><p>When it comes to Blockchain or in this case Distributed Ledger Technologies (DLT) usually its cryptocurrencies which comes to everybody’s mind. For the moment we won’t need this feature. IOTA, beside enabling the exchange of value transactions (like other cryptocurrencies) has some interesting other features. As widely known IOTA enables no-fee based zero value immutable transactions. This service alone could be used to onboard all the data to IOTA’s network, but it is not organized (streamed) nor private. This is were a second level implementation Mask Authenticated Messaging (MAM) claims to introduces a secure and reliable streaming of data to this permissionless distributed ledger. The trick for enabling zero fee transactions lies with ending the separation of those who validate the ledger (called incentivized miners in other blockchain architectures) and those who perform transactions in the network. In IOTA you are both and if you like to add a transaction you need to validate two others before yours gets validated.</p><p>Sounds good. Lets try to implement the easiest solution for the M0-M3 milestones first and then explore the costs when scaling the use — case.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/0*Qq5xo7j5sRbnIpUM" /></figure><p>This article and the implementation of the use case mainly follows.</p><ul><li><a href="https://www.iota.org/">https://www.iota.org/</a></li><li><a href="https://www.mobilefish.com/developer/iota/iota_quickguide_raspi_mam.html">https://www.mobilefish.com/developer/iota/iota_quickguide_raspi_mam.html</a></li><li><a href="https://discordapp.com/invite/fNGZXvh">https://discordapp.com/invite/fNGZXvh</a></li><li><a href="https://github.com/iotaledger">https://github.com/iotaledger</a></li><li><a href="https://thetangle.business/">https://thetangle.business/</a></li></ul><p>Certainly there is already an excellent open minded community which sets up many tutorials and Proof of Concept (PoC) cases available even though the IOTA Foundation is quite early to the party. I try to implement a solution based on the open source freely available protocol and point out where we would need to adapt when scaling up from our prototype.</p><h3>Overview of implementation and results</h3><p>The solution is based on</p><ul><li>Sending data with MAM. This is the MAM publisher program from our Raspberry Pi (RPi). MAM object creation and signing is done on device.</li><li>Performing the tip selection (find randomly two transactions which needs validation called as a function getTransactionToConfirm (gTTA)) on a serviced Permanode for the cost calculation. <em>Actually using the devnets full Node for the prototype in the implementation (which comes for free).</em></li><li>Outsourcing Proof of Work (PoW) to the same full Node. (<a href="https://devnet.thetangle.org/nodes;">https://devnet.thetangle.org/nodes;</a> <a href="https://powsrv.io/">https://powsrv.io/</a>)</li><li>Broadcasting it via the same full node which then gossips it to its neighbors to the entire network.</li><li>Using MAM to fetch the data — MAM receiver — on a web application deployed on google app engine.</li><li>Visualization via google charts (deployed on google app engine).</li></ul><p>Most of the libraries of IOTA’s ecosystem are on github. Meaning we can use our package manager to quickly dive in.</p><p>As IOTA is permissionless we don’t need to create somewhere an account or get any other authorization to use the system. As it turns out the property “permissionless” is most exciting but as well most difficult to property to secure the network.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/731/1*SArrNhZR8SzRstEtP73OHw.png" /><figcaption><em>Overview of flow of data</em></figcaption></figure><p>A much more advanced and complete prototype of a real MAM use case has been implemented and written down by <a href="https://medium.com/@erwinrooijakkers/gdpr-compliant-smart-meter-data-on-the-iota-tangle-four-lessons-learned-while-putting-the-dea852a5b2aa">Erwin Rooijakkers</a>.</p><p>He listed already some of the current drawbacks like</p><ul><li>Non available out of the box secure authorization of your MAM channels.</li></ul><blockquote>Will most likely been introduced in the upcoming <strong>MAM+</strong> release</blockquote><ul><li>Non availability of permanodes (services) which stores the immutable data forever. (Drawbacks of having an immutable encrypted storage for ever and its implication of future tech potentially exploiting it.)</li></ul><blockquote>There is a service now available in beta (prices are subject to change) the estimation in this article only reflect the current pricing table — February 2019 <a href="https://thetangle.business/">https://thetangle.business</a></blockquote><ul><li>Currently relatively high computational / energy costs for the Proof of Work (PoW) (used as a spam protection for the network) necessary before attaching a message to the tangle.</li></ul><blockquote>Can be significantly optimized using Field Programmable Gate Arrays (FPGA)</blockquote><ul><li>Computational effort for the tip selection. The algorithm is necessary for finding the best two tips to be confirmed before issuing the transactions.</li></ul><p>When it comes to the current relatively high PoW requirements we have some even more recent analysis available by <a href="https://hackernoon.com/lessons-learned-from-evaluating-iota-on-internet-of-things-devices-a44575e606de">Atis Elsts</a> and by <a href="https://medium.com/@punpck/iota-crypto-core-fpga-1st-progress-report-caebe1dac579">MicroEngineer</a>.</p><p><strong>The computational effort of PoW</strong></p><p>Beside all the other tasks (Trytes to Byte conversion, signing, etc.) PoW holds the heaviest job for the device. Both show 83s to 90s for PoW on our RPi(not knowing which PoW implementation they used). Which would work for us as we just send every 3 minutes a new measurement.</p><p><strong>The energy consumed for doing PoW</strong></p><ul><li>Atis article derives approximately 55J (Joules) for the PoW which is 1.5*10^-5 kWh.</li><li>Erwins article derives 0,00005kWh ~180J for one transaction for the PoW.</li></ul><blockquote>As far as I understood the computational time and with that the necessary energy consumed can be reduced to approximately 300ms at the moment using a FPGA instead of the RPi. Basically implementing the PoW routines with hardware gates to accelerate its computation.</blockquote><h4>Message size and TPS requirements</h4><p>Assuming 1600 bytes per IOTA transaction (2673 trytes) and we need two transaction per MAM message. Further every device send every 3 minutes one MAM message (this is for our message 2 IOTA transactions).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/490/1*5V1BFl9svTz8quMip17deA.png" /></figure><p><strong>Implementation #1 (currently possible)</strong></p><ul><li>The Full Node is performing the PoW, gTTA and findTransactions (all heavy tasks outsourced — we need to trust the Node here).</li><li>The Node just never performs snapshots (growth with the tangle network and all its transactions).</li><li>MAM implementation without public key encryption (we just send the encryption key (side-key) e.g. by email).</li></ul><p>This is my estimation based on thetangle.business service rates. Using getTransactionToApprove (gTTA) — the tip selection (0.3€ per 1000 executions) and then attachingToTanlge (PoW) (1€ per 100 executions). Further I have just assumed per user 100 fetches (findTransactions) from the MAM stream per day. We need for one MAM message (with the current payload and security) two transactions. Both transactions to be valid to be broadcast would need perform PoW. But we only need one gTTA for the MAM bundle .</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/639/1*SGYejBlooRbP20kqWNBtCw.png" /><figcaption>Cost for the use case for implementation #1</figcaption></figure><p>This is a steep price and probably not worth to follow for our use case for now.</p><p><strong>Implementation #2 (currently possible)</strong></p><ul><li>Our RPi device is performing the PoW in ~90s / transactions. For our MAM message this would take ~180s . The energy costs would be with the device holder.</li><li>The Node performs local snapshots after (let’s say 100 days) (data is lost after snapshots ) which means we lose older data. <em>We just use for our cost estimation the permanode service from thetangle.business</em>.</li><li>MAM implementation with self-made key encrypted exchange (hopefully quantum proof).</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/644/1*9Po6Law2UfyIwc_7jQ2_5g.png" /><figcaption>Estimation of cost for Implementation #2</figcaption></figure><p>Estimation is based on thetangle.business rates for gTTA and findTransactions. The PoW is done on the RPi and tries to approximate only the portion of energy necessary for PoW ( knowing that the RPi has to run anyway full time). For one device it’s assumed to stay in the always free limits but only cost the user in additional energy costs.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/588/1*9bSoNbFY1_x__lz_yuNybQ.png" /></figure><p>I stay positive that prices can be further reduced when using optimized HW and SW <strong>K1</strong>. As pointed out earlier it is all beta and early. <br>When it comes to the soft points I experienced some difficulties to figure out which libraries are up to date and can be used. Discord chat and the community really helps here when stuck <strong>K3</strong>. I particular liked the move from the foundation to restrict the chat to more development related topics rather than having it’s all about submerged in price talks on the IOTA token. Just recently the documentation got a new facelift too. The development talks are even live to be followed in the chat now - thats very interesting! The functionality which is provided out of the box is all available or getting build in variety of programming languages — but there is no real graphical user interface based platform yet .</p><p>When it comes to our particular use-case (visualization of environmental sensor data) its all a bit to much drama to store every measurement on the tangle and visualize it form there.<strong> </strong>But when you imagine it becomes necessary (by law) for hospitals to measure contamination levels — an immutable ledger for the audit trail might get more interesting (cost and value wise).</p><p><strong>Implementation #3 (possible future setup — omega)</strong></p><ul><li>The device is performing PoW in a very efficient way (maybe even only very limited amount, less than required today). Main protection will be Network-bound Proof of Work (NBPoW).</li></ul><blockquote>Bandwidth is a scarce recourse and naturally will limit the ability of bad actors as the costs of reserve a dominant part of the bandwidth becomes too expensive.</blockquote><ul><li>Permanodes store all <em>necessary</em> transactions.</li></ul><blockquote>Either distributed (not all transactions on one node) with Iota Controlled agenT (ICT) - incentivized via IOTA tokens. Or centrally via IRI permanode — icentivised via IOTA tokens. At least that is my limited understanding of it.</blockquote><ul><li>MAM+ used with out of the box sidekey safely encrypted exchange.</li></ul><p>In order to fully enjoy this architecture I am afraid we will need to wait some years.</p><h3>Implementing the use case</h3><p>As outlined earlier IOTA is getting actively developed. By joining the Discord chat you can even see the Devs exchange information for there PRs on github. As well the second level protocol MAM is under development towards MAM+.<br>That means that the library I am using below might be in parts already outdated when you read this.</p><h4>Transmitting a message on a public MAM channel</h4><p>On the RPi</p><pre><strong>pi@raspberrypi:~/tmmiot $</strong><br>mkdir IOTA</pre><pre><strong>pi@raspberrypi:~/tmmiot/IOTA $</strong><br>git clone <a href="https://github.com/jhab82/tmmiot-IOTA-agent.git">https://github.com/jhab82/tmmiot-IOTA-agent.git</a></pre><pre><strong>pi@raspberrypi:~/tmmiot/IOTA/tmmiot-IOTA-agent $</strong><br>npm install</pre><p>Before we are transmitting the sensor data lets shortly try to just send a message and understand what are the different options provided by MAM.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/45346d61c7cb06b204e44dbe46d26540/href">https://medium.com/media/45346d61c7cb06b204e44dbe46d26540/href</a></iframe><p>The above code initializes the MAM object that is necessary to create the MAM channel (For those who like to deep dive into this construct of Merkel trees go for it <a href="https://github.com/l3wi/mam.client.js/blob/master/docs/overview.md">short</a> or <a href="https://medium.com/coinmonks/iota-mam-eloquently-explained-d7505863b413">long</a>)</p><p>We need the IOTA javascript library const IOTA = require(’iota.lib.js’)which allows us to create transaction and outsource work to a IOTA Server (full Node). These Servers are distributed, mostly Virtual Private Server VPS (on AWS, Google Cloud or Azure) running IOTA Reference Software (IRI). The so called full nodes are the backbone of the <strong>current</strong> IOTA network.</p><blockquote>IOTA was developed bearing in mind a mesh network environment of the future IoT. The current network tries to simulate the performance with measures like manual peering and computational PoW.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/960/1*bnyt8PCkFhjrgzYxDz1QrQ.png" /><figcaption><a href="https://www.iota.org/get-started/faqs">https://www.iota.org/get-started/faqs</a></figcaption></figure><p>As we have not installed a full node ourselves we are using public available full nodes and its exposed API to attach our message to the tangle. And as we are in development state, we certainly use the IOTA foundation provided development tangle https://nodes.devnet.thetangle.org</p><p>Further we initialize our MAM object with the IOTA provider Mam.init(iota, undefined, 1)and define it to be of lowest security and change it to be public. MAM can be</p><ul><li><strong>public </strong>(meaning everyone with the address — we call it root address here — can read the stream) and</li><li><strong>restricted</strong> (only with the root-address and a password (side-key) chosen by the publisher) and</li><li><strong>private </strong>(only the seed holder).</li></ul><p>That is already quite a bit of deep diving into the words and phrases used by the IOTA ecosystem. Don’t worry though we have not even touched the surface of this complex undertaking 😄 but the onboarding of data is very quick.</p><p>In the code we have an async publish function which translates our payload to trytes and attach it via Mam.attach to the tangle. Here the full node takes the heavy job of finding the two tips to confirm (gTTA) performs PoW with those tips. On the RPi the transactions gets constructed (if private or restricted as well signed) and then send to be broadcast.</p><pre><strong>pi@raspberrypi:~/tmmiot/IOTA/tmmiot-IOTA-agent $</strong><br>node mam_min_publish.js</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/0*sAnOwEf6ee6r3yr-" /><figcaption>Feedback of the channel-id / root / address</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/0*gR1M6Bz3sxdalV74" /><figcaption>RTPSMMSRXHS9TKHVNJ9B9KPVJSVOET9JRJVPVTZJTVCYZVKXVIWBLWIKAQCGNKBVJMEEA9GWVQEGGTOHKLLTWDD9WD</figcaption></figure><p>It takes two IOTA transaction for our one MAM message. If you increase the size of the payload above the limits of an IOTA transaction (according to <a href="https://docs.iota.org/introduction/iota-token/anatomy-of-a-transaction">iota.org</a> you can store 2187 trytes in this message) or change the security setting you would need more transactions per MAM message.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/0*LO48jbkN2dopYAzi" /></figure><p>The tangle explorer shows us that we have created two transactions which got immediately confirmed.</p><p>In IOTA every transaction needs to validate two other transactions (those two transaction to confirm can be found by the tip selection or the getTransactionToApprove (gTTA) function). When it comes to zero value transaction they don’t need any validation though. Once they are broadcast to the tangle they get accepted. Contrary to value transactions which gets only confirmed when validated by others (basically making sure value is not created nor deleted - excluding double spends).</p><p>In order to protect the network from spam the IOTA network requires some Proof of Work (PoW) for every attached transaction. PoW needs some computational power and for now we outsource this to the public available full node (which luckily provides this via their API for free).</p><p>With the public MAM decoder we get the decoded message and the channel ID which is the root address and the next channel ID (next root address) where the next message would be stored.</p><p>The above screenshots shows us that we have stored our data successfully and that we can fetch it with the provided root-address (channel-ID).</p><h3>What is different to the other implementation</h3><p>Contrary to both other IoT platforms we did not authorize , register or had to set up an account nor give any credit card details for future billing — awesome you might think now, I’ll store all my data here. Unfortunately you can’t. At least not forever that easy. In order to keep the full nodes databases reasonable small — the database needs to get pruned from time to time (IOTA calls that a snapshot). Meaning only the balances of the IOTA addresses gets summed up and the database start all over again of course with sound consensus on the state of all non-zero balances. <em>So the data is not immutable at all?</em> Sure it is before the node gets pruned manually — <strong>or you have a Permanode which keeps all data and let you query it (most likely for a fee as in thetangle.business).</strong></p><p>In addition to the other IoT platforms you wont have a central authority in this network which could view, alter or delete your data. Its is not Google or Siemens, I mean the administrator who authorizes your access. I am sure there are different approaches with sound rights management and encryption to limit the possibility of access in centrally organized permissioned systems, but they all prone to fail once we are moving to the machine economy.</p><p>Another features for the paranoid data owner in IOTA is its claimed quantum computer resistant encryption architecture. That sounds so futuristic and I honestly am by no means knowledgeable enough to discuss post-quantum cryptography with you. Anyways what I understood is that most public key algorithms are able to be broken by sufficiently powerful future quantum computers. One Time Pad OTP based architectures are not that easy to brute forced by very efficient quantum computing.</p><p>To sum it up we have</p><ul><li>created a MAM encoded message</li><li>attached this message via remote PoW to the tangle</li><li>received the message via a public tangle explorer (providing the channel-ID / root-address)</li><li>decoded the message via the public web interface</li></ul><p>When executing our above program again a new channel-ID will be generated which leaves our messages unrelated. But we like to be able to stop our stream and resume to the same channel when starting over again. Let’s do this next.</p><h3>Resume publishing on a created channel</h3><p>In order to resume publishing on a channel we need to store the next root address and some other information (including the seed) from the state of the MAM object (mamState).</p><p>In order to always restream the entire channel we need to store as well the first root-address. I have rewritten the code above to just do this. Now we can resume publishing on this public channel and would be able even after a our RPi breaks down to resume the channel.</p><p><a href="https://github.com/jhab82/tmmiot-IOTA-agent/blob/master/mam_resume_publish.js">jhab82/tmmiot-IOTA-agent</a></p><p>Next we restrict the channel from others to be viewed — we need to change the MAM object to be encrypted by a chosen password (side-key).</p><h3>Change the channel to restricted mode</h3><p>There is only very little to be changed to the code except creating a key and transforming the key to trytes:</p><pre>const key = iota.utils.toTrytes(&quot;tmmiot-iota-sideky&quot;);</pre><p>Then we need to change the Mode of our mamState:</p><pre>mamState = Mam.changeMode(mamState, &quot;restricted&quot;, key);</pre><p>That’s it from here we can’t use the tangle explorer but another explorer to view our restricted channel. Reviewing the mamChannelRoot.json which is created now with every new channel we have all the information to request the stream.</p><pre>{&quot;subscribed&quot;:[],&quot;channel&quot;:{&quot;side_key&quot;:&quot;HDADADXCCDHDRAXCCDHDPCRAGDXCSCTCZCMD&quot;,&quot;mode&quot;:&quot;restricted&quot;,&quot;next_root&quot;:&quot;DKMVKBRGITNGLVEZPOGASILFTIRK9KFJHBKJESQKFIYMGOJLFQKWKFMGIPASCNNTBGR9ITJRQGYJSJILS&quot;,&quot;security&quot;:1,&quot;start&quot;:1,&quot;count&quot;:1,&quot;next_count&quot;:1,&quot;index&quot;:0},&quot;seed&quot;:&quot;UJHR9SDKXUOBNVHDGDXKPUBCABGPXDWAATCKITOTQRQSJJCBXONMZVDVKZDPPYXNZYLTQMHHJ9SISIDJF&quot;}</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/749/1*K2U9Ewc7twckui30C2XEqg.png" /></figure><p>When we resume the feed we get further entries.</p><h3>Adding the sensor data to the agent</h3><p>Just adding the package like we did for the other agents in Google and MindSphere.</p><p><a href="https://github.com/jhab82/tmmiot-IOTA-agent/blob/master/tmmiot_mam_publish.js">jhab82/tmmiot-IOTA-agent</a></p><pre><strong>const</strong> rpiDhtSensor = require(‘rpi-dht-sensor’); <br>//DHT sensor com package<br><strong>var</strong> dht = <strong>new</strong> rpiDhtSensor.DHT22(4); //on GPIO 4</pre><pre><strong>const</strong> Sensor = require(‘sds011-client’);//PM sensor com package <br><strong>const</strong> sensor = <strong>new</strong> Sensor(“/dev/ttyUSB0”); <br>// Use your system path of SDS011 sensor.</pre><pre>sensor.setReportingMode(‘query’); //set the PM sensor to query mode<br>sensor.setWorkingPeriod(3); //set the interval to 3min.</pre><p>And query our PM sensor. We get this every 3 min. published to our channel then.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/798/0*g5amUp7X06lnPQwv" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/0*ozSWZfQC_752GoPH" /></figure><p>Wonderful — we can run this nohup and leave the room and can rest assured knowing that we will have our sensor data secured, immutably stored in the tangle.</p><p>Just for remembering it — our RPi is not doing a lot of work though. Its fetching the sensor data every 3 minutes creating a MAM object from that and sends all the hardwork to the full node which provides us beside finding our transaction to confirm doing PoW and attaching the message to the tangle.</p><p>Probably the devnet full node are load balanced Virtual Private Server (VPS) — providing us with an entry point to the tangle devnet. But it could be as well a HW optimized cluster providing a very eco-friendly efficient service.</p><h3>Visualization of data</h3><p>Compared to Google Cloud implementation in <a href="https://medium.com/coinmonks/tell-me-more-internet-of-things-part-2-google-cloud-iot-cost-and-value-comparison-38bfb20d94e1">Part 2</a> we have not yet seen an old school database which can be queried with SQL to get us all the necessary information for visualization various metrics. With MindSphere the onboarded data is not yet queried with available APIs or the GUI — we just saw a predefined visualization of our own sensor data. Both IoT platforms are not ready to just onboard new environmental sensors — they are fully permissioned. An administrator would need to authorize them (as shown). Of course we would need to automate the onboarding process but for now its all manually permissioned.</p><p>With IOTA everyone could already just onboard their data individually with above guidance to the same tangle. But in order to have all the data from all sensors (100, 1000 and 10.000) we would need to think a bit further.</p><p>Of course we could implement a market-place which enables to store the individual root-addresses and their side-keys (potentially by providing a bit of cash to the owner or better IOTA tokens) but that is maybe for the later chapters (similar to <a href="http://data.iota.org/">data.iota.org</a>). For now we assume we know all the root-addresses and their side-keys.</p><p>Next I build a simple google chart application able to fetch the data from the tangle (by providing your root-key— similar to the firebase app we queried for our data but instead of listing the variables writing them to a chart.)</p><h4>Visualization of the MAM stream</h4><p>I have written a very rough visualization of a public MAM stream</p><p><a href="https://github.com/jhab82/iota-mam-visualization">jhab82/iota-mam-visualization</a></p><p>Whereas in a database you can query the latest 10 entries of a filtered object (e.g. device). With MAM you need to run from the root until the end. As the next root of the message gets derived from the actual root.</p><p>I have streamed my sensor data one day to the tangle having now 480 payloads stored immutable in this distributed ledger. In order to visualize this and continuously update the stream I need to store somewhere my root-addresses otherwise I would need to run from the beginning to the end through the MAM which is computationally heavy.</p><blockquote>There is already other MAM implementation in the making like <a href="https://medium.com/@lamberti.robin/random-access-authenticated-messaging-45a5f40f2532">RAAM</a>. Furthermore as mentioned there is a project MAM+ on the agenda from the foundation which might come with additional functionality.</blockquote><p>But here its the current MAM implementation. Or should I say I hope its the current. In order to reduce the computational effort we only derive the next message and store the the next root temporarily. The user can manually executes to decode the next message from that stream.</p><p>I have switched back to a public MAM stream (only because I don’t know how to securely ask for the sidekey on this backend implementation). I should have implemented it all client side (maybe next).</p><p>Code snippet from the backend function for fetching a single MAM message and the router.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/df451e4c463f7bb7508a28e0d255425c/href">https://medium.com/media/df451e4c463f7bb7508a28e0d255425c/href</a></iframe><p><a href="https://iota-mam-vis-app-dot-tell-me-more-iot.appspot.com/">https://iota-mam-vis-app-dot-tell-me-more-iot.appspot.com/</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/942/0*zkTSAOUllSVRUgXs" /><figcaption>Animated (GIF) for the implemented visualization of an MAM sensor stream</figcaption></figure><p>I like your comments, corrections and suggestions 👌.</p><blockquote><a href="https://coincodecap.com/?utm_source=coinmonks">Get Best Software Deals Directly In Your Inbox</a></blockquote><figure><a href="https://coincodecap.com/?utm_source=coinmonks"><img alt="" src="https://cdn-images-1.medium.com/max/584/0*OJ-qb5G6i863msBB.png" /></a></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=381008495d1d" width="1" height="1" alt=""><hr><p><a href="https://medium.com/coinmonks/tell-me-more-internet-of-things-part-4-iota-cost-and-value-comparison-381008495d1d">Tell me more Internet of Things — Part 4— IOTA cost and value comparison</a> was originally published in <a href="https://medium.com/coinmonks">Coinmonks</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Tell me more Internet of Things — Part 3 — MindSphere cost and value comparison]]></title>
            <link>https://medium.com/@bertrand.jan/tell-me-more-internet-of-things-part-3-mindsphere-cost-and-value-comparison-b333ebfb872a?source=rss-14c8d196ddc0------2</link>
            <guid isPermaLink="false">https://medium.com/p/b333ebfb872a</guid>
            <category><![CDATA[iot]]></category>
            <category><![CDATA[siemens]]></category>
            <category><![CDATA[cloud-computing]]></category>
            <dc:creator><![CDATA[Jan Bertrand]]></dc:creator>
            <pubDate>Wed, 06 Feb 2019 14:01:31 GMT</pubDate>
            <atom:updated>2019-09-22T07:22:42.653Z</atom:updated>
            <cc:license>http://creativecommons.org/publicdomain/zero/1.0/</cc:license>
            <content:encoded><![CDATA[<h4>MindSphere — device onboarding, data storage and visualization. How to connect your device to MindSphere via the MindConnect library (C and Node.js) and visualize the data.</h4><p><a href="https://medium.com/@bertrand.jan/tell-me-more-internet-of-things-part-1-iot-platform-cost-and-value-comparison-558ce8966767">Part 1</a> <strong>| </strong><a href="https://medium.com/coinmonks/tell-me-more-internet-of-things-part-2-google-cloud-iot-cost-and-value-comparison-38bfb20d94e1">Part 2<strong><em> </em></strong></a><em>| </em><a href="https://medium.com/@bertrand.jan/tell-me-more-internet-of-things-part-3-mindsphere-cost-and-value-comparison-b333ebfb872a"><strong>Part 3</strong></a><em> | </em><strong>Part 4</strong><em>| </em><a href="https://medium.com/@bertrand.jan/tell-me-more-internet-of-things-part-5-google-cloud-user-handling-ae285e7e34b2">Part 5</a><strong> </strong><em>|</em><a href="https://medium.com/@bertrand.jan/tell-me-more-internet-of-things-part-6-google-cloud-user-input-push-subscription-aa39ebc4a348">Part 6</a> <em>| … | Part n</em></p><p>In <a href="https://medium.com/coinmonks/tell-me-more-internet-of-things-part-2-google-cloud-iot-cost-and-value-comparison-38bfb20d94e1">Part 2</a> of this series we explored Google IoT for our environmental sensor device. The average cost per device was determined to ~0.7 €/device per year. There was even a solution which was entirely free (in case you wont get any paying participants / customers 😏).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/1*QqvD9HPQQBRkh_Y58_41hw.png" /></figure><p>Here we do the same but with Siemens MindSphere. Thanks to my friends in Siemens I have access to an account. It’s not for free and the pricing is simply sorted in to three different plans (small, medium, large). All necessary increases beyond the plans allowances are not transparent. As our scaled use case is well above some of the plans limits I try my best to estimate the costs.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/663/1*WqKQgdz7CT8-Y0SFIby01g.png" /></figure><p>My approach is based mainly on</p><ul><li><a href="https://documentation.mindsphere.io/#/kiosk">https://documentation.mindsphere.io/#/kiosk</a></li><li><a href="https://developer.mindsphere.io/">https://developer.mindsphere.io/</a></li></ul><p>Certainly there is not so much third party tutorials compared to Google Cloud. I try to implement the most straightforward solution and where necessary point out the necessary adaptation when scaling up.</p><h3>Overview of implementation and results</h3><p>The solution is based on onboarding the device</p><ol><li>via the MindConnect Library <strong>M1</strong></li><li>On our raspberry pi device we use the @mindconnect/mindconnect-node.js library for onboarding and sending the data to our registered mclib-asset.</li><li>Show how you can use the publicly available C library to create your custom agent.</li><li>Creating an assets for receiving the data (agent-asset or mclib-asset) <strong>M2</strong></li><li>Creating an asset for visualizing the data (referencing, data-mapping, the agent-asset).</li><li>Visualizing the data via the Fleet Manager <strong>M3</strong></li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/796/1*sN4J-vkFehTH1r8kSNxTaA.png" /><figcaption><em>Overview of flow of data for visualization in MindSphere</em></figcaption></figure><p>This implementation does still <strong>not</strong> provide</p><ol><li>User Management — individual visualization and event suggestions.</li><li>Automated data analytics for the user (e.g. out of the box functions like MindSphere’s own predictive maintenance app)</li></ol><p>I am afraid you need to wait until MindSphere will offer free tier (developer) value plan accounts or pay the smallest plan (~3600€/year). We use the Graphical User Interface (GUI) for creation of:</p><ul><li>Aspects (which act for us as templates for the sensors variables) and</li><li>Types [Basic Assets] (which act as templates for our raspberry pi edge (referencing all sensor variables)</li><li>Asset 1 — “Visualization” asset referencing our newly created basic type(Visualization of onboarded asset).</li><li>Asset 2 — “mclib&quot; asset referencing the mclib core.mclib template.</li></ul><p>We do need administrator rights (the standard user as well as the subtenant user does not have the necessary rights to create any of these objects)</p><p><em>We create just one subtenant which represents our collective pi-sensor data store (note: we have not yet introduced the user itself, which likes to visualize their own data). The subtenant can see only his dedicated assets (which looks like we need as many subtenants as users if we proceed to the next Milestone M4 — but that is for later articles to be examined.)</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/840/1*24_mvFp-7ZrVauywq3t9BA.png" /><figcaption>Status of implementation</figcaption></figure><p>The current implementation (w/o users and individual visualization and event monitoring) has a comparable high price. That is a factor 100 compared what would Google Cloud IoT charge. <strong>Knowing that most of the functionality and services provided by the base MindSphere plan we just won’t use at the moment</strong>. Especially the amount of agents which need to simultaneously ingest data to our MindSphere tenant (account) drives the price, as we have to increase the plan to accommodate for more agents onboarded. Both 1.000 and 10.000 device scenarios are not covered by the base plans and I have extrapolated the cost to show the comparison.</p><p>The below costs are just an estimation based on (past) publicly available information and are both not released by Siemens nor reviewed <strong>K1</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/735/1*URt0oBBbjhZlrbtoY3N82w.png" /><figcaption>Estimated costs for current implementation based on public available information (no binding quotes or equally relevant information)</figcaption></figure><p>Beside the limits for agents we exceeding asset instances for the 10.000 device scenario. The data ingest stays well below. The following table shows as well that we won’t utilize most of the other functions.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/696/1*QEnrkBiXG4QU-q583Z580g.png" /><figcaption>MindAccess IoT Value Plan — Size overview compared to size requirements of our application</figcaption></figure><p>Looking to the soft factors — MindSphere is easy to set up. Of course the compilation of your own C agent takes time but the available node.js library is very easy to use for prototyping <strong>K3.</strong> When it comes to documentation I would like to see some more end to end use cases from the community, but there is already quite a bit of official docs and examples available including Siemens own forums (most of it internal though) <strong>K4.</strong> MindSphere provides out of the box visualization which is in my opinion far easier to set up compared to google data-studio (but as well much less customizable) <strong>K5.</strong></p><p>Anyway it seems that MindSphere is not focusing on this IoT market which accommodates massive amounts of “agents” (like in our scaled use-case). MindSphere allows much more data ingest and assumes to be competitive with less devices ingesting with higher output.</p><p>When it comes to database handling or data storage we need to further see how we could implement our further project milestones using the MindSphere open platform.</p><h3>Implementing the use case in MindSphere</h3><h4>Registering a new user as subtenant</h4><p>The below picture story shows what the administrator of the tenant has to do to create a subtenant and a new user. Below the user screens for registering and login to MindSphere are shown.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*cUpbljCND1pdj7i9R2ULEw.png" /></figure><h4>Creating the aspects, types and assets</h4><p>As mentioned earlier creating the aspects, types and the users-own sensor representation is the tenant admin job. The subtenants users does not have the rights to create those assets.</p><p>We need to create the communication asset (mclib-asset) which authorize our device to onboard and to exchange data via predefined datapoint ids. And we need to create an asset which maps those datapoints and is able to visualize the data.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*bPON_j8_Z1o-mlXLYSIiEg.png" /><figcaption>Creating types, basic-asset (aspect), asset</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*mrADQ_a5aIV9HKH5AGtQaA.png" /><figcaption>Creation and configuration of mclib-asset</figcaption></figure><h3>Onboarding the sensor data</h3><p>Our raspberry pi has no preferred protocol for exchanging data to another device. If you are in the process industry usually the sensors are connected via BUS (Profibus, Modbus) or via 4–20mA analog signals to I/O cards from there digitalized and onboarded for the automation program. If you have a Mindconnect Nano or a S7 automation program you could onboard with those devices / protocols directly (Either with the IoT Extension or directly via a MindConnect Nano) .</p><blockquote><strong>Edited 07.02.2019:</strong> Thanks Marion. The value base plan comes already with the IoT Extension which allows 5GB data ingest. If more is needed the upgrade to 20GB holds additional costs.</blockquote><p>With the raspberry we connect to the internet via WiFi and will communicate via node.js MindConnect library (agent) to MindSphere (we will compile our own C agent too ). The agent is communicating with the mclib assets securely via a shared secret. That is necessary for our use case we certainly can’t integrate a MindConnect Nano from Siemens to onboard and data communication (Otherwise we would need 10.000 nanos 😅). Beside the less computational shared secret encryption we could choose RSA too.</p><h3>C MindConnect library agent compilation, agent onboarding and timeseries upload</h3><blockquote>Thats the tough part — if you like to see why I think its easy to set up, skip to the below node.js implementation.</blockquote><p>You get the latest mclib version <a href="https://support.industry.siemens.com/cs/document/109755348/mindconnect-library-3-1-for-mindsphere-3-0-?dti=0&amp;lc=en-WW">here</a>. Some of the below scripts and files I have shared here: <a href="https://github.com/jhab82/tmmiot-MindSphere-mclib-agent">https://github.com/jhab82/tmmiot-MindSphere-mclib-agent</a></p><p>After accepting the conditions for using the library you are allowed to download. I have saved my version in google drive and shared the link for me being able to get it via the command line like this:</p><pre>@raspberrypi:~/tmmiot/MindSphere $ <br>curl -L &quot;<a href="https://drive.google.com/uc?export=download&amp;id=1HX51t28XR80-tPcDi8P00xYfQesbgb8E">https://drive.google.com/uc?export=download&amp;id=</a>YOURIDOFTHEFILE&quot; &gt; mclib.zip</pre><p>Most of the raspbian images come with a long list of pre-installed software. Mine came with zip for unzipping our mclib.</p><blockquote>The next steps are summarizing the C agent build explained in the README</blockquote><pre>@raspberrypi:~/tmmiot/MindSphere $<br>unzip mclib.zip</pre><p>Creating a few directories</p><pre>#!/bin/bash<br>mkdir tmmiotAgent<br>mkdir tmmiotAgent/build<br>mkdir tmmiotAgent/build/openssl<br>mkdir tmmiotAgent/build/curl<br>mkdir tmmiotAgent/build/mcl<br>mkdir tmmiotAgent/build/agent<br>sudo chmod 755 tmmiotAgent</pre><p>Copy the mclib files to tmmiotAgent/MCL_Core</p><pre>@raspberrypi:~/tmmiot/MindSphere $<br>cp -r MindConnect_Library_V3.1.2.0 MCL_Core<br>mv MCL_Core tmmiotAgent/</pre><h4>Building SSH</h4><p>Downloading SSH</p><pre>@raspberrypi:~/tmmiot/MindSphere $<br>wget <a href="https://www.openssl.org/source/old/1.0.2/openssl-1.0.2k.tar.gz">https://www.openssl.org/source/old/1.0.2/openssl-1.0.2k.tar.gz</a></pre><p>Unzip to tmmiotAgent</p><pre>@raspberrypi:~/tmmiot/MindSphere $<br>tar xvzf openssl-1.0.2k.tar.gz -C tmmiotAgent/</pre><p>Configure &amp; install</p><pre>@raspberrypi:~/tmmiot/MindSphere/tmmiotAgent/openssl-1.0.2k $ <br>./config — openssldir=/home/pi/tmmiot/MindSphere/tmmiotAgent/build/openssl shared -fPIC<br>sudo make install</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/0*D2GWooh9RgoKOnM5" /><figcaption>SSH build takes up to 30min.</figcaption></figure><h4>Building libcurl</h4><p>Download curl and unzip to tmmiot folder</p><pre>@raspberrypi:~/tmmiot/MindSphere/<br>wget <a href="https://curl.haxx.se/download/curl-7.52.1.zip"><strong>https</strong>://curl.haxx.se/download/curl-7.52.1.zip</a><br>unzip curl-7.52.1.zip -d tmmiotAgent</pre><p>Configure &amp; install</p><pre>@raspberrypi:~/tmmiot/MindSphere/tmmiotAgent/curl-7.52.1 $<br>LDFLAGS=”-Wl,-R/home/pi/tmmiot/MindSphere/tmmiotAgent/build/openssl/lib” ./configure — enable-http — with-ssl=/home/pi/tmmiot/MindSphere/tmmiotAgent/build/openssl — prefix=/home/pi/tmmiot/MindSphere/tmmiotAgent/build/curl — without-libssh2 — disable-ftp — disable-tftp — disable-file — disable-ldap — disable-rtsp — disable-dict — disable-telnet — disable-pop3 — disable-imap — disable-smb — disable-scp — disable-sftp — disable-smtp — disable-gopher — disable-manual</pre><pre>sudo make install</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/0*q5GyNSsc-iJw36Ey" /><figcaption>Building libcurl (takes up to 30min)</figcaption></figure><h4>Building MCLsudo</h4><p>Create a shell script build_mcl.sh</p><pre>#!/bin/bash<br> <strong>OPENSSL_DIR</strong>=”/home/pi/tmmiot/MindSphere/tmmiotAgent/build/openssl”<br> <strong>CURL_DIR</strong>=”/home/pi/tmmiot/MindSphere/tmmiotAgent/build/curl”<br> <strong>MCL_SOURCE_DIR</strong>=”/home/pi/tmmiot/MindSphere/tmmiotAgent/MCL_Core”<br> <strong>MCL_BUILD_DIR</strong>=”/home/pi/tmmiot/MindSphere/tmmiotAgent/build/mcl”<br> <strong>if</strong> [ -d ${MCL_BUILD_DIR} ]; then<br> sudo rm -rf ${MCL_BUILD_DIR}<br> fi<br> sudo mkdir ${MCL_BUILD_DIR}<br> sudo chmod 777 ${MCL_BUILD_DIR}<br> cd ${MCL_BUILD_DIR}<br> cmake <strong>-DCMAKE_PREFIX_PATH</strong>=”${OPENSSL_DIR};${CURL_DIR}” <strong>-DCMAKE_BUILD_TYPE</strong>=Release <strong>-DMCL_STATICLIB</strong>=OFF <strong>-DMCL_USE_LIBCURL</strong>=ON <strong>-DMCL_USE_OPENSSL</strong>=ON <strong>-DMCL_CREATE_DOXYGEN</strong>=OFF <strong>-DMCL_TESTING</strong>=OFF <strong>-DMCL_LOG_UTIL_LEVEL</strong>=MCL_LOG_UTIL_LEVEL_NONE ${MCL_SOURCE_DIR}<br> cmake — build . — target mc</pre><p>Create, copy above and change to an executable file</p><pre>@raspberrypi:~/tmmiot/MindSphere/<br>nano build_mcl.sh <br><strong>chmod</strong> +<strong>x</strong> <strong>build_mcl</strong>.sh</pre><p>Before we can execute we need to install CMAKE</p><pre>sudo apt-get update<br>sudo apt-get install cmake</pre><p>We have now following directory structure with all libs unzipped and installed to the build directory</p><pre>@raspberrypi:~/tmmiot/MindSphere/tmmiotAgent $ ls<br>build curl-7.52.1 MCL_Core openssl-1.0.2k</pre><p>Then we execute the build_mcl.sh</p><pre>@raspberrypi:~/tmmiot/MindSphere/<br>sudo ./build_mcl.sh</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/0*BtJQNpwn_SNwcYaq" /></figure><p>Build target mc — okay. Let’s check the dynamic dependencies:</p><pre>@raspberrypi:~/tmmiot/MindSphere $<br>ldd tmmiotAgent/build/mcl/build/Release/libmc.so</pre><pre>linux-vdso.so.1 (0x7efa6000)<br> /usr/<strong>lib</strong>/<strong>arm</strong>-<strong>linux</strong>-<strong>gnueabihf</strong>/<strong>libarmmem</strong>.<strong>so</strong> (0<strong>x76f35000</strong>)<br> libssl.so.1.0.0 =&gt; /home/pi/tmmiot/MindSphere/tmmiotAgent/build/openssl/<strong>lib</strong>/<strong>libssl</strong>.<strong>so</strong>.1.0.0 (0<strong>x76ed0000</strong>)<br> libcrypto.so.1.0.0 =&gt; /home/pi/tmmiot/MindSphere/tmmiotAgent/build/openssl/<strong>lib</strong>/<strong>libcrypto</strong>.<strong>so</strong>.1.0.0 (0<strong>x76d44000</strong>)<br> libcurl.so.4 =&gt; /home/pi/tmmiot/MindSphere/tmmiotAgent/build/curl/<strong>lib</strong>/<strong>libcurl</strong>.<strong>so</strong>.4 (0<strong>x76d01000</strong>)<br> libm.so.6 =&gt; /lib/arm-linux-gnueabihf/libm.so.6 (0x76c6d000)<br> libc.so.6 =&gt; /lib/arm-linux-gnueabihf/libc.so.6 (0x76b2e000)<br> libdl.so.2 =&gt; /lib/arm-linux-gnueabihf/libdl.so.2 (0x76b1b000)<br> libz.so.1 =&gt; /lib/arm-linux-gnueabihf/libz.so.1 (0x76af4000)<br> /<strong>lib</strong>/<strong>ld</strong>-<strong>linux</strong>-<strong>armhf</strong>.<strong>so</strong>.3 (0<strong>x76f78000</strong>)</pre><p>Shows us that all libssl, libcrypto and libcurl are referenced by our own builds.</p><h4>Building the custom agent</h4><p>We create our agent folder and Make file</p><pre>@raspberrypi:~/tmmiot/MindSphere/tmmiotAgent $ <br>mkdir agent<br>nano CMakeLists.txt</pre><p>We save following script for CMakeLists.txt</p><pre>CMAKE_MINIMUM_REQUIRED(VERSION 3.5 FATAL_ERROR)<br> PROJECT(TmmiotAgentAppplication LANGUAGES C)<br> SET(CMAKE_C_STANDARD 99)<br> SET(CMAKE_C_STANDARD_REQUIRED ON)<br> FILE(GLOB SOURCES *.c)<br> LIST(APPEND AGENT_SOURCES ${SOURCES})<br> SET(MCL “/home/pi/tmmiot/MindSphere/tmmiotAgent/build/mcl/build/Release/libmc.so” CACHE INTERNAL “MCL” FORCE)<br> SET(MCL_INCLUDE_DIRECTORIES “/home/pi/tmmiot/MindSphere/tmmiotAgent/build/mcl/include/” CACHE INTERNAL “MCL_INCLUDE_DIRECTORIES” FORCE)<br> SET(AGENT_OUTPUT_DIR ${CMAKE_BINARY_DIR}/build)<br> SET(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${AGENT_OUTPUT_DIR})<br> SET(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${AGENT_OUTPUT_DIR})<br> SET(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${AGENT_OUTPUT_DIR})<br> ADD_EXECUTABLE(${PROJECT_NAME} ${AGENT_SOURCES})<br> TARGET_INCLUDE_DIRECTORIES(${PROJECT_NAME} PUBLIC ${MCL_INCLUDE_DIRECTORIES})<br> TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${MCL})</pre><p>We need to copy the available mcl headers to our build directory</p><pre>@raspberrypi:~/tmmiot/MindSphere/tmmiotAgent/MCL_Core $ <br>cp -r include/ /home/pi/tmmiot/MindSphere/tmmiotAgent/build/mcl/</pre><p>There are example source code which we will adapt to onboard our pi and then send timeseries data. Copy the example files for the onboarding to the agent</p><pre>pi@raspberrypi:~/tmmiot/MindSphere/tmmiotAgent/agent $ ls<br>callbacks.c callbacks.h CMakeLists.txt onboard_dsc_upload.c</pre><p>Adapt the onboad_dsc_upload.c file with your initial access token and further tenant information.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3grc1az1Pu-aRvsw2B4dUA.png" /></figure><p>I have adapted the first code block from the example:</p><pre><strong>if</strong> (MCL_OK == code)<br> {<br> <strong>configuration</strong>-&gt;mindsphere_hostname = “https://southgate.eu1.mindsphere.io&quot;;<br> <strong>configuration</strong>-&gt;mindsphere_port = 443;<br> <strong>configuration</strong>-&gt;mindsphere_certificate = mindsphere_certificate;<br> <strong>configuration</strong>-&gt;security_profile = MCL_SECURITY_SHARED_SECRET;<br> <strong>configuration</strong>-&gt;proxy_hostname = NONE;//”http://192.168.0.1&quot;;<br> <strong>configuration</strong>-&gt;proxy_port = NONE;//3128;<br> <strong>configuration</strong>-&gt;proxy_type = MCL_PROXY_HTTP;<br> <strong>configuration</strong>-&gt;user_agent = “tmmiot agent v1.0”;<br> <strong>configuration</strong>-&gt;initial_access_token = initial_access_token;<br> <strong>configuration</strong>-&gt;tenant = “<strong>yourTenantName</strong>”;<br> <strong>configuration</strong>-&gt;load_function.shared_secret = (mcl_load_shared_secret_callback_t) custo$<br> <strong>configuration</strong>-&gt;save_function.shared_secret = (mcl_save_shared_secret_callback_t) custo$</pre><pre>// Initialize mcl communication with the configuration.<br> printf(“Initializing mcl communication : “);<br> code = mcl_communication_initialize(configuration, &amp;communication);<br> printf(“%s.\n”, mcl_log_util_convert_error_code_to_string(code));<br> }</pre><p>And commented everything after the onboarding (no configuration creation…) simple onboarding.</p><pre>/*<br>// <strong>If</strong> onboarding <strong>is</strong> successful, <strong>or</strong> the agent <strong>is</strong> already onboarded, initialize a store.<br>...<br>save_data_point_ids(data_point_id_1, data_point_id_2);<br>}<br>*/</pre><p>Executing and building the agent</p><pre>@raspberrypi:~/tmmiot/MindSphere/tmmiotAgent/build/agent $<br>cmake /home/pi/tmmiot/MindSphere/tmmiotAgent/agent/</pre><pre>cmake -build . -clean-first</pre><p>Executing via</p><pre>pi@raspberrypi:~/tmmiot/MindSphere/tmmiotAgent/build/agent $<br>./build/TmmiotAgentAppplication</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/0*SdCIyRHYrQU_74ZT" /></figure><p>The agent was onboarded successfully and the file registrationInformationFile.txt was created.</p><h4>Creating the agent mclib configuration and data mapping via GUI</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1023/1*laGgOPDKxu-iNBNJD79I4A.png" /><figcaption>Creating the mc lib configuration and adding all the variables from the “visualization asset”</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1023/1*YBq0hEOoCTKehuKCc2RrgA.png" /><figcaption>The mclib asset gets all the necessary data points and mappings to the “visualizing” asset</figcaption></figure><p>We have all the data points configured in order to later visualize the data we need to map the datapoints into our asset referencing the same data structure</p><h3>Configuring the data (timeseries) upload</h3><p>First we move our adapted onboard_dsc_upload.c to an archive. And then copy the timeseries example to our agent folder.</p><pre>@raspberrypi:~/tmmiot/MindSphere/tmmiotAgent/agent $<br>mkdir archive<br>mv onboard_dsc_upload.c archive/<br>cp ../MCL_Core/examples/timeseries_upload.c ../agent/</pre><p>Further we adapt the timeseries_upload.c file and adapt it with our configuration and data ids.</p><pre>char *configuration_id = “51830356–7180–4a0d-9f26–4681c623f89e”;</pre><p>We start with just entering two datapoint T and H. The executable will then add two data points to the timeseries. You need to change the code on this point to allow initial token transfer (the example has a bug here). My example<em> on github is changed already.</em></p><pre>// <strong>If</strong> exchange returns unauthorized, <strong>then</strong> get <strong>new</strong> <strong>access</strong> token.<br> <strong>if</strong> (MCL_UNAUTHORIZED == code || MCL_NO_ACCESS_TOKEN_EXISTS == code)<br> {</pre><p>Change the CMakeLists.txt file and rename the executable</p><pre>@raspberrypi:~/tmmiot/MindSphere/tmmiotAgent/build/agent $<br>cmake /home/pi/tmmiot/MindSphere/tmmiotAgent/agent/<br>cmake — build . — clean-first</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/0*TtUDbcViF-itLhTZ" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*aAMlDJc4v-Vo-6FQ1qfGWg.png" /></figure><p>The mclib asset gets all the necessary data points and mappings to the “visualizing”-Asset. All that is a bit too much drama for just a prototype. For our later product we would need to create a custom compiled agent for the hardware architecture. But for now we will proceed with the node.js library.</p><h3>Nodes.js MindConnect library onboarding and timeseries upload</h3><p>Compared to the C experience above this feels like a walk in the park. First the data mappings need to be set up like in in the above example with the c agent.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*JyRqFV4YlfG21D__lHNZJg.png" /><figcaption>Complete data configuration and mapping</figcaption></figure><h4>Installing the library</h4><p>As the node.js library just got released under the MIT licence to the public you can easily install it via npm package manager. Create a new folder for your agent.</p><pre>@raspberrypi:~/tmmiot/MindSphere/tmmiotAgentNodeJs/$<br>npm init -y<br>npm i <a href="http://twitter.com/mindconnect/mindconnect-nodejs">@mindconnect/mindconnect-nodejs</a> -save</pre><h4>Create the node.js agent</h4><p>I have created a script which sends every three minutes a new datapoint of our sensors.</p><pre>@raspberrypi:~/tmmiot/MindSphere/tmmiotAgentNodeJs/$<br>nano stream-pi-sensor-data.js</pre><p>copy to stream-pi-sensor-data.js</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/1c2e2c20b8735dec24b3c68fedad1873/href">https://medium.com/media/1c2e2c20b8735dec24b3c68fedad1873/href</a></iframe><h4>Creating your agentconfig.json</h4><p>As outlined earlier we need to store the boarding configuration. Which gets called via the above script. If the onboarding is successful a hidden subfolder get created .mc which stores the shared secret.</p><pre>@raspberrypi:~/tmmiot/MindSphere/tmmiotAgentNodeJs/<br>nano agentconfig.json</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*hxDPR9BL9bGV77_JSkaL5Q.png" /></figure><p>just copy your onboarding information into that file.</p><h4>Adding the hardware sensor libs</h4><p>We can integrate the libraries/packages for the hardware sensors now</p><pre>@raspberrypi:~/tmmiot/MindSphere/tmmiotAgentNodeJs/$ <br>npm install sds011-client -save<br>npm install rpi-dht-sensor -save</pre><p>Voilá — with root execution sudo node stream-sensor-pi-data.js this is much easier compared to the above C agent steps.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*-juOL8oiFZot49pD6P34IA.png" /><figcaption>Fleet manager visualization of the sensor data. Compared to Google DataStudio this is well optimized for realtime series representation</figcaption></figure><p>I like your comments, corrections and suggestions 👌.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b333ebfb872a" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Tell me more Internet of Things — Part 2 — Google Cloud IoT cost and value comparison]]></title>
            <link>https://medium.com/coinmonks/tell-me-more-internet-of-things-part-2-google-cloud-iot-cost-and-value-comparison-38bfb20d94e1?source=rss-14c8d196ddc0------2</link>
            <guid isPermaLink="false">https://medium.com/p/38bfb20d94e1</guid>
            <category><![CDATA[iot]]></category>
            <category><![CDATA[technology]]></category>
            <category><![CDATA[internet-of-things]]></category>
            <category><![CDATA[value-engineering]]></category>
            <category><![CDATA[google-cloud-platform]]></category>
            <dc:creator><![CDATA[Jan Bertrand]]></dc:creator>
            <pubDate>Thu, 10 Jan 2019 06:33:31 GMT</pubDate>
            <atom:updated>2019-09-22T07:23:17.564Z</atom:updated>
            <content:encoded><![CDATA[<h4>Google Cloud IoT — onboarding, data storage and visualization. How to connect your device to Google Cloud IoT and stream the ingested data to a database for storage, visualization and analyzation.</h4><p><a href="https://medium.com/@bertrand.jan/tell-me-more-internet-of-things-part-1-iot-platform-cost-and-value-comparison-558ce8966767">Part 1</a> <strong>| </strong><a href="https://medium.com/coinmonks/tell-me-more-internet-of-things-part-2-google-cloud-iot-cost-and-value-comparison-38bfb20d94e1"><strong>Part 2<em> </em></strong></a><em>| </em><a href="https://medium.com/@bertrand.jan/tell-me-more-internet-of-things-part-3-mindsphere-cost-and-value-comparison-b333ebfb872a">Part 3</a><em> | </em><a href="https://medium.com/@bertrand.jan/tell-me-more-internet-of-things-part-4-iota-cost-and-value-comparison-381008495d1d">Part 4</a><em>| </em><a href="https://medium.com/@bertrand.jan/tell-me-more-internet-of-things-part-5-google-cloud-user-handling-ae285e7e34b2">Part 5</a><strong> </strong><em>|</em><a href="https://medium.com/@bertrand.jan/tell-me-more-internet-of-things-part-6-google-cloud-user-input-push-subscription-aa39ebc4a348">Part 6</a> <em>| … | Part n</em></p><p>In <a href="https://medium.com/@bertrand.jan/tell-me-more-internet-of-things-part-1-iot-platform-cost-and-value-comparison-558ce8966767"><strong>Part 1</strong></a> of this series I explained how we intend to compare the IoT Platform based on a specific use-, business-case and its value proposition. We defined the scope and size of the project and finished with the hardware setup of the sensor.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/279/1*ak_n0OHvK8ZdSguNm6NL8g.png" /></figure><p>The goal of this part is to store sensor data continuously in a scalable database able to serve for visualization and data analysis. Within the Google cloud services there are multiple ways to implement this. I followed mainly these tutorials:</p><ul><li><a href="https://cloud.google.com/community/tutorials/cloud-iot-rtdp">Real time Data Processing With Cloud IoT Core</a></li><li><a href="https://medium.com/google-cloud/build-a-weather-station-using-google-cloud-iot-core-and-mongooseos-7a78b69822c5">Build a Weather Station using Google Cloud IoT Core and MongooseOS</a></li></ul><p>We start to implement a solution which is scalable and based on the standard services Goolge Cloud provides. Afterwards we replace Cloud Flow engine with Cloud Functions to increase the transparency of the underlying services and to compare a restricted scalable version (which could even run for free for only a few devices and for prototyping)</p><h4>Overview of implementation and results</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/907/1*CkU_VtJsNrQspiP6TWxQ9A.png" /><figcaption>Implemented (costs estimated) solution</figcaption></figure><p>The device is onboarded via a node.js MQTT (Message Queuing Telemetry Transport) agent. With RSA public / private key encryption — the IoT Core, as the device registry holds the public key of the device for encrypted communication <strong>M2</strong>. From there we use Pub/Sub to collect the data<strong> </strong>and pull it with Cloud Flow / Cloud Functions to our Database (Big Query). The visualization is implemented with the help of DataStudio <strong>M3</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/697/1*vAshu5uFQda6qk9yTbiwTg.png" /><figcaption>State of implementation (M0 — M3)</figcaption></figure><p>For the current implementation with no users and only devices ingesting data, the IoT Core costs are the highest followed by the computing costs of the cloud function. There is a minimum 1024 bytes cap on the ingested message. Which accounts for our higher net ingest (as our message is about 100 bytes with MQTT overhead a bit more). The cost per device increases with more devices and the prototype is for free <strong>K1</strong>. The service price includes maintaining and updating the infrastructure as well as keeping them secure <strong>K2</strong>.</p><p>On the soft side the device agents onboarding via MQTT node.js libraries is relatively easy and various starter tutorials exists <strong>K3</strong>. The device management (IoT Core) is well explained. There is enough documentation available but for just visualization of data its quite complex composition of services. <strong>The possibility of entering a cloud shell directly from the browser and the available step by step tutorials for the different service are great K4. </strong>All implemented Milestones (<strong>M1-M3</strong>) are provided out of the box with various different possible services including the visualization via DataStudio <strong>K5. </strong>In addition to all that greatness (you know by now already that I am close to fan boy status) the sheer endless possibilities to define where your data should be stored or processed makes the platform fit for IP (Intellectual Property), ECC (Export Control Classification) and possible other liabilities. On the other side of the shining medal this free choice increases the complexity of the implementation.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/734/1*Lppbg65R4hh-n3-Qwv459A.png" /><figcaption>Google Cloud estimated costs running with Cloud Function.</figcaption></figure><p>I have created a <a href="https://tell-me-more-iot.appspot.com/">configurator</a> for this implementation which you can use to explore how I derived the costs for the different services. Inputs are</p><ul><li><strong>amount of devices </strong><em>(our case: 1; 100; 1000; 10.000)</em></li><li><strong>message size</strong> <em>(our case: 100 Bytes)</em></li><li><strong>message frequency </strong><em>(our case: 20 message per device per minute)</em></li></ul><p><a href="https://tell-me-more-iot.appspot.com/books/5634472569470976">Google Cloud IoT Configurator - Node.js on Google Cloud Platform</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*c_jVhwAQYcC5vbP41j8oAg.png" /><figcaption>Screen of my cost configuration app (naturally running on Google Cloud App engine)</figcaption></figure><p>There is of course as well the official more complex cost estimator — with many more functions and services. <a href="https://cloud.google.com/pricing/">https://cloud.google.com/pricing/</a></p><p>In this Part 2 implementation (M0-M3) is<strong> not</strong> included yet: <strong>User Management — </strong>individual visualization and event suggestions. <strong>Efficient data storage</strong> for fast querying for the user. <strong>Automated data analytics </strong>for the user.</p><h3>Highly scalable implementation</h3><p>The solution is based on onboarding the device to</p><ol><li><strong>IoT Core</strong>. Here the device gets registered via a public/private key (asymmetric encryption) provided by the device owner. <em>We only send data from the device to Google Cloud IoT Core. The device manager can do more — like updating the devices configuration (incl. rollbacks etc.)</em></li><li>The device runs a node.js program which sends the sensor data to the registry via <strong>MQTT</strong> (Message Queuing Telemetry Transport) protocol.</li><li>From there we create a subscription in <strong>Pub/Sub</strong> to this registry.</li><li><strong>Data flow</strong> is used to fetch the data from this subscription and pushes it for permanent storage to the Database BigQuery.</li><li><strong>BigQuery</strong> holds the schema for storage and is queryable by API or with Data Studio</li><li><strong>Data Studio</strong> for visualizing, reporting and manual analytics.</li></ol><p>You ask yourself maybe why do I need so many services to just visualize and query data? We are in the same boat here — lets find out together.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/610/1*LaCW43vHs1cVU2MwRChykw.png" /><figcaption><em>Overview of Google cloud services used in this article for the project</em></figcaption></figure><p>This implementation does still not provide</p><ol><li>User Management — individual visualization and event suggestions.</li><li>Efficient data storage for fast querying for the user.</li><li>Automated data analytics for the user.</li></ol><p>If you like to try it out yourself please get yourself a free-tier Google Cloud offer. There is a free trial with ~200$ of free usage for 1 year. In addition there are certain always free limits too.</p><p>In Google Cloud we can separate different projects by project-ids. They have their own resources, billing and analyzation. We define a new Google cloud project. My project name (project id) is tell-me-more-iot. It is a unique global identifier and you need to choose one yourself.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/900/0*a5LRaJ8YXpdFbVIx" /><figcaption><em>Creating a new project in Google Cloud (project id: tell-me-more-iot)</em></figcaption></figure><p>Maybe here a little overview map for the new ones (it’s quite a bit of functionality in this GUI)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/662/1*k2uTKHE5nb3ILSo8GPbJxw.png" /><figcaption><em>Some overview for the complex, extensive dashboard of google cloud</em></figcaption></figure><h3>Google IoT Core and Pub/Sub</h3><p>There is a good quick start <a href="https://cloud.google.com/iot/docs/quickstart">tutorial </a>available for basic onboarding (or even virtual onboarding of compute instances — if you don’t have a pi or a running linux laptop on hand)</p><p>We introduce both possibilities to create our registry and devices by GUI (Graphical User Interface) and via the command line. For this I show both ways later you can decide how to progress yourself</p><h4>With the GUI</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*sYrpFW827axt7UUu6Z4zqQ.png" /><figcaption>Creating a IoT Core Registry (and with that a topic for the Pub/Sub)</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*qknu2OGDjylYhH5u16oQ9g.png" /><figcaption><em>Creating the topic for the Pub/Sub during IoT Core registry creation</em></figcaption></figure><p>We chose following names:</p><blockquote>PROJECT_ID=”tell-me-more-iot”<br>TOPIC_ID=”tmmiot-topic-1&quot;<br>TOPIC_PATH=”projects/tell-me-more-iot/topics/”<br>REGISTRY_ID=”tmmiot-registry-1&quot;<br>REGION=”europe-west1&quot;</blockquote><h4>With the command line via Cloud Shell</h4><p>The cloud shell (terminal) is an ephemeral linux debian instance with pre configured software. You can define your own docker profile (the image which should be deployed once cloud shell opens) with your necessary software. But it comes already with git, node.js and of course gcloud — the CLI (Command Line Input) for the entire service portfolio of Google Cloud.</p><p>Execution of the gcloud command leads to</p><pre>@cloudshell:~ (tell-me-more-iot)$ <br><strong>gcloud iot registries create</strong></pre><pre><strong>ERROR</strong>: (gcloud.iot.registries.create) argument (<strong>REGISTRY </strong>: — region=REGION): Must be specified.<br>For detailed information on this command and its flags, <strong>run</strong>:<br> gcloud iot registries create — help</pre><p>We could consult further the help or you just execute the following script with</p><pre>@cloudshell:~ (tell-me-more-iot)$ <br><strong>mkdir scripts<br>touch createIoT-1.sh<br>chmod +x createIoT-1.sh<br>nano createIoT-1.sh</strong></pre><p>copy and paste the following code ( mkdir creates a new folder scripts, touch creates a new file with the name createIoT-1.sh (our shell script). chmod +x give the file the rights to get executed. nano is a command-line editor / alternatively you could use the web-based cloud editor from Google.)</p><pre>#!/bin/bash<br>PROJECT_ID=”tell-me-more-iot”<br>TOPIC_ID=”tmmiot-topic-1&quot;<br>TOPIC_PATH=”projects/tell-me-more-iot/topics/”<br>REGISTRY_ID=”tmmiot-registry-1&quot;<br>REGION=”europe-west1&quot;<br>gcloud config set project $PROJECT_ID<br>gcloud pubsub topics create $TOPIC_ID<br>gcloud iot registries create $REGISTRY_ID \<br> — region=$REGION \<br> — no-enable-http-config \<br> — enable-mqtt-config \<br> — event-notification-config=topic=$TOPIC_ID</pre><p>Then execute the shell script with</p><pre>@cloudshell:~ (tell-me-more-iot)$ <br><strong>./createIoT-1.sh</strong></pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/900/0*jfwBC71R373_jqwh" /><figcaption><em>Creating the registry and sub/pub topic via CLI</em></figcaption></figure><p>Not so much happening at the moment as we have not send anything to the registry neither did we define a device (the representation in the registry of our <strong><em>pi</em></strong>)</p><p>Let start preparing sending the sensor data to the registry.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/607/1*t1wRIPJy4LGT1hnIECDbqw.png" /><figcaption><em>Status of the implementation</em></figcaption></figure><h3>Prepare the device for sending data to the cloud registry device</h3><blockquote>Back to the pi.</blockquote><p>We create a folder for our MQTT client software</p><pre>@raspberry: ~ $ <br><strong>mkdir tmmiot &amp;&amp; cd tmmiot</strong></pre><p>Pull the dedicated client node.js script (based on this <a href="https://github.com/GoogleCloudPlatform/nodejs-docs-samples">extensive example repositories</a>)</p><pre>@raspberry: ~/tmmiot/ $ <br><strong>git clone </strong><a href="https://github.com/jhab82/tellMeMoreIoT-MQTTclient"><strong>https://github.com/jhab82/tellMeMoreIoT-MQTTclient</strong></a></pre><p>Once that is downloaded we need to install and potentially replace the USB port name ttyUSB0 of your sensor in the script (see <strong>Part 1</strong>)</p><pre>@raspberry: ~/tmmiot/tellMeMoreIoT-MQTTclient/ $ <br><strong>npm install</strong></pre><p>The program would run but would crash with asking for a private key file which we need to create.</p><ul><li>The <strong>private key</strong> — which decrypts messages (created and owned by our device)</li><li>The <strong>public key</strong> — which is able to encrypts the message (created by our device and is shared with our IoT Core registry device)</li></ul><p>According to this <a href="https://cloud.google.com/iot/docs/how-tos/credentials/keys">tutorial</a> our device needs to sign a JSON Web Token (JWT) which is send to the IoT core for <strong>proof of identity. </strong>Further we use the X.509 certificate which expires by default after 30 days — you could add -days 100000 to have some more time for device registration.</p><pre>@raspberry: ~/tmmiot/tellMeMoreIoT-MQTTclient/ $ <br><strong>openssl req -x509 -newkey rsa:2048 -keyout rsa_private.pem -nodes -out rsa_cert.pem -subj &quot;/CN=unused&quot;</strong></pre><p>Two files have been created. The rsa_private.pem stays where it is and will not be shared with anyone or anything. The rsa_cert.pem we should copy now over to our registry.</p><h4>Onboarding the device via GUI</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*UVkyD7UdcditX7WAk5UmWg.png" /><figcaption><em>Adding the device and to the IoT registry and handing over the public key (this public key was generated on our pi — only for visual aid I have created here with the consol)</em></figcaption></figure><p>We navigate to our tmmiot-registy-1 and click create and fill in the necessary information, including pasting our <strong>RS256_X509</strong> certificate into the public key value field (d<em>on’t forget to add the device). </em>We are ready to communicate securely with the cloud now.</p><h4>Sending data to the cloud registries dedicated device</h4><blockquote>Back to the pi</blockquote><p>It’s time to bring the sensor data to the cloud. Before you are able to start the agent (or client onboarding and sending of data) you need to change some variables to fit your project in the mqtt-agent.js .</p><pre>var argv = { projectId: “<strong>tell-me-more-iot</strong>”,<br> cloudRegion: “<strong>europe-west1</strong>”,<br> registryId: “<strong>tmmiot-registry</strong>”,<br> deviceId: “<strong>tmmiot-device-1</strong>”,<br> privateKeyFile: “rsa_private.pem”,<br> tokenExpMins: 20,<br> numMessages: 10,<br> algorithm: “RS256”,<br> mqttBridgePort: 443,<br> mqttBridgeHostname: “mqtt.googleapis.com”,<br> messageType: “events”,<br> };</pre><p>I have adapted the node.js MQTT client example provided by <a href="https://github.com/GoogleCloudPlatform/nodejs-docs-samples/tree/master/iot/mqtt_example">Google</a>. The client runs every 3 min. and queries the sensor which then runs for 2–3 s and produces a measurement point which gets send with JSON formatted string to the Google cloud registry. Every 20 min. the JSON web token gets renewed. The data we send is JSON formated as following:</p><pre>{“id”:”tmmiot-device-1&quot;,”time”:1544729995403,”date”:”2018–12–13T19:39:55.403Z”,”pm2p5&quot;:5,”pm10&quot;:6.8}</pre><p>Running the client with:</p><pre>@raspberry: ~/tmmiot/tellMeMoreIoT-MQTTclient/ $ <br><strong>node mqtt-agent.js</strong></pre><p>Or use the nohup command to run the program in the background (even if you close the terminal)</p><pre>@raspberry: ~/tmmiot/tellMeMoreIoT-MQTTclient/ $ <br><strong>nohup node mqtt-agent.js &gt; out.log 2&gt;&amp;1 &amp;</strong></pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/0*5pn5y52IOwtUQrF0" /><figcaption>IoT Core registry and first heartbeat and data received from the device</figcaption></figure><h4>Creating a subscription to a topic</h4><p>We need to subscribe to the Pub/Sub topic in order receive or handle the data.</p><pre>@cloudshell:~ (tell-me-more-iot)$<br><strong>gcloud pubsub subscriptions create tmmiot-subscription <br>-topic=tmmiot-topic-1</strong></pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*cUUfgiQ_TpPZVfiG5d7RLw.png" /><figcaption>Pulled sensor data by command line on Cloud Shell</figcaption></figure><p>The subscription will deliver the message when requested (pull) from the topic and retain the message for 7 days (this duration can be limited or extended). Once the message is received and gets acknowledged its not any longer in the topic/registry.</p><p>As we have send already some sensor data to the topic and have the subscription we can pull (request the data) — the pull will not deliver the message in any defined order. The following code just pulls one message and acknowledge it.</p><pre>@cloudshell:~ (tell-me-more-iot)$ <br><strong>gcloud pubsub subscriptions pull -auto-ack tmmiot-subscription</strong></pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/530/1*RubvfjUZQJ5_YULPIWifLQ.png" /><figcaption><em>Status of the implementation</em></figcaption></figure><p>The <strong><em>pi</em></strong> runs overnight and we can see the monitoring of the devices in the registry</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/0*_dUKyatcsRgotmwt" /><figcaption><em>Monitoring of the device registry in Google IoT — Bytes received peaks at 640B every 20min (JSON web token renewal) and around 128B for the message every 3 min.</em></figcaption></figure><h3>Streaming the subscription data to BigQuery</h3><p>There is a quite easy possibility to stream the data from the pub/sub subscription to a BigQuery database.</p><p>The Google Cloud Flow function runs a template Java application which streams all JSON formatted String data into a predefined BigQuery database with the equivalent schema. The data we send would require a database as shown below</p><pre>{“id”:”tmmiot-device-1&quot;,”time”:1544729995403,”date”:”2018–12–13T19:39:55.403Z”,”pm2p5&quot;:5,”pm10&quot;:6.8}</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/614/1*o4leb_nY8TA8Gd2GKiUHfQ.png" /><figcaption>Database schema represented by a simple table</figcaption></figure><h4>Creating a BigQuery database</h4><p>Let’s use the command line for creating the database and adding our schema. First we need to define a JSON formatted file tmmiot_table_schema.json and store it in our cloudshell.</p><pre>[<br> {<br> “description”: “device-id”,<br> “name”: “id”,<br> “type”: “STRING”,<br> “mode”: “NULLABLE”<br> },<br> {<br> “description”: “Measurement time”,<br> “name”: “time”,<br> “type”: “STRING”,<br> “mode”: “NULLABLE”<br> },<br> {<br> “description”: “Measurement date”,<br> “name”: “date”,<br> “type”: “STRING”,<br> “mode”: “NULLABLE”<br> },<br> {<br> “description”: “Sensor 1”,<br> “name”: “pm2p5”,<br> “type”: “STRING”,<br> “mode”: “NULLABLE”<br> },<br> {<br> “description”: “Sensor 2”,<br> “name”: “pm10”,<br> “type”: “STRING”,<br> “mode”: “NULLABLE”<br> }<br>]</pre><p>Create the dataset tmmiot_dataset</p><pre>@cloudshell:~ <br><strong>bq mk — dataset tell-me-more-iot:tmmiot_dataset</strong></pre><p>Then we add a table tmmiot_table to the dataset with the JSON formatted schema</p><blockquote>bq mk — table [PROJECT_ID]:[DATASET].[TABLE] [PATH_TO_SCHEMA_FILE]</blockquote><pre>@cloudshell:~ <br><strong>bq mk -table tell-me-more-iot:tmmiot_dataset.tmmiot_table tmmiot_table_schema.json</strong></pre><p><em>Hint: In contrast to the prior CLI we wont use </em><strong><em>gcloud</em></strong><em> as the command but </em><strong><em>bq</em></strong><em>.</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/0*c1nWirp190gdo-VP" /><figcaption><em>BigQuery dataset with table and schema</em></figcaption></figure><h4>Creating a cloud flow stream to BigQuery</h4><blockquote><strong>Please delete the Dataflow job after your tests as this service is designed for high performance and will cost you money over time</strong></blockquote><p>Still our sensor data is not getting logged for good. The subscription only holds 7 days the telemetry event data. We would like to permanently store the data and the most easiest and highly scalable solution — we use a <a href="https://cloud.google.com/dataflow/docs/guides/templates/provided-templates#cloudpubsubtobigquery">template from Google Cloud Flow</a>.</p><p>In order to use cloud flow we need to first define a data bucket for storing temporary files.</p><p><em>Hint: Here we use</em><strong><em> </em></strong><strong><em>gsutil </em></strong><em>to create and access the storage function of google cloud which is organized in buckets. You can certainly just use the GUI again.</em></p><blockquote>gsutil mb -p [PROJECT_NAME] -c [STORAGE_CLASS] -l [BUCKET_LOCATION] gs://[BUCKET_NAME]/</blockquote><pre>@cloudshell:~ <br><strong>gsutil mb -p tell-me-more-iot gs://tmmiot_bucket_1</strong></pre><p>To create a subfolder we need to copy cp a file to the subdir.</p><pre>@cloudshell:~ <br><strong>touch tmp_test<br>gsutil cp tmp_test gs://tmmiot_bucket_1/tmp/</strong></pre><p>This is all possible as well with the GUI of course</p><p><em>Hint: we have created storage without taken care of the storage location yet. If you would need your data in a specific place — you need to specify that</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/0*RG5bVzI-TDwfUikK" /><figcaption>Further we open the Dataflow GUI and create a new job</figcaption></figure><p>Further we open the Dataflow GUI and create a new job. Job name tmmiot-dataflow and Cloud Dataflow template: <strong>Cloud Pub/Sub to BigQuery</strong></p><blockquote>Job name: <strong>tmmiot-dataflow<br></strong>Cloud Dataflow template: <strong>Cloud Pub/Sub to BigQuery<br></strong>Regional endpoint: <strong>europe-west1<br></strong>Cloud Pub/Sub input topic: <strong>projects/tell-me-more-iot/topics/tmmiot-topic-1<br></strong>BigQuery output table: <strong>tell-me-more-iot:tmmiot_dataset.tmmiot_table<br></strong>Temporary Location: <strong>gs://tmmiot_bucket_1/tmp<br></strong>Max workers<strong>: 1</strong></blockquote><blockquote>Hint: n1-standard-1 is the smallest machine able to use for this template (we tried f1-micro and the next but following error arises). If you don’t hand over max workers and machine-type by default there will be 4 workers and n1-standard-4 (with 4 vCPUs and 15GB RAM).</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/755/0*yjqRFHU8OtA0EH9o" /><figcaption><em>Error when trying to use a f1-micro compute engine as the data flow engine</em></figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*fzyTXjYwjho1a02D12qrRA.png" /><figcaption><em>Creation of the dataflow job and view of the compute instance where the job is running</em></figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/0*dWFBl_Tnjsa6sRNk" /><figcaption><em>Dataflow overview with resource metrics</em></figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/0*orrrRjwI8oqYk-3S" /><figcaption><em>Querying the database after 9 min data flow running</em></figcaption></figure><blockquote>Hint: A Dataflow job can only be stopped but not be entirely deleted. The job will be shown in the overview. If you made a typo for the bucket name for example the job failed and will stay in the overview.As I had ingested data to the topic (Pub/Sub) overnight I would have assumed to get a all the unacknowledged messages pushed into the database.But after waiting 9 min we only see three entries — meaning the streaming service only accounts for new messages.</blockquote><p>The JAVA templates<a href="https://github.com/GoogleCloudPlatform/DataflowTemplates/blob/master/src/main/java/com/google/cloud/teleport/templates/PubSubToBigQuery.java"> source code states</a></p><pre>/** * The {@link PubSubToBigQuery} pipeline is a streaming pipeline which ingests data in JSON format * from Cloud Pub/Sub, executes a UDF, and outputs the resulting records to BigQuery. Any errors * which occur in the transformation of the data or execution of the UDF will be output to a * separate errors table in BigQuery. The errors table will be created if it does not exist prior to * execution. Both output and error tables are specified by the user as template parameters.</pre><blockquote>Hint: This flow engine is heavily oversized for our one lonely sensor — but once you get more traffic you know where to look for 😄</blockquote><h3>Visualizing data with Data Studio</h3><p>That is the final step to reach our stories goal. But before we go to Part 3 we will replace the Dataflow service in order to create a less scalable version of the same functionality for better transparency — and to save some euros.</p><p>Let’s try to visualize the time series for PM10 and PM2.5 from our sensor (as we have only one device we do it only for this).</p><ul><li>Navigate to <a href="http://datastudio.google.com/">datastudio.google.com</a> and create a new report.</li><li>Connect your BigQuery to this report</li><li>Configure the date to read in as text</li><li>Create New Field which converts the date string into YYYYMMDDHH format</li></ul><pre><strong>TODATE</strong>(date, ‘RFC_3339’, ‘%Y%m%d%H’)</pre><ul><li>Configure the sensor data as average (or max or min)</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/957/1*inAM-osP64K6LW4I1MqVmQ.png" /><figcaption><em>Create a new report with Data Studio connected to BigQuery</em></figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/0*c7cHKGtAYNvzFoMv" /><figcaption><em>Visualization of sensor data in Google Cloud Studio</em></figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/612/1*-xX4mFv3NzPo2IFPfJ-Vrw.png" /><figcaption>Overview of implementation</figcaption></figure><h4>Billing</h4><p>After leaving this running for ~26h billing shows me ~2,50€ consumption. All connected to the Cloud Dataflow engine.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/979/1*H1R_KwNqgVppczVhvSlVnA.png" /><figcaption>Screen from the billing for tell-me-more-iot project</figcaption></figure><h3>Replace Dataflow with Cloud Function</h3><p>Lets quickly replace the Dataflow job (designed to handle huge amount of telemetry events) and exchange it with the less scalable but quickly deployed solution. Its cloud function.</p><p>The cloud function just runs with a predefined allocated memory on the app or compute engine account.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*C3BCp0fRM0RW2Ne7n0IUOA.png" /><figcaption>Cloud Function setup</figcaption></figure><blockquote><strong>index.js</strong></blockquote><pre>/**<br> * Triggered from a message on a Cloud Pub/Sub topic.<br> *<br> * @param {!Object} event Event payload and metadata.<br> * @param {!Function} callback Callback function to signal completion.<br> */<br>exports.pubsubToBQ = (event, callback) =&gt; {<br> <strong>const</strong> pubsubMessage = event.data;</pre><pre><strong>const</strong> BigQuery = require(‘@google-cloud/bigquery’);<br> <strong>const</strong> bigquery = <strong>new</strong> BigQuery();</pre><pre>bigquery<br>    .dataset(&quot;tmmiot_dataset&quot;)<br>    .table  (&quot;tmmiot_table&quot;)<br>    .insert (JSON.parse(Buffer.from(pubsubMessage.data, &#39;base64&#39;).toString()), {&#39;ignoreUnknownValues&#39;:true, &#39;raw&#39;:false})<br>    .then   ((data) =&gt; {<br>      console.log(`Inserted 1 rows`);<br>      console.log(data);<br>    })<br>    .catch(err =&gt; {<br>      <strong>if</strong> (err &amp;&amp; err.name === &#39;PartialFailureError&#39;) {<br>        <strong>if</strong> (err.errors &amp;&amp; err.errors.length &gt; 0) {<br>          console.log(&#39;Insert errors:&#39;);<br>          err.errors.forEach(err =&gt; console.error(err));<br>        }<br>      } <strong>else</strong> {<br>        console.error(&#39;ERROR:&#39;, err);<br>      }<br>    });<br><br><br>  callback();<br>};</pre><blockquote><strong>packages.json</strong></blockquote><pre>{<br> “name”: “pubsubToBigQuery”,<br> “version”: “0.0.1”,<br> “dependencies”: {<br> “@google-cloud/bigquery”: “^.3.0”<br> }<br>}</pre><blockquote>Hint: If you try it yourself please change the names for dataset and table</blockquote><p>We replaced the Cloudflow (Big Data) with a smaller solution Cloud Functions.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/605/1*omY7P6Bm1YuYb9Zon8yh7A.png" /><figcaption>Overview of implementation</figcaption></figure><h4>Billing</h4><p>After ~24h there is no billable cost from Cloud Function. There are only 9 Invocations registered but the function reliable executed every 3 minutes. That is most probable due to how Cloud Functions is counting Invocations.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/969/1*8Fy57nI7njLxczx6HJ8ozg.png" /><figcaption>Filtered billable services for Cloud Function after leaving it 24h running</figcaption></figure><p>I like your comments, corrections and suggestions 👌.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=38bfb20d94e1" width="1" height="1" alt=""><hr><p><a href="https://medium.com/coinmonks/tell-me-more-internet-of-things-part-2-google-cloud-iot-cost-and-value-comparison-38bfb20d94e1">Tell me more Internet of Things — Part 2 — Google Cloud IoT cost and value comparison</a> was originally published in <a href="https://medium.com/coinmonks">Coinmonks</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Tell me more Internet of Things — Part 1 —  IoT platform cost and value comparison]]></title>
            <link>https://medium.com/coinmonks/tell-me-more-internet-of-things-part-1-iot-platform-cost-and-value-comparison-558ce8966767?source=rss-14c8d196ddc0------2</link>
            <guid isPermaLink="false">https://medium.com/p/558ce8966767</guid>
            <category><![CDATA[internet-of-things]]></category>
            <category><![CDATA[healthcare]]></category>
            <category><![CDATA[iota]]></category>
            <category><![CDATA[raspberry-pi]]></category>
            <category><![CDATA[blockchain]]></category>
            <dc:creator><![CDATA[Jan Bertrand]]></dc:creator>
            <pubDate>Fri, 28 Dec 2018 15:17:41 GMT</pubDate>
            <atom:updated>2020-08-27T11:45:43.395Z</atom:updated>
            <content:encoded><![CDATA[<h3>Tell me more Internet of Things — Part 1 — IoT platform cost and value comparison</h3><h4>Comparison of selected IoT (Internet of Things) AEP (Application Enablement Platform) by implementing step by step a specific use-case and adding a possible DLT (Distributed Ledger Technology) implementation to that comparison.</h4><p><a href="https://medium.com/@bertrand.jan/tell-me-more-internet-of-things-part-1-iot-platform-cost-and-value-comparison-558ce8966767"><strong>Part 1</strong></a><strong> | </strong><a href="https://medium.com/coinmonks/tell-me-more-internet-of-things-part-2-google-cloud-iot-cost-and-value-comparison-38bfb20d94e1">Part 2<strong><em> </em></strong></a><em>| </em><a href="https://medium.com/@bertrand.jan/tell-me-more-internet-of-things-part-3-mindsphere-cost-and-value-comparison-b333ebfb872a">Part 3</a><em> | </em><a href="https://medium.com/@bertrand.jan/tell-me-more-internet-of-things-part-4-iota-cost-and-value-comparison-381008495d1d">Part 4</a><em>| </em><a href="https://medium.com/@bertrand.jan/tell-me-more-internet-of-things-part-5-google-cloud-user-handling-ae285e7e34b2">Part 5</a><strong> </strong><em>|</em><a href="https://medium.com/@bertrand.jan/tell-me-more-internet-of-things-part-6-google-cloud-user-input-push-subscription-aa39ebc4a348">Part 6</a> <em>| … | Part n</em></p><p>This article (Part 1) explains the project goals. I am introducing the use/business case and how I intend to compare the cloud implementations. At the end we will set up the hardware of the use-case and deploy a simple program which prints the sensors data to the command line.</p><blockquote>This is my personal project (multiple parts) which could stretch along month.</blockquote><h3>Motivation and targets</h3><p>According to <a href="https://blogs.gartner.com/smarterwithgartner/files/2018/08/PR_490866_5_Trends_in_the_Emerging_Tech_Hype_Cycle_2018_Hype_Cycle.png">Gartner Hype Cycle</a> the Term<strong> IoT Platform</strong> is just about on its decline from its hypest and highest rise.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/824/1*7KXIvmxn_q4j3eA4Zy7zkQ.png" /><figcaption>Adapted Gartner Hype cycle with IoT Platform and Blockchain as of July 2018. Yin Yang symbol (describes how seemingly opposite or contrary forces may actually be complementary)</figcaption></figure><p>Even though Gartner is not necessarily right about every detail in technology it is certainly true that there is loads of positive business outlook from the very same research team states several trillion industry in just a few years (yes trillion 1,000,000,000,000 🐵)</p><p>True is as well that many companies have already opened their devices/businesses to the internet. And some made the collected data analyzation and data visualization centrally to their value proposition.</p><p>Whereas companies like Siemens focus in some parts more on the industrial business with their own platform MindSphere, which states to be the Operating System (OS) for the Industrial Internet of Things (IIoT). Others like Google (Google Cloud) or Amazon (AWS) added specially IoT to their vast cloud functionalities in order to advertise this market better.</p><p>All of these platforms have in common that they are offered as services. Whereas Siemens MindSphere is a Platform as a Service (PaaS) — Google and Amazon bring the Infrastructure as a Service (IaaS) included in their offerings. Meaning Siemens won’t have their own Servers (Data Centers ~ Clouds) but need to partner up with Microsoft, Amazon or Google.</p><p>The maverick approach for IoT combines two of the most hyped topics — IoT and Blockchain (better DLT <strong>D</strong>istributed <strong>L</strong>edger <strong>T</strong>echnology) and with that it would be on the highest hype on that very same curve. IOTA stands for (“A permissionless distributed ledger for a new economy”) — it’s not really the abbreviation I was expecting but it makes sense 😎. We have to be fair here, IOTA is not a platform but rather a protocol.</p><p>So adding IOTAs distributed and decentralized approach to the comparison is risky but I think worth it and opens up to a lot of questions and discussion while comparing to centrally managed platforms.</p><p>Currently IOTA transactions (messages) are secured by distributed Node software running on personal servers or cloud instances (VPS). So it is neither a IaaS nor a PaaS — it enables with providing node software, the protocol as well as a wide community to promote their vision of IoT.</p><p>All IoT solutions have in common beside other things like security, data handling and automation to solve scaling.</p><h3>But why do we need all that scaling?</h3><p>The control theory and system identification Professor emphasized us to always apply the most simple and easiest approach before going nuts (meaning just try linearly identify a system before training nonlinear neural networks). Translated to our use-case here that would be starting not necessarily with the BigData approach 😅. The use case (product) we will develop is at the time of writing just one device and we could implement it very easy non scale-able way. Knowing that without the other ~9.999 devices we won’t have any way of doing big data diagnostics which is the real value contribution for the business case.</p><p>In order to understand the IoT platforms benefits but as well its drawbacks we define a business case for our product (use-case) to understand how the value proposition develops with those increased functionalities.</p><ul><li><strong>Use-case</strong>: The product we connect to the IoT “platform”.</li><li><strong>Business case</strong>: How to make money with this product/service connected to the cloud?</li><li><strong>Value proposition</strong>: What is in for the customer?</li></ul><h3>The reference architecture</h3><p>To structure our approaches and use the same wording we follow the reference architecture for IoT systems introduced by the <a href="http://www.iaas.uni-stuttgart.de/RUS-data/INPROC-2016-48%20-%20Comparison%20of%20IoT%20Platform%20Architectures.pdf">Institute of Architecture of Application Systems.</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/329/1*lKiNAWp4IzoBYZU3RwzdVA.png" /><figcaption>IoT reference architecture</figcaption></figure><p>Every platform has its own terms which can be mapped on this simple overview.</p><h3>The use-case</h3><p>Everyone needs a portable environmental sensing device which tells you at home, work or while commuting which air you are breathing and other influencing health condition you are exposed to.</p><h4>The prototype</h4><ul><li><strong>Sensors </strong>(Particulate Matter — SDS011 PM2.5 and PM10, Humidity and Temperature)</li><li><strong>Device</strong>: Raspberry Pi 3b+</li><li><strong>Drivers</strong>: USB connected (digital), GPIO connected (analog)</li><li><strong>Gateway</strong>: Raspberry Pi 3b+ — WiFi module</li><li><strong>IoT Integration Middleware</strong>: IoT Platform (Google IoT, AWS IoT MindSphere, “IOTA” not a Middleware but a protocol and distributed network)</li><li><strong>Application: Visualization</strong>: metrics, time-series.. , <strong>notification:</strong> notify when conditions are not healthy, <strong>automation:</strong> support APIs for controlling {e.g. heating, air …}, <strong>manual event input</strong>: user can or should log when sick or other metrics, <strong>analytics:</strong> diagnostics based on big data nonlinear system identification 👍</li></ul><h4>Use case assumptions</h4><ul><li><strong>Message-size</strong>: 20 words (columns where every word is about 5 chars)</li></ul><blockquote>20 words * 5 chars/words = 100 chars ~ 100 Bytes ~ 0,0001 MB</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/575/1*6LdF-OSSN7tcHKPo4TUVng.png" /><figcaption>Table representation of the telemetry message (device — message)</figcaption></figure><ul><li><strong>Message-frequency</strong>: 20 messages/hour</li></ul><p>That would lead to data ingest of roughly 18 MB / year per device</p><blockquote>20*24*100*365 = 17,52 MB / year per device</blockquote><p>As our product get super popular we would account</p><blockquote>1.000 Devices ~17,52 GB / year</blockquote><blockquote>10.000 Devices ~175,2 GB / year.</blockquote><p>If we don’t throw away that data (certainly not) let’s say we gain roughly <strong>300 GB</strong> of data in 3 years (10.000 Device ramp up)</p><h4>Business case assumptions</h4><p>Only for the sake of staying easy (we want to compare the platforms but not the business case) we only provide the visualization and analyzation.</p><p>The device itself can be assembled by open sourced instruction or could be bought by a third parties.</p><ul><li>Free to use application (only visualization and alarms) [0 EUR]</li><li>Licensed version which gives you health recommendation based on the data analytics (of all users devices and their personal inputs). [20 EUR / year]</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/631/1*zS91Yj2gHKaziufYkty1Ug.png" /><figcaption><em>Draft of profit accumulation for our business plan (needs updating for the IoT AEP costs)</em></figcaption></figure><h4>Value proposition assumptions</h4><blockquote>We really don’t know what we are breathing during a course of the day. Certainly we don’t know individually how it affects our own health.</blockquote><p>The value</p><ul><li>of having an continuous environmental measurement and the possibility of logging personal health events.</li><li>getting recommendation (based on the provided big data analytics) from basic avoiding certain levels to supplement or counter measures.</li><li>personal recommendation — e.g. analyzing your next flat or house to be sure it does not affect your health.</li></ul><p>That is a long introduction for a comparison of IoT platforms. But I guess in order to compare the solutions we need an end to end use — case. Just comparing the prices of data storage won’t do it.</p><h3>The Milestones and KPIs</h3><p>In order to be able to compare the platforms we introduce sections (milestones) and some indicators for comparisons.</p><h4>KPIs (Key Performance Indicators)</h4><ul><li>K1: Cost of solution running continuous (€/year, €/user)</li><li>K2: Maintenance costs (€/year, €/user)</li><li>K3: Complexity of implementation (difficult=1, ok = 2, easy &amp; short=3)</li><li>K4: Documentation quality (none=1, some=2, more=3)</li><li>K5: Out of the box functionality (few=1, some hacking=2, all is there=3)</li></ul><h4>Milestones</h4><p>This is a prototype and we use javaccript where possible (Node.js) even if that is less suitable.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/844/1*55Ga3QTwD2bfT3n7Y_3-vg.png" /><figcaption>Milestones</figcaption></figure><ul><li>M0: Hardware setup (for all the same).</li><li>M1: Hardware connection (Raspberry Pi and its Sensors).</li></ul><blockquote>Easiest implementation with available libraries. No HW serial coding or embedded C programming (in case of MindSphere that might be necessary for the prototype 😅 node.js lib is not yet publicly available)</blockquote><ul><li>M2: Onboarding sensors (data).</li></ul><blockquote>Easiest onboarding of device. Outlook of onboarding further devices (automatic onboarding when user registers)</blockquote><ul><li>M3: Visualization of data.</li></ul><blockquote>Visualization (out of the box if available)</blockquote><ul><li>M4: User visualization and event handling (thresholds).</li></ul><blockquote>Users own device visualization and event handling (out of the box if available).</blockquote><ul><li>M5: User input in case of events or manual.</li></ul><blockquote>User input to enrich event data from the device. Easiest implementation. Outlook for mobile input.</blockquote><ul><li>M6: Integration of external data sources.</li></ul><blockquote>Adding external API available sensing data e.g. API call for the dedicated GPS coordinates and add them for data quality enriching.</blockquote><ul><li>M7: Analyzation of data (for correlation of air quality other factors on own health).</li></ul><blockquote>We won’t have big data but we provide data and check how difficult is penetration of this data (automated or manual). Machine learning for identifying correlation between sickness and various inputs.</blockquote><ul><li>M8: Automation (Sending commands to actuators)</li></ul><blockquote>Closing the feedback loop (e.g. automate the central heating actuator when events occur). Actuator control.</blockquote><h3>Possible non IoT-AEP implementation (non-sense implementation) — only for the concept</h3><p>Just make the <strong><em>pi</em></strong> a server — install a LAMP (Linux Apache My-SQL PHP) on the raspberry <strong><em>pi</em></strong> and provide a static IP or do IP forwarding so you can view data via HTML.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/850/1*UYXao6Qx09E4XwBU5JDIYw.png" /><figcaption>Milestones M0 — M3 implemented</figcaption></figure><blockquote>Mhhh. that would probably work for our prototype and only one device but even there you would need to update every now and then the LAMP stack to stay secure.</blockquote><p>You could add an API (Application Programming Interface) to your backend which allows a stronger server to collect the data from all the devices (raspberries).</p><blockquote>Mhhh that would probably work but still a lot of manual administration of devices, when scaling your data-server needs to be scaled as well and we have not even spoken about the security to be implemented for the data exchange as well cost of maintaining the own data center…</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/691/1*Md3qsyptIuNxYe_GFsgTOA.png" /><figcaption>completely out of the blue fictitious values — only for conceptual flow</figcaption></figure><p>The implementation has high continuous cost position like energy, procurement, invoicing, etc. for the user and the data collector. The data servers need space and cooling <strong>K1</strong><em>. </em>High maintenance costs including device stack upgrades to keep device security high as well as continuous updating and upgrading servers when scaling <strong>K2</strong>. The device as well as the data collector are quite complex to set up. Activities involve creating own solutions for every necessary functionality <strong>K3</strong>. On the positive side you will find a lot of tutorials and best practices for the different functions (but don’t necessarly know whether they are still secure) <strong>K4</strong>. When it comes to out of the box services — its all you. From defining the servers HW, setting the OS and installing the complete stack to program the front end and back end <strong>K5.</strong></p><p><em>Let’s start with setting up the hardware.</em></p><h3>M0 — The hardware setup</h3><p><em>If you are not interested in the hardware side you could directly switch to </em><a href="https://medium.com/@bertrand.jan/tell-me-more-internet-of-things-part-2-google-cloud-iot-cost-and-value-comparison-38bfb20d94e1"><strong><em>Part 2 </em></strong></a><em>— where we start with the IoT platform baby steps for Google IoT.</em></p><p>We need to get our sensor read in our device (<strong><em>pi</em></strong>). We have an analog measurement connecting directly on the analog Input / Outputs (IOs) provided by our raspberry. This measurement is continuous and we do not need to take care of any interval as the lifetime of the device is not dependent on managing the measurement cycle.</p><p>The Particulate Matter (PM) sensor is connected via USB and does have a lifetime of approximately 8000h if running continuously (60 meas./min) — it’s less than a year.</p><p>We want to query the sensor only every 3 min. for around 5s to get a valid measurement point.</p><h3>Bills of material (BoM)</h3><p>Prototype Product BoM:</p><ul><li>Raspberry Pi 3b+</li><li>Micro SD card 16GB</li><li>Sensor 1: SDS011</li><li>Sensor 2: HD011</li></ul><p>Tools for assembly of components and development</p><ul><li>Keyboard &amp; Mouse — for connecting to Raspberry (one time).</li><li>HDMI cable — for connecting the raspberry to a TV (one time).</li><li>Laptop — for accessing the raspberry remotely (SSH) and development.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/900/0*LoQg0iAn_kkkHMXu" /><figcaption><em>Material cost break down of the prototype (that is all way too expensive — i know)</em></figcaption></figure><h3>Setting up the Raspberry and connecting the sensors</h3><p>Skip this if you have a running <strong><em>pi </em></strong>with node.js 8*, npm 6* and git</p><p>There are plenty of tutorials for setting up a raspberry including the sensors.</p><p>At the end the HW should look like below and you should be able to connect to the raspberry pi remotely via PuTTY (on windows) or SSH (linux) from your laptop.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/803/0*dVNrCEgY8GsXn-YM" /><figcaption><em>My device remotely reachable on IP 192.16.0.167 and Port: 22. The devices default user: pi and password: raspberry</em></figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/900/0*ppI0rxO_Jd-GtNs-" /><figcaption><em>USB connected SDS011 sensor to the Raspberry (no humidity or temperature connected)</em></figcaption></figure><p>Once you are connected remotely to the command line (shell) of your <strong><em>pi</em></strong> we can start installing necessary software and packages for the development.</p><p>As outlined earlier we will try to us javascript (frontend and backend).</p><p>This project uses node.js version (backend javascript programming) 8 and the package manager (software packages for node) npm in version 6.</p><pre>pi@raspberrypi:~ $ <strong>node -v</strong><br>V8.12.0<br>pi@raspberrypi:~ $ <strong>npm -v</strong><br>6.4.1</pre><p>In order to install node on a pi I did some bash piping — meaning execute a script directly from the internet (<strong>curl</strong> <em>location-of-script-in-the-internet</em> | <em>(hand-it-over)</em> bash). <em>Actually for security reasons it might be always better to look first into a script before executing it!</em></p><pre>~ $ curl -sL <a href="https://deb.nodesource.com/setup_8.x">https://deb.nodesource.com/setup_8.x</a> | sudo -E bash <br>~ $ sudo apt-get install -y nodejs</pre><p>With that we should have node on the pi and the package manager npm running. In addition we use <a href="https://github.com/">github.com</a> for storing and pulling the different self created or adapted program code used for the different IoT Platforms.</p><p>The following command installs gits CLI (Command Line Interface) to your <strong><em>pi</em></strong></p><pre>pi@raspberrypi:~ $ <strong>sudo apt-get install git</strong></pre><h3>Retrieving the signals</h3><p>Our particulate matter sensor is connected to the USB port but should not be active yet. Let’s check the connection port with dmesg and find our that our sensor is connect on ttyUSB0</p><pre>pi@raspberrypi:~ $ <strong>dmesg | grep ttyUSB</strong><br>[544416.775421] usb 1–1.1.2: ch341-uart converter now attached to ttyUSB0</pre><p>We could probably study the specification of the UART communication protocol and implement our own serial driver. <a href="https://nettigo.pl/attachments/398">https://nettigo.pl/attachments/398</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/900/0*S5K6yucGFfl24fq-" /><figcaption>UART COM protocol</figcaption></figure><p>But we could as well just use the work from others</p><p><a href="https://www.npmjs.com/package/sds011-client">https://www.npmjs.com/package/sds011-client</a></p><p>Before installing this package let us set up our project folder tmmiot, create a tests subfolder, create a file index.js for reading the sensor data and write them to the console.</p><pre>~$ <strong>mkdir tmmiot &amp;&amp; mkdir tmmiot/tests &amp;&amp; cd tmmiot/tests</strong><br>~/tmmiot/tests $ npm init -y</pre><p>This creates a new file package.json which you could change with</p><pre>pi@raspberrypi: ~/tmmiot/tests $ <strong>nano package.json</strong></pre><p>Now we can add to the package dependencies the package which provides commands for communicating with the sensors.</p><pre>pi@raspberrypi: ~/tmmiot/tests $ <strong>npm i sds011-client -save</strong></pre><p>This will install all necessary files from the package to a subfolder node_modules<strong>. </strong>Our package.json file looks now like this — with the added dependencies.</p><pre>{<br> &quot;name”: &quot;tests&quot;,<br> &quot;version&quot;: &quot;1.0.0&quot;,<br> &quot;description&quot;: &quot;&quot;,<br> &quot;main&quot;: &quot;index.js&quot;,<br> &quot;scripts&quot;: {<br> &quot;test&quot;: &quot;echo \&quot;Error: no test specified\&quot; &amp;&amp; exit 1&quot;<br> },<br> &quot;keywords&quot;: [],<br> &quot;author&quot;: &quot;&quot;,<br> &quot;license&quot;: &quot;ISC&quot;,<br> &quot;dependencies&quot;: {<br> &quot;sds011-client&quot;: &quot;^0.0.1&quot;<br> }<br>}</pre><p>Looking on the <a href="https://github.com/ivkos/sds011-client">github</a> page for this package we can use those simple commands to see the readings on our console. Let’s open the index.js file and code our test.</p><pre>pi@raspberrypi: ~/tmmiot/tests $ <strong>nano index.js</strong></pre><p>In index.js editor paste following code.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/3a4ca291a1759714c579803645fb4d29/href">https://medium.com/media/3a4ca291a1759714c579803645fb4d29/href</a></iframe><p>After executing the script we see every second a new reading on the console. You could change the frequency to 1 min. for example sensor.setWorkingPeriod(1)</p><pre>pi@raspberrypi: ~/tmmiot/tests $ <strong>node index.js</strong></pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/803/1*-wQpG__FVBP28sExB-WRVg.png" /><figcaption>Output of the sensor data with 1 sec. sample rate</figcaption></figure><blockquote>Troubleshoot: Your <strong>pi</strong><em> </em>user need to have the rights to access the group tty</blockquote><pre><a href="http://twitter.com/raspberrypi">@raspberrypi</a>:~/tmmiot/test $ <strong>groups</strong><br>pi adm dialout cdrom sudo audio video plugdev games users input netdev gpio i2c spi</pre><blockquote>If this looks like this you need to add yourself the tty group</blockquote><pre>pi@raspberrypi:~/tmmiot/test $ sudo usermod -a -G tty pi</pre><blockquote>Logoff ~<em>$</em> exit and the new group is added.</blockquote><blockquote>Congratulation you have mastered the hardware setup for the PM Sensor. The humidity and temperature sensor is just for your own exploration 😃</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/787/1*KI7X48-11hGT3Icyoh7GsA.png" /><figcaption>Adding the humidity and temperature sensor DHT22 (all installed on a development board sunfounder super kit)</figcaption></figure><p>Next IoT it is. <a href="https://medium.com/@bertrand.jan/tell-me-more-internet-of-things-part-2-google-cloud-iot-cost-and-value-comparison-38bfb20d94e1"><strong>Part 2</strong></a></p><p>I like your comments, corrections, and suggestions 👌.</p><figure><a href="http://bit.ly/2G71Sp7"><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*fKX2mtg7p1lOs7JmosPLsA.png" /></a></figure><blockquote><a href="https://coincodecap.com/?utm_source=coinmonks">Get Best Software Deals Directly In Your Inbox</a></blockquote><figure><a href="https://coincodecap.com/?utm_source=coinmonks"><img alt="" src="https://cdn-images-1.medium.com/max/584/0*OJ-qb5G6i863msBB.png" /></a></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=558ce8966767" width="1" height="1" alt=""><hr><p><a href="https://medium.com/coinmonks/tell-me-more-internet-of-things-part-1-iot-platform-cost-and-value-comparison-558ce8966767">Tell me more Internet of Things — Part 1 —  IoT platform cost and value comparison</a> was originally published in <a href="https://medium.com/coinmonks">Coinmonks</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Exploring IOTA #ICT-3, Reverse engineering the code Part-2]]></title>
            <link>https://medium.com/coinmonks/exploring-iota-ict-reverse-engineering-the-code-part-2-bfa3cc1fba88?source=rss-14c8d196ddc0------2</link>
            <guid isPermaLink="false">https://medium.com/p/bfa3cc1fba88</guid>
            <category><![CDATA[reverse-engineering]]></category>
            <category><![CDATA[ict]]></category>
            <category><![CDATA[iota]]></category>
            <category><![CDATA[iot]]></category>
            <category><![CDATA[blockchain]]></category>
            <dc:creator><![CDATA[Jan Bertrand]]></dc:creator>
            <pubDate>Wed, 22 Aug 2018 07:20:32 GMT</pubDate>
            <atom:updated>2020-09-01T17:23:06.935Z</atom:updated>
            <content:encoded><![CDATA[<h4>Diving deeper in this little code base of ICT (IOTA controlled agenT). Trying to figure out why invalid Txs (Transactions) got passed ICT and IRI (IOTA Reference Implementation). Finally discussing what will be the next step in this testing phase of ICT.</h4><p>The <strong>ICT</strong> test phase 0.1.1 was stopped by<strong> CfB</strong> (<strong>C</strong>ome-<strong>f</strong>rom-<strong>B</strong>eyond) phasing it out over a week, requesting the participants to disconnect their <strong>ICT</strong> clients from the main net and their connected nodes. Over a week you could follow a few testers confirming on DISCORD ICT off that was about a month ago in late July. But the <strong><em>why </em></strong>and <strong><em>what is next</em></strong> will be discussed later.<br>Now we deep dive into why<strong> ICT</strong> during test phase 0.1.1 has been over time poorly performing due to invalid transaction which never should have been gossiped by either <strong>ICT</strong> nor <strong>IRI</strong> (<strong>I</strong>OTA <strong>R</strong>eference <strong>I</strong>mplementation is the node software which holds the distributed tangle).</p><p>The source code of the recompiled ict-0.1.1 can be found here (no worries CfB stated that we can expose the code as he is about to publish it… As there are new test phases entered the next version might be significantly changed anyways).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/603/1*HIO3aXxsCo0lpf7yG85ugw.png" /><figcaption>Come-from-Beyond statement exposing the code base</figcaption></figure><p><a href="https://github.com/jhab82/ict-0.1.1_jhab82">jhab82/ict-0.1.1_jhab82</a></p><p>When we started the alpha testing of <strong>ICT </strong>0.1.1 there have been phases where my <strong>ICT</strong> was not active really even though it was connected to at least 4 neighbor <strong>IRI </strong>nodes. And with active I mean my<strong> ICT</strong> was almost not gossiping Tx to its neighbors.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*HqW9q3zxjBxTnGsPh9nheA.png" /><figcaption>7 days ICT performing on the f1-micro cloud instance. The first 2–3 days almost no outbound Tx as of invalid transaction getting gossiped.</figcaption></figure><p>In order to analysis the cause we need to understand what the <strong>ICT</strong> logic stopped sending the <strong>UDP</strong> (<strong>U</strong>ser <strong>D</strong>atagram <strong>P</strong>rotocol)packets back to its neighbors.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/594/1*9Dz2T_zEnQJLzfue9PnGxw.png" /><figcaption>Sharing the analysis on DISCORD #ICT channel</figcaption></figure><p>I recognized that the invalid Tx counter was active in every epoch (every minute of processing before <strong>ICT</strong> is reset and starts over again). Checking the logic the <strong>IRI </strong>node (<strong>ICT</strong> is connected to) gets ignored with further sharing its Tx once the invalid Tx has been seen by <strong>ICT</strong>.</p><p>That means depending on the time when the invalid Tx is recognized no Tx are transmitted. In our case there where invalid Tx after already a couple of seconds in an epoch. This leads to almost no outbound traffic</p><p>After recompiling the Trasaction.java and adding some lines in that class which allowed me to check why the Tx are invalid I concluded that all invalids are caused by an earlier TimeStamp than</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/9d16ba566a8d8915aa3538c2fc5d539b/href">https://medium.com/media/9d16ba566a8d8915aa3538c2fc5d539b/href</a></iframe><p>By using the following command we get the timestamp in an human readable format.</p><pre>$date -d @1508760000<br><strong>Mon Oct 23 12:00:00 UTC 2017</strong></pre><p>I added in tha if statement above following command</p><pre>System.out.println(Converter.trytes(trits,0,8019));</pre><p>and was able to retrieve the invalid Tx which caused the<strong> ICT</strong> to stop gossiping. It turned out this time the infamous FPSbundle caused the <strong>ICT</strong> to stop gossiping</p><pre>BUNDLE: FPSJJPZO9LGRIZLLHTNCBEELJHKJSPXJDXLFGKPTTTXZMAZZNKIXHQTTOPURGGVLKNZVAS9FTCUFUIMB9</pre><p><a href="https://thetangle.org/bundle/FPSJJPZO9LGRIZLLHTNCBEELJHKJSPXJDXLFGKPTTTXZMAZZNKIXHQTTOPURGGVLKNZVAS9FTCUFUIMB9">Bundle FPSJJPZO9LGRIZLLHTNCBEELJHKJSPXJDXLFGKPTTTXZMAZZNKIXHQTTOPURGGVLKNZVAS9FTCUFUIMB9</a></p><p>Looking at the transaction object ( you can get a better view of a transaction by converting the trytes to the below representation using iota.utils.transactionObject(TxInTrytes) )</p><pre>{ hash: &#39;ZQNFEEIHXB9LEHAUDYMEDQCKA9CGYHIYORBYJTZ9XUDULKWAE9KDBXG9DVQEHPMFWZRUEKDVXJLCA9999&#39;,<br>  signatureMessageFragment: &#39;KTCNPN...(shortened)...UOZ&#39;,<br>  address: &#39;JNYEGRFRQQNYQNMJV9YRPRWMEGBZYLNHURIGEGQWF9AISLMQEUZOEBDBQYETETKEBLUQNGVAOGWXHQKEY&#39;,<br>  value: 0,<br>  obsoleteTag: &#39;999999999999999999999999999&#39;,<br> <strong> timestamp: 1507219591,</strong><br>  currentIndex: 2,<br>  lastIndex: 3,<br>  bundle: &#39;FPSJJPZO9LGRIZLLHTNCBEELJHKJSPXJDXLFGKPTTTXZMAZZNKIXHQTTOPURGGVLKNZVAS9FTCUFUIMB9&#39;,<br>  trunkTransaction: &#39;NEJKMDKIPBRISDEXICIXGMNCGTV9NGKLMPNIOUWESVIIUQFOEQQHZEENBWFWLAIFREZBYRNJWOISZ9999&#39;,<br>  branchTransaction: &#39;SIQJAMJKQISZGI9J9JAKFSGVLAPLMMBVJEXLSQLLEZQTIKQPQTBZ9JFIARRFKRMLMXZNQUVEFJYEA9999&#39;,<br>  tag: &#39;999999999999999999999999999&#39;,<br>  attachmentTimestamp: 1531119376226,<br>  attachmentTimestampLowerBound: 0,<br>  attachmentTimestampUpperBound: 12,<br>  nonce: &#39;BFA999GC99IPA99999999999999&#39; }</pre><p>As seen above the timestamp of this Tx is before the allowed one which throws an error and ignores this node from that moment on.</p><pre>$ date -d @1507219591<br>Thu Oct  5 16:06:31 UTC 2017</pre><p>In the code that is realized by checking whether the invalid transaction counter of a neighbor is exceeding zero. If that is the case, the while loop is entered again (realized by continue; )</p><pre>101  if (neighbor2.numberOfInvalidTransactions != 0) {<br>102      continue;<br>103  }</pre><p>And this is where the counter is increased to one (the counter will not exceed one as the loop is discontinued as with the above statement.)</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/8aa4e53f2ee2dbecabf040267b0d6684/href">https://medium.com/media/8aa4e53f2ee2dbecabf040267b0d6684/href</a></iframe><p>Looking at the FPS Bundle it apparently has been issued back in October the 5th and until now there are still reattaches. At some point the bundle stopped getting reattached and the <strong>ICT</strong> invalid Tx counter stayed 0 and the network got healthy again.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/599/1*5iTrXT14yGwr-17agg0k8Q.png" /><figcaption>Yellow marked the invalid Tx counter getting 0 again after the FPS stopped getting reattached</figcaption></figure><p>Which leaves us the questions why did <strong>IRI </strong>pass those invalid Tx in the first place. And the answer to that questions in my opinion should be found in the <strong>IRI</strong> source code.</p><p>Heading over to <a href="https://github.com/iotaledger/iri">https://github.com/iotaledger/iri</a> and searching in the code base for Timestamp — we like to find out where <strong>IRI</strong> decides to ignore a transaction based on its timestamp.</p><p>After some trials (there is currently no documentation of the code available) I found the class TransactionValidator.java . Here is the boolean function hasInvalidTimestamp(TransactionViewModel transactionViewModel) returns true once the transaction timestamp meets listed criteria, one of them it needs to be larger than snapshotTimestampMs</p><pre><strong>return transactionViewModel.getAttachmentTimestamp() &lt; snapshotTimestampMs</strong>                || transactionViewModel.getAttachmentTimestamp() &gt; System.currentTimeMillis() + MAX_TIMESTAMP_FUTURE_MS;</pre><p>Which ist according to IOTA.java</p><pre>long snapshotTimestamp = configuration.longNum(Configuration.DefaultConfSettings.SNAPSHOT_TIME);</pre><p>and Configuration.java at the moment</p><pre>public static final String GLOBAL_SNAPSHOT_TIME = &quot;1531148400&quot;;</pre><p>But this still doesn’t tell us that all transaction with lower timestamp should get ignored by IRI.</p><p>We find in Node.java a function preProcessReceivedData(...) which should preprocess incoming transactions from its neighbors. It loops through all neighbors IPs and only continue once the IP address of the sender senderAddress matches on of the IPs of the neighbors. This step actually ignors all incoming packets from other IPs to be further processed. Than their is some random dropping of transaction done — don’t know the purpose yet.</p><p>After that the try {} statement</p><ul><li>from the transaction message a hash is created</li><li>check whether the transaction has been recently seen recentSeenBytes</li></ul><p>Only if the transaction is not cached the transaction gets validated. The Object TransactionModel is created and with that the validation run is entered where our earlier exception should be thrown once the timestamp of the transaction is earlier than the GLOBAL_SNAPSHOT_TIME . This exception is caught with</p><pre>} catch (final TransactionValidator.StaleTimestampException e) {</pre><p>and increases the numberOfInvalidTransaction++ for that neighbor.</p><p><a href="https://github.com/iotaledger/iri/blob/d59de9fbaa2432a7123d9a4d65a1555241fcd934/src/main/java/com/iota/iri/network/Node.java">iotaledger/iri</a></p><p>This whole validation and preprocessing is handled via a hash of the actual transaction. When the runValidationthrows the timestamp exception the transaction should be removed from the queue of transactions to be further processed:</p><pre>transactionRequester.clearTransactionRequest(receivedTransactionHash);</pre><p>Clearly the Tx should not been transmitted in the first place this is obvious by the implementation in <strong>IRI</strong>. <strong>Still I am not able to figure out where the bug resides. </strong>It could have many reason but one possible explanation is that the faulty transaction is not removed from the queue and therefore gets processed further. Another possibility is that the preProcessReceiveData is getting bypassed.</p><p>As I still have no full node actively participating on the tangle I am not able to debug this situation. I think I will leave that for another time — maybe it will be already solved with the next <strong>IRI </strong>release or its actually not a bug but a feature 😅</p><p><strong>Summing it up:</strong> I have looked at both <strong>ICT</strong> and <strong>IRI</strong> java code and understood by that a little more the mechanics of both implementations — specially in connection with recognizing invalid transactions.</p><p>Where <strong>ICT </strong>is gossiping valid transactions to its neighbors it ignores for the rest of the 60s epoch the neighbor with invalid transactions. This had caused <strong>ICT </strong>perform quite poorly (in terms of not gossiping Tx) over some period of testing phase 0.1.1 as transaction have been passing <strong>IRI</strong> with invalid timestamps.</p><p>CfB himself confirmed that those Tx should not been shared by <strong>IRI</strong> and I tried in the above article to find the cause. Unfortunately I couldn&#39;t quite figure out the cause but outlined the problem and diving into the code where it should get excluded.</p><h4>Whats next on ICT</h4><p>As mentioned earlier the testing of ict-0.1.1 has stopped and with that the second testing phase was announced.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/408/1*3VpOE76s3vcVfwnZySIoUw.png" /><figcaption>Screen from Discord</figcaption></figure><p>The second testing phase apparently should be without any IRI nodes connected to ICT but only with ICTs connected to ICTs. The transaction structure will be changed that only ICT participants validating this structure can participate. This sounds like we are testing the concept of <strong>EC E</strong>conomic <strong>C</strong>lustering. Here network participants are in an ICT independent cluster but still over the internet processing their transactions.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/410/1*2cVv7MPrgB7G4g-yb_AX1Q.png" /></figure><p>When? It is not very clear at the moment. First the final IOTA Tx structure needs to be aligned and then the ICT code - specially the Transaction.java — need to be changed.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/404/1*xo4qiBW7VWzt6Kxuiy4Shw.png" /></figure><p>In addition to the new Tx structure CfB would like to test disturbance of the network by spammers joining the test. He will provide a java spammer which should then be used for disturbing the network (even the FPGA F<strong>ield-Programmable Gate Array </strong>guys<em> </em>should join the party.)</p><p>And finally some recommendation which attack transaction will most likely get past <strong>ICT</strong> protection. <strong>Very much looking fwd. to find out which protection CfB is talking about here 👌</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/406/1*wRQR0xEH36cYC-cBU2_6EQ.png" /></figure><p>Initially I guess the second test phase of <strong>ICT</strong> should have been further continued on the main net but there has been some debate on whether the auto-tethering functionality (Nelson) of the popular node software (Hercules) by <em>Roman Semko</em> is potentially disturbing the network performance.</p><p>If I understood it correctly <em>Roman</em> came up with the solution to get around asking for neighbors to connect your Node to.</p><p><em>A bigger headache for everyone to run their own node to set manually up neighbors. Without neighbors you are not receiving the transaction of the network and won’t support the tangle at all. Roman early understood this hassle and implemented an automatic functionality where neighbors getting rotated by certain metrics and most important you don’t have to know other node operators nor you need Discord and ask under #nodesharing who wants to add you as a neighbor.</em></p><p>Why this functionality is not intended by design is explained in the official IOTA FAQ.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/648/1*Z_lddB7oCtkE5crPpq14vw.png" /><figcaption>Screen from IOTA official FAQ</figcaption></figure><p>Note that IOTA themselves already in 2016 tried auto-tethering (peer discovery) but discontinued as of the same explained drawbacks</p><p><a href="https://forum.iota.org/t/discussion-removing-peer-discovery/939">Discussion: Removing Peer Discovery</a></p><p>When it comes to ICT I guess CfB likes to enable a function which caps inflowing Txs.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/518/1*7tdBcugTwvHN2Vss2uIPYw.png" /></figure><p>Due to an interesting complex paper there is some proof of how the network topology should look like in a wireless network setup (I tried to read and understand what this paper proofed but I couldn’t get passed the first picture). What I understood is that they have researched the <em>average consensus algorithm </em>— where a discrete number measurement nodes would converge to a consensus about their average measurement better if the network topology stays constant and simple.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/637/1*9aSwetxdBZeU4Vupnpr6Fg.png" /><figcaption><a href="https://www3.nd.edu/~mhaenggi/pubs/jstsp11.pdf">https://www3.nd.edu/~mhaenggi/pubs/jstsp11.pdf</a></figcaption></figure><p>As it seems the peer discovery implementation by Roman will not be discontinued in the short run and with that a majority of the network participants are connecting via auto-tethering on that internet holding tangle main net — ICT second test phase moves to its own network.</p><p>In order to exclude any interference from that auto-tethering <strong>ICT</strong> needs his own network which should best be represented for the future IoT world. This network will be based on an unique transaction model structure which will exclude any main net Tx.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/683/1*9LrFrHJfBlrc5mYnpdk40w.png" /></figure><p>Further there is some light over the<strong> EC (E</strong>conomic <strong>C</strong>luster)sand wireless ad-hoc networks as the later will have <strong>NBPoW (N</strong>etwork <strong>B</strong>ound <strong>P</strong>roof of <strong>W</strong>ork) to secure it. In an IoT environment only devices within the wireless network reach will be able to peer.</p><p>If you then follow past conversations of CfB and his implementation of this PoW <em>“IOTA ability of a node to occupy some range of the EM spectrum for some interval of time works as an anti-Sybil measure. Spectrum is a very scarce resource (@FCC can confirm that)…”</em></p><p>the purpose and functionality of <strong>ICT </strong>becomes a bit more clear.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/667/1*E0rgCqgIWux9ALWp64hbJg.png" /></figure><p>Here the first two articles of the <strong>ICT </strong>side exploration:</p><ul><li><a href="https://medium.com/coinmonks/exploring-iota-ict-1-running-ict-on-a-cloud-computer-bc3d96b246ea">Exploring IOTA #ICT-1, testing ICT on a cloud computer</a></li><li><a href="https://medium.com/coinmonks/exploring-iota-ict-2-reverse-engineering-the-code-1-ecda56d4908">Exploring IOTA ICT, Reverse engineering the code Part-1</a></li></ul><p>If you like to start exploring IOTA yourself you can start here with your first self made transaction.</p><p><a href="https://medium.com/coinmonks/exploring-iota-1-getting-a-linux-terminal-on-cloud-google-com-and-sending-a-transaction-d7b9f1ce100a">Exploring IOTA #1 - getting a linux terminal on google cloud and sending a transaction</a></p><p>Looking forward to your comments, doubts and corrections 👍</p><p>Cheers,<br>Jan</p><blockquote><a href="https://coincodecap.com/?utm_source=coinmonks">Get Best Software Deals Directly In Your Inbox</a></blockquote><figure><a href="https://coincodecap.com/?utm_source=coinmonks"><img alt="" src="https://cdn-images-1.medium.com/max/584/0*OJ-qb5G6i863msBB.png" /></a></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=bfa3cc1fba88" width="1" height="1" alt=""><hr><p><a href="https://medium.com/coinmonks/exploring-iota-ict-reverse-engineering-the-code-part-2-bfa3cc1fba88">Exploring IOTA #ICT-3, Reverse engineering the code Part-2</a> was originally published in <a href="https://medium.com/coinmonks">Coinmonks</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Exploring IOTA #ICT-2, Reverse engineering the code Part-1]]></title>
            <link>https://medium.com/coinmonks/exploring-iota-ict-2-reverse-engineering-the-code-1-ecda56d4908?source=rss-14c8d196ddc0------2</link>
            <guid isPermaLink="false">https://medium.com/p/ecda56d4908</guid>
            <category><![CDATA[reverse-engineering]]></category>
            <category><![CDATA[tutorial]]></category>
            <category><![CDATA[iota]]></category>
            <category><![CDATA[java]]></category>
            <category><![CDATA[ict]]></category>
            <dc:creator><![CDATA[Jan Bertrand]]></dc:creator>
            <pubDate>Tue, 24 Jul 2018 05:48:42 GMT</pubDate>
            <atom:updated>2018-10-08T18:37:37.881Z</atom:updated>
            <content:encoded><![CDATA[<h4>We explore how to decompile java source code with the help of publicly available web-based java decompilers. Then recompile it using the standard java compiler. Changing the code in order to confirm receiving UDP packets. With that starting to understand the code of ICT hopefully 😄</h4><p>Maybe that’s a bit too complex for me, trying to understand just by looking at the code the underlying purpose of IOTA controlled agent (ICT). Major reasons:</p><ul><li>I am not a coder by profession</li><li>I have no experience with swarm logics</li><li>my first experience with Java dates back to school-time but that was in the early 90s.</li><li>…</li></ul><p>Anyway — lets just do it.</p><p><em>I am still testing this on my google cloud instance (f1-micro). My text editor is vim (which i have kind of hate/love relationship already) — please have look at my other articles if you want to set this environment up yourself.</em></p><ul><li><a href="https://medium.com/coinmonks/exploring-iota-1-getting-a-linux-terminal-on-cloud-google-com-and-sending-a-transaction-d7b9f1ce100a">Exploring IOTA #1 - getting a linux terminal on google cloud and sending a transaction</a></li><li><a href="https://medium.com/coinmonks/exploring-iota-ict-1-running-ict-on-a-cloud-computer-bc3d96b246ea">Exploring IOTA #ICT-1, testing ICT on a cloud computer</a></li></ul><p>This article is not intended to harm or disturb the testing phase of ICT. It documents my trial to understand the underlying mechanics of ICT by looking at the code base (there is not much else at the moment except that — no documentation). I’ve asked Come-from-Beyond on discord #ICT channel to publish this baby steps.</p><p>Furthermore I might be totally wrong with my findings 😄</p><h4><em>Decompiling the class files</em></h4><p>If you were one of the lucky ones able to download the first pre-alpha release from ICT (0.1.1) (in the official IOTA discord channel) you can follow up on all the next steps. If not then maybe there will be the next chance on version 0.1.2. <strong>Come-from-Beyond</strong> mentioned on discord that he is releasing the code after refactoring anyway soon.</p><p>The *.class files (compiled *.java code) are compressed hidden in that little zip file. After you extract the files you could use available online decompliers which try to inverse the compilation by using different strategies. I used this site</p><p><a href="http://www.javadecompilers.com/">http://www.javadecompilers.com/</a></p><p>Those different strategies can be selected upon uploading the class file. I tried <strong>CFR</strong> first but wasn’t successful — the code was not entirely readable and more importantly it wasn’t able to be compiled again. The best result I achieved with the <strong>Procycon</strong> strategy.</p><ul><li>decompile all class files in the zip folder with Procycon and store the resulting java files.</li></ul><p>We can use any text editor for having a first glance at the code.</p><p>There are five files to be looked at</p><ul><li><strong>Ict.java</strong> — the main class file which hold the complete schedule and main function.</li><li><strong>Transaction.java </strong>— the class which analysis the received IOTA transactions and returns errors if not valid</li><li><strong>Converter.java</strong> — which translates the received transactions from bytes to trits and trytes (those conversion transfer functions are string based)</li><li><strong>Curl.java</strong> — the infamous hash function recalculating the hash of this transaction and confirm the validity of the so called nonce.</li><li><strong>Neighbor.java</strong> — just logging incoming/outgoing transactions into groups (all, new, invalid, requested, shared)</li></ul><h4>Recompiling the java files</h4><p>I mean I had no clue about the code after decompiled the class files. But Iknew I need to somehow check how i can compile those java files again to finally start the application again.</p><p>First thing you need to have the command available to compile the classes. Which means you might need to change from the Java Runtime Environment JRE to the Development Kid JDK, which just needs a couple of 50MB more than the former.</p><pre>~$ sudo apt-get update<br>~$ sudo apt-get install default-jdk</pre><p>Next we are going to compile all java files and move them into the dedicated class path indicated in the java files. Lets assume we have created a subfolder IOTA</p><pre>~/IOTA$ javac *.java<br>~/IOTA$ mkdir cfb &amp;&amp; cd cfb<br>~/IOTA/cfb$ mkdir ict<br>~/IOTA$ mv *.class cfb/ict/</pre><p>The class file need to be placed in a relative path to where you start the application or we would need to add their location in environment PATH variables. Looking at the first lines of our decompiled Ict.java<strong> </strong>file shows that java expect the package and classes to be found in cfb.ict<em>.</em></p><pre>// <br>// Decompiled by Procyon v0.5.30<br>// <br><br><strong>package cfb.ict</strong>;<br><br>import <strong>cfb.ict.</strong>Converter;<br>import cfb.ict.Neighbor;<br>import cfb.ict.Transaction;<br><br>import java.util.HashMap;<br>import java.net.SocketAddress;</pre><p>Other classes like HashMap and SocketAddress are imported from the known libraries within java.</p><p>With this we can start the recompiled java program. We just need to place a file <strong>ict.properties </strong>(with only one line <strong>port=<em>11111</em></strong>) in our IOTA folder. From here we can start the program with the following command</p><p>🔥 Please don’t use the recompiled ICT with real IRI neighbors on the main-net. This is why i have used a different port (11111). We don’t know whether the program is working properly and we don’t want to disturb the tests. Furthermore if your neighbors have added you, they did most likely because they expect you to have a normal ICT and might not be too happy if you use them as your own test devices 👊</p><pre>~/IOTA$ java cfb.ict.Ict ict.properties</pre><p>We have specified the main class ICT to be called in cfb.ict and hand over the file ict.properties. The output is not that spectacular as we have no incoming traffic yet.</p><pre>[2018-07-22T11:28:30.883] Ict 0.1.1<br>2018-07-22T11:28:31.049<br>Number of transactions = 0<br>Number of missing transactions = 0</pre><p>Next we are going to send a message to the ICT via UDP from a different f1-micro instance. Which means just set up another cloud f1-micro instance or use any other linux distribution which is connected to the internet and is not blocked by your ICT client.</p><p>The easiest way to send an UDP packet to your ICT client I found is this</p><pre>$echo &quot;Hello ICT&quot; &gt; /dev/udp/YOUR_ICT_IP/11111</pre><p>Which results on your ICT side (once a minute has passed) to immediate boring response</p><pre>[2018-07-22T11:28:30.883] Ict 0.1.1<br>2018-07-22T11:28:31.049<br>Number of transactions = 0<br>Number of missing transactions = 0<br><br><strong>2018-07-22T11:30:11.848<br>Number of transactions = 0<br>Number of missing transactions = 0</strong></pre><p>In order to make sure we receive the packet lets rewrite the code which prints our transmitted UDP message. After the byte[] data = datagramPacket.getData(); we add the following in order to print the incoming packets.</p><pre>String string = new String(data, 0, datagramPacket.getLength());<br>System.out.println(string);<br>System.out.println(&quot;----&quot;);</pre><p>In addition we like to see the IP of the sender and we add after the final SocketAddress socketAddress = datagramPacket.getSocketAddress(); the following code to print the address</p><pre>System.out.println(&quot;SocketAddress =&quot; + socketAddress);</pre><p>After compiling the ICT.java and moving the *.class file to cfb/ict/ we can rerun our recompiled and changed ICT. Once we send four times the same message again we get this result (leave it a minute time to get the last lines):</p><pre>[2018-07-22T11:46:39.484] Ict 0.1.1<br>2018-07-22T11:46:39.585<br>Number of transactions = 0<br>Number of missing transactions = 0<br>Hello ICT<br>----<br>Hello ICT<br>----<br>Hello ICT<br>----<br>Hello ICT<br>----<br>2018-07-22T11:47:44.403<br>Number of transactions = 0<br>Number of missing transactions = 0</pre><p>We get the messages but no information about the IP address. Revisiting the code that is due to not getting passed this statement:</p><pre>if (datagramPacket.getLength() != 1650) {<br>       datagramPacket.setLength(1650);<br>}  else {</pre><p>Constructing a message with 1650 chars should be easy with linux, we can even use the SEED generation function and extend to 1650 in order to just get capital A...Z9</p><pre>cat /dev/urandom |tr -dc A-Z9|head -c${1:-1650} &gt; <strong>test.tx</strong></pre><p>we can’t use our echo command here as it breaks our 1650 length message into smaller messages. But we can do the following on our non-ict instance</p><pre>cat <strong>test.tx</strong> &gt; /dev/udp/10.142.0.4/11111</pre><p>The result actually won’t print the complete message but we get more</p><pre>{deleted: content of test.tx 1650 chars long}<br>----<br>SocketAddress =/IP:39025<br>2018-07-22T11:59:59.169<br><strong>/IP:39025: 2 / 0 / 1 / 0 / 0</strong><br>Number of transactions = 0<br>Number of missing transactions = 0</pre><p>The bold marked line from the above ICT report is new and needs to be understood — looking at the code Alex from the official developer Discord did a thorough summary. Which at least one of those statement we have just proven invalidTxs ourselfs</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/358/1*_7kwhqwViIMts8heyxlAnQ.png" /><figcaption>Description of ICT logs by Alex</figcaption></figure><ul><li>allTxs = number of UDP packages received at the specified port (default=14265) during a 1min period.</li><li>newTxs = number of valid transactions, that weren&#39;t received before during a 1min period.</li><li>invalidTxs = number of UDP packages, that don&#39;t form a proper transaction (invalid value, invalid address, invalid timestamp, i.e. before Mon Oct 23 12:00:00 UTC 2017, invalid transaction hash).</li><li>requestedTxs = number of times the ICT could answer a request for a certain transaction from this neighbor.</li><li>sharedTxs = number of new transactions, that were relayed to that neighbor during a 1min period.</li><li>Number of transactions = sum of all newTxs of all neighboring nodes during a 1min period.</li><li>Number of missing transactions = number of all requests, the ICT couldn&#39;t answer during a 1min period.</li></ul><p>And we can extend the statement by our observation. The number of invalidTxs will not increase further than one. As you can see above, I’ve send two times the test.tx invalid transaction and the counter stopped at one. This is most likely as the code for validation of the transaction is not entered again in that epoch (1min. period) once a invalid transaction is found.</p><p>Summing it up: We have used online decompilers to look at the ICT java code which we then recompiled using standard java compiler and let it run again. We send UDP packets to our recompiled ICT and analysed by that the first few lines of the code.</p><p><em>In the next chapter I am planning (try) to get deeper into the logics of ICT and show you how we can identify invalid transaction and understand why they are getting pass IRI and ICT at the moment.</em></p><p><strong>I’d love to see your questions doubts or corrections</strong></p><p>Cheers,<br>Jan</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ecda56d4908" width="1" height="1" alt=""><hr><p><a href="https://medium.com/coinmonks/exploring-iota-ict-2-reverse-engineering-the-code-1-ecda56d4908">Exploring IOTA #ICT-2, Reverse engineering the code Part-1</a> was originally published in <a href="https://medium.com/coinmonks">Coinmonks</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Exploring IOTA #ICT-1, testing ICT on a cloud computer]]></title>
            <link>https://medium.com/coinmonks/exploring-iota-ict-1-running-ict-on-a-cloud-computer-bc3d96b246ea?source=rss-14c8d196ddc0------2</link>
            <guid isPermaLink="false">https://medium.com/p/bc3d96b246ea</guid>
            <category><![CDATA[iota]]></category>
            <category><![CDATA[raspberry-pi]]></category>
            <category><![CDATA[ict]]></category>
            <category><![CDATA[technology]]></category>
            <category><![CDATA[f1-micro]]></category>
            <dc:creator><![CDATA[Jan Bertrand]]></dc:creator>
            <pubDate>Fri, 29 Jun 2018 18:49:29 GMT</pubDate>
            <atom:updated>2018-07-03T11:23:27.853Z</atom:updated>
            <content:encoded><![CDATA[<h4><strong>I</strong>OTA <strong>C</strong>ontrolled agen<strong>T (ICT) has been released for testing in the official discord channel. I will show you how to run it on your f1-micro (small computer) cloud instance.</strong></h4><p>I am not cover here what ICT should solve or what in its final implementation is doing. Simply because i can’t - Its pre alpha testing. There is some speculation about it but until I have not seen it and understood the underlying mechanics that is just guessing or speaking about something someone spoke about. For now, I just let it run :-)</p><p>There are six easy bullets explained by <strong>Come-from-Beyond</strong> how to set up his little java program.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/378/1*PAODrgYoLo96NQc-Q498Bg.png" /><figcaption>Screenshot from CFB steps for this test</figcaption></figure><p>There is further communication that the best hardware for this test should be a raspberry Pi Minus One. I have a raspberry Pi 3b+ and successfully set it up, but my combo modem/router won’t allow me to fwd. the necessary port so I ignored “a little” CFBs advices (“better Raspi only”) — sorry — run the program on a <strong>V</strong>irtual <strong>P</strong>rivate <strong>S</strong>erver VPS how you could call my little computer on google server farms (name: f1-micro).</p><p>If you want to follow this tutorial please get yourself a VPS — here i explained how to get yourself a f1-micro cloud instance. <a href="https://medium.com/coinmonks/exploring-iota-1-getting-a-linux-terminal-on-cloud-google-com-and-sending-a-transaction-d7b9f1ce100a"><strong>Exploring IOTA #1</strong></a></p><p>Lets get some information about the hardware we just created. Open from your webbrowser the SSH web-terminal and type:</p><pre>:~$ cat/proc/meminfo<br><strong>MemTotal:         606684 kB</strong><br>....</pre><p>Which means have we 606MB of memory. Now we get the cpu information</p><pre>:<strong>~</strong>$ cat /proc/cpuinfo<br>processor       : 0<br>vendor_id       : GenuineIntel<br>cpu family      : 6<br>model           : 63<br>model name      : Intel(R) Xeon(R) CPU @ 2.30GHz</pre><p>How can we have 0 processors?</p><p>Following a bit research the f1-micro actually has a shared-core which is than 0.2 virtual CPU (a virtual CPU is a single hardware hayperthread on an Intel Xeon E5)</p><p>For mor detail info:</p><p><a href="https://www.opsdash.com/blog/google-cloud-f1-micro.html">Exploring the Google Cloud f1-micro Instance - OpsDash</a></p><p>Than we could check which linux dist. we have on our system with</p><pre>:<strong>~</strong>$ cat /etc/issue<br>Debian GNU/Linux 9 \n \l</pre><h4>Download the zip file</h4><p><strong>Edit 30.06.2018</strong>: By now the file is not available any longer- i am afraid to mirror it as of disturbing the test — you may want to wait for the next testing phase (and join the <a href="https://www.google.de/search?rlz=1C1CHBD_deDE710DE711&amp;ei=ol03W9DmE4rosAeT3bm4DA&amp;q=official+IOTA+discord+chat&amp;oq=official+IOTA+discord+chat&amp;gs_l=psy-ab.3..0i71k1l8.0.0.0.1689.0.0.0.0.0.0.0.0..0.0....0...1..64.psy-ab..0.0.0....0.2f-ADx97m0c">official discord channel</a> in between for new news in the #ICT channel)</p><p>you can import the zip file by using SSH or the SSH web browser functionality</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/309/1*wciiaFsgGdyuIqOgAFlRRw.png" /></figure><p>This uploads the file to your home directory so you may want to move them into a seperate newly created folder</p><pre>:~$mkdir iota-ict<br>:~$mv ict-0.1.1.zip iota-ict<br>:~$cd iota-ict<br>~/iota-ict$ ls<br><strong>ict-0.1.1.zip</strong></pre><h4>Create the file ict.properties</h4><pre><strong>~/iota-ict</strong>$ vim ict.properties<br>port = 14265</pre><p>In order to save the one line you have edit in this file you need to use (:wq) in vim — you dont know how much i love this editor :-)</p><pre>~/iota-ict$ ls<br><strong>ict-0.1.1.zip</strong>  <strong>ict.properties</strong></pre><p>Your two files are prepared for execution</p><h4>Run java</h4><p>First thing in order to run java you need to get java.</p><p>You can get the<strong> J</strong>ava <strong>R</strong>untime <strong>E</strong>nviroment JRE (which needs approximatly 480MB of disk space)</p><pre>sudo apt-get update<br>sudo apt-get install default-jre</pre><p>Just a short check on what means default</p><pre>java -version<br><strong>openjdk version &quot;1.8.0_171&quot;<br>OpenJDK Runtime Environment (build 1.8.0_171-8u171-b11-1~deb9u1-b11)<br>OpenJDK 64-Bit Server VM (build 25.171-b11, mixed mode)</strong></pre><p>And finally start the program</p><pre>java -cp ict-0.1.1.zip cfb.ict.Ict ict.properties</pre><p>where -cp indicated the <strong>c</strong>lass<strong>p</strong>ath and we can find out more when</p><pre>$ java -help<br>java [-options] class [args...]<br>...<br>Where options include:<br> -cp &lt;class search path of directories and <strong>zip</strong>/jar files&gt;</pre><p>which means we specifing the main class in cfb.ict.Ict and hand over the main class the file ict.properties (where our UDP port is defined)</p><p>After correct execution you should see this</p><pre>[2018-06-29T11:36:58.620] Ict 0.1.1<br>2018-06-29T11:36:58.725<br>Number of transactions = 0<br>Number of missing transactions = 0</pre><p>The program is not terminated either is not printing anything else — lets go to the next step</p><p><strong>Tell 3–4 IRI neighbors your UDP/IP</strong></p><p><strong>U</strong>ser <strong>D</strong>atagram <strong>P</strong>rotocol UDP is the less known protocol for sending bit packets over the internet. As everyone has heard from TCP/IP which stands for “lets use the” <strong>T</strong>ransmission <strong>C</strong>ontrol <strong>P</strong>rotocol over the <strong>I</strong>nternet <strong>P</strong>rotocol less people would throw UDP/IP in the room. As far as i can remember UDP does not control much — means the recipient does not check back whether packages have been recieved or not — it basically throws all the error checking stuff out.</p><p>Back to CFBs task — break it down to</p><ul><li>what is my VPS IP known to the world?</li></ul><pre>$ curl ipecho.net/plain<br><strong>12.123.123.123 </strong></pre><ul><li>can someone else reach my IP via UDP on port 14265?</li></ul><p>We can check from outside the google cloud with following command</p><pre>nc -v -u -z -w 3 <strong>12.123.123.123</strong> 14265<br><strong>MySecondInstanceIP</strong> [<strong>12.123.123.123</strong>] 14265 (?) : Connection refused</pre><p>the command sends UDP packets to port 14265 of 12.123.123.123 and reports when after 3 seconds no ICMP packet recieved.</p><p>We need probably to add a rule to our firewall than. There is a VPC network tab in google cloud where you can add those rules to the existing ones</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/852/1*7dJNjsW42FmsIo6KTkg1Qg.png" /><figcaption>VPC network tab with the rule for allowing UDP traffic on port:14265 fow all IPs</figcaption></figure><p>This should work now after executing above rule and check again with netcat as outlined above</p><ul><li>Tell 3–7 IRI full nodes to add your IP</li></ul><p>First make sure you have started ICT again. You might want to run it in the background and log the output in a file (ict.log). In addition it should not stop once you exit the console or shutdown your laptop/pc (nohup)</p><pre>~/iota-ict$ <strong>nohup</strong> java -cp ict-0.1.1.zip cfb.ict.Ict ict.properties &gt; ~/<strong>ict.log 2&gt;&amp;1 &amp;</strong></pre><pre>[1] 27870</pre><p>Once this is executed get a Process ID PID (27814) and you can see the performance with</p><pre>$ top -p 27870</pre><p>Once you are opening ict.log as a “live-stream”</p><pre>~$ tail -f ict.log<br><strong>nohup: ignoring input<br>[2018-06-29T12:55:31.521] Ict 0.1.1<br>2018-06-29T12:55:31.626<br>Number of transactions = 0<br>Number of missing transactions = 0</strong></pre><p>there is not much happening until you have found IRI nodes adding you</p><p>This is the tricky part — you would need to join discord chat and ask in the dedicated ICT channel whether someone likes to add you. I finally managed to get three neighbors who added my IP and I would like to say thank you again for helping me out to figure out all those little traps.</p><p>Once they have added you successfully you will get</p><pre>Number of transactions = 114<br>Number of missing transactions = 1<br>2018-06-29T12:59:13.162<br>/<strong>IPaddressFromNode1</strong>:14600: 874 / 43 / 1 / 0 / 43<br>/<strong>IPaddressFromNode2</strong>:14600: 12 / 1 / 0 / 0 / 1<br>Number of transactions = 44<br>Number of missing transactions = 0</pre><p>Some people decompiled the class files in the zip folder and i followed — once decompiled there could be the following interpretation of the numbers. But this is guessing as I have not understood the code. Maybe next #ICT-2 article</p><pre>/<strong>IPaddressFromNode1</strong>:14600: 874 / 43 / 1 / 0 / 43</pre><blockquote>874 = numberOfAllTransactions</blockquote><blockquote>43 = numberOfNewTransactions</blockquote><blockquote>1 = numberOfInvalidTransactions</blockquote><blockquote>0 = numberOfRequestedTransactions</blockquote><blockquote>43 = numberOfSharedTransaction</blockquote><p><strong>EDIT 03.07.2018</strong>: Running on the f1-micro cloud instance will cost you money once your are out of the free trial time or quota.</p><p>With my ICT running two days with 4 neighbors i had 4.5 GiB outbound traffic from America to EMEA (which means the neighbors are in EMEA)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/587/1*JytOxnmHPnwHqouRaDnShQ.png" /><figcaption>Billing of google cloud account — 4.5 GB outbound</figcaption></figure><p><strong><em>Please make sure you switch of your instance if you dont use it anymore otherwise you will get charged.</em></strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/644/1*vusZLWnXQrdOtTFNf7K0Kw.png" /><figcaption>Incoming and outgoing traffic of ICT node</figcaption></figure><p>Lets assume average 50–60KB/s outgoing traffic which than equals 4–5GiB/day</p><pre>{50, 60}KB/s * 60s * 60min/h * 24h/day = <strong>{4.3, 5.2} GiB/day</strong></pre><p>Giving this i might have two neighbors in Americas (won’t charge) and two neighbors in EMEA (charge).</p><p>In this article we have executed the ICT java application on a f1-micro google cloud instance. We have not covered what what ICT is doing or what it is good for.</p><p>This is up for the next episodes of the exploring IOTA #ICT side exploration. Here I’d like to look through the decompiled code and understand what this pre alpha-release is actually doing. The emphasis is on trying — that might get a little embarrassing as I have very little java experience (maybe funny).. From there we can speculate what it might intent to solve or do for the IOTA, tangle and its vision — again at least i can try.</p><p>I’d love to see your questions doubts or corrections</p><p>Cheers, Jan</p><p>If you are interested in using IOTA and understand by exploring it you could start here:</p><p><a href="https://medium.com/coinmonks/exploring-iota-1-getting-a-linux-terminal-on-cloud-google-com-and-sending-a-transaction-d7b9f1ce100a">Exploring IOTA #1</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=bc3d96b246ea" width="1" height="1" alt=""><hr><p><a href="https://medium.com/coinmonks/exploring-iota-ict-1-running-ict-on-a-cloud-computer-bc3d96b246ea">Exploring IOTA #ICT-1, testing ICT on a cloud computer</a> was originally published in <a href="https://medium.com/coinmonks">Coinmonks</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Exploring IOTA #2, retrieve your transaction and create your “wallet”]]></title>
            <link>https://medium.com/coinmonks/exploring-iota-2-retrieve-your-transaction-and-create-your-wallet-bc8e8c91fec9?source=rss-14c8d196ddc0------2</link>
            <guid isPermaLink="false">https://medium.com/p/bc8e8c91fec9</guid>
            <category><![CDATA[tutorial]]></category>
            <category><![CDATA[wallet]]></category>
            <category><![CDATA[transactions]]></category>
            <category><![CDATA[iota]]></category>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Jan Bertrand]]></dc:creator>
            <pubDate>Sun, 24 Jun 2018 17:33:11 GMT</pubDate>
            <atom:updated>2020-01-28T15:14:33.258Z</atom:updated>
            <content:encoded><![CDATA[<h4>In this article I show you how to retrieve information from the tangle and clarify how you can prepare your very first own “wallet” / address with your own seed / “password”.</h4><p>In the last article (<a href="https://medium.com/coinmonks/exploring-iota-1-getting-a-linux-terminal-on-cloud-google-com-and-sending-a-transaction-d7b9f1ce100a">Exploring IOTA #1</a>) I have shown how to interact via node.js on a cloud Linux instance with the IOTA <strong>testnet</strong> (now called <strong>devnet</strong>). Last time we ended with sending zero value transaction to the devnet and were able to find this transaction via a tangle explorer.</p><p><a href="https://testnet.thetangle.org/transaction/CNBZCND9UXDHQPLCQXSFJNPM9AIKHTTAROWVMVBYSTGKKOCVEDQQMPKOMJCSB9VV9LCOAECKNY9LEB999">Testnet Transaction CNBZCND9UXDHQPLCQXSFJNPM9AIKHTTAROWVMVBYSTGKKOCVEDQQMPKOMJCSB9VV9LCOAECKNY9LEB999</a></p><p>In this chapter, we would like to retrieve the transaction we have send and in addition, change the code in order to</p><ul><li>create your <strong>seed (your password to your wallet — if you lose it you lose all your funds connect to this seed/password)</strong></li><li>create from your seed your addresses</li><li>get some test <strong>tokens </strong>(IOTAs)</li><li>send non-zero value transactions</li></ul><blockquote><a href="https://coincodecap.com/category/wallets">Discover and review best Crypto wallets</a></blockquote><h4>Messages, zero-value transactions, and snapshots</h4><p>If there is the one thing always mentioned about “blockchains” that they give you the assurance that the data in this ledger can not be tampered with.<br>This means our transaction which we have send (for me its a couple of days ago) should not have been changed.</p><p>That is true for IOTA as well but is only valid for <strong>messages</strong> within one snapshot. In order to reduce database size on the nodes (reference implementation on a server which participates in the IOTA ledger and which stores all transactions), the historical data gets pruned from time to time — in IOTA they call this a snapshot. In this step, just the correct balances on the addresses are retrieving consensus on the node network and all messages and zero value addresses are wiped out (at least this is my understanding of it).</p><p>This step assures that the local node database is reduced in size and the performance increase and the disc requirements reduce. But what happens to my immutable message I’ve transferred with my zero value transaction after a snapshot — its not anymore retrievable from the tangle.</p><p>There are concepts of permanodes around which finally could save all the historic information (or at least the information a company or and individual would need for all history — maybe we try to create such a permanode in the last chapter of this exploration), but I’ve not seen any service offered so far on the devnet. Don’t worry in our example we should be within one snapshot and be able to retrieve our message.</p><p>In addition, I think of IOTA as a protocol that enables immutable secure transmission/streaming of data for everyone/everything (permissionless ledger). You are able to send zero value transactions without fees and exchange value securely. Storing of data could be implemented in various ways as second or third layer protocols or as optional in the IOTA reference Implementation IRI.</p><p>For our article that means as well when you read this after a snapshot please use your bundle id, as mine is probably gone by then.</p><h4>Retrieving the transaction</h4><p>Back to coding again. The best way to find out which function we can use to retrieve the message is looking for the official <strong>github</strong> iota.lib.js repository.</p><p><a href="https://github.com/iotaledger/iota.lib.js#iotaapi">iotaledger/iota.lib.js</a></p><p>After scrolling through the README my eyes crossed this function — let&#39;s try to implement it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/890/1*ROM4noU06telZUc2DQWONw.png" /></figure><p>The easiest way to get your code always up to date and open to the community is by using git on the command line and publish your changed code to your github repro.</p><p>Here is a good first step for this:</p><p><a href="https://docs.gitlab.com/ee/gitlab-basics/start-using-git.html">Git on the command line | GitLab</a></p><pre>228  git clone <a href="https://github.com/jhab82/exploring-iota.git">https://github.com/jhab82/exploring-iota.git</a><br>240  cd exploring-iota/<br>243  vim recieve.js<br>242  git checkout master<br>245  git diff<br>246  git status<br>252  git commit -m &quot;bla bla done&quot;<br>254  git push origin</pre><p>This it the commands i’ve used to clone a project, change the recieve.js, checked the difference and the status and commit the changes finally pushed it to the master on github.</p><p>I’ve implemented the <em>findTransactions</em> function (above is the <em>findTransactionObjects</em> function introduced which acts as wrapper for this function) with passing only one bundle id. Nested in there I use the <em>getBundle</em> call to extract only the <em>signatureMessageFragment</em> from the Bundle (which holds our message).</p><p>Executing</p><blockquote>node recieve.js</blockquote><p>will give you the following:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/788/1*gwErpazd4wqvl9lcoceX0g.png" /></figure><p>The first line gives you the converted text messages from the raw trytes!</p><p>Wait a minute why do we need to slice this message…. I mean why do we need to reduce the whole bunch of 9 by one 9.</p><pre>message = success2[0].signatureMessageFragment;                                        <strong>message = message.split(&quot;9&quot;).join(&quot;&quot;);       </strong>                                 console.log(iota.utils.fromTrytes(message));</pre><p>If you don’t do it it will give you “null”. Never mind there is an issue reported here: <a href="https://github.com/iotaledger/iota.lib.js/issues/96">https://github.com/iotaledger/iota.lib.js/issues/96</a>.</p><p>The explanation is that <em>fromTrytes</em> needs an even number of values. I am sure you can normalize it nicer than split and join… If you execute the below you get <strong>null</strong>.</p><pre>message = success2[0].signatureMessageFragment;                                        <strong>     </strong>                                 console.log(iota.utils.fromTrytes(message));</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/772/1*_MWR9DOfEMs2E8mhghy5BQ.png" /></figure><p>They might change that in future implementations and throw an error if the amount of trytes is not able to be passed by <em>fromTrytes</em>.</p><h4>Creating your own seed</h4><p>If there is one thing you should take care about if you are in crypto/blockchain take your privatekeys, seeds, passwords seriously private!</p><p>You are now your own bank — there is no person or group which acts as a link between you and safe ground — you are responsible.</p><p>This is why you should never use any seed generators without understanding why and what and how.</p><p>For our purpose we just can stick to good old chap Linux for generating us a nice little acceptable seed which should be 81 characters long should only have capital letters and the number 9 — please in a random fashion…</p><pre><strong>cat /dev/urandom |tr -dc A-Z9|head -c${1:-81}</strong></pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/734/1*qnZKUH3547OR1uV4DBpxTQ.png" /></figure><p>you might think what is wrong with Jan? he just told me I should never expose it and he almost fu** … paste it here…</p><p>Yeah i did not (the last letter are covered with a thick red paint though) but if you like to try — here is the challenge: Whoever get access to my devnet tokens on this wallet (how to get devnet tokens i will show you later) will get a special award. Its just guessing about 9–10 characters or you might want to brute force it.</p><p>The best learning here would be if you can understand that exposing your seed is crazy and that even with only 9–10 letter left its hard to guess your seed but not impossible. If you think you could just guess the 81 character please watch this</p><p>and just to make it more easy here is the part of the exposed seed for copy and paste (without 9–10 chars)</p><pre><strong>BIOBBXLOWLVSIBNAORH9VDZCQO9GUYAYCLDUY9W9UKSUCPONSSBPUCDAUUEOZIUXSBTEC9RI</strong></pre><p>So if you crack the last letter you could control the wallet (as this is on the devnet — you won’t get rich anyways)</p><p>We should really repeat all the stuff we have done prior and in the first article again to understand what is a seed ~ wallet. An address ~ temporary storage of information / value and how i can get tokens…</p><p>For now we are just changing our transfer function to be used with our seed and send again a zero value transaction:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/721/1*zB_tAnADTqT9P_Tzln1iGA.png" /></figure><p>This will give us when executed</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/784/1*uyBl5bnRWoxC-nCxK1MOsA.png" /></figure><p><strong>Troubleshoot: </strong>As I’ve experienced problems with the remote PoW please just do the above code without the following two lines (in order to leave the PoW executed by the node rather than the powbox)</p><pre>//const remoteCurl = require(&quot;@iota/curl-remote&quot;)<br>//remoteCurl(https://medium.com/iota,%20&quot;https://powbox.testnet.iota.org&quot;,%20500)</pre><p>Ok that means we have send from our seed (which is now private) a zero value transaction over the test net to the very popular address HELLOWORLDHELLOWORLD….</p><p>But what happens if i send a non-zero value transaction (I want to send devnet tokens to this address) — well than you need to have tokens send to your address first.</p><h4>Create your first own address</h4><p>Lets do it than. Create an address where only you — the seed holder has control of.</p><p>Just create a new little file and name it e.g. genNewAdress.js and copy your seed as const and the command as shown below</p><pre>const seed = &quot;<strong><em>PasteYourSeedHere</em></strong>&quot;</pre><pre>iota.api.getNewAddress (seed,  (error, success) =&gt; {<br>        if(error){<br>                console.log(error)<br>        }else {<br>                console.log(success)<br>        }<br>})</pre><p>After executing it you will get something similar (Your address is unique and obviously looks different than mine)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/693/1*KUGaZPNmasHD3r6zzmDTjg.png" /></figure><pre>FBTICMZPRTLDFYZZSMBABZTBULMWZVRKZPXTFJEIOPUJLFQDIOPWHKCXKIBPYBGXBSHZIBRYUBMYCRGHA</pre><p>The special thing about this address is that it belongs to me and only I am able to send value from this address to another address using my seed.</p><h4>Get your devnet tokens</h4><p>So lets get devnet tokens here:</p><p><a href="https://faucet.testnet.iota.org/">Welcome to IOTA Faucet</a></p><p>I just paste my freshly created address in this little app and i get an ETA for receiving my tokens</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/745/1*zGy3XnuB4D1S0CBa2VTipg.png" /></figure><p>Cool — I should have tokens but i don’t know hot to check them. Come on lets check via command line our balance.</p><h4>Get your addresses balances</h4><p>You could probably only have a look at that particular address but exploring IOTA further will show us that every time i spend form this address all remaining funds will be transferred to the next address generated from this seed. That means we would like to get the balance from all existing addresses created by this seed.</p><p>I have done this by nesting the getBalance command into the getNewAddress command <strong><em>(i’ve changed the operator =&gt; to include the function expression for better visibility)</em></strong></p><pre>const seed = &quot;....&quot;</pre><pre>var addresses = new Set()<br>var allAddresses</pre><pre>iota.api.getNewAddress(seed, {&#39;returnAll&#39;:true}, function(error, allAddresses) {<br>        if(error) {<br>                console.log(error)<br>        } else {<br>                allAddresses.forEach(function(addr) { addresses.add(addr)})<br>                console.log(allAddresse)<br>                iota.api.getBalances(allAddresses, 10, function(error, success) {<br>                        if(error) {<br>                                console.log(error)<br>                        }else {<br>                                console.log(success)<br>                     }<br>                })<br>        }<br>})</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/693/1*J4JrYzW2E3U8p4MIJFPSUg.png" /></figure><p>Congratulation you have received 1000 IOTA!</p><h4>Send a non-zero value transaction</h4><p>Now we could send to the popular Address “HELLOWORL…” some IOTAs — just because we can. Just copy the send.js and create a send_fromWallet.js script with your seed and changing the value from 0i to 1i.</p><pre>const seed = &quot;<strong>PasteYourSeedHere</strong>&quot;<br>const message = iota.utils.toTrytes(&quot;I will send you 1i for just because i can....&quot;)</pre><pre>address = &quot;HELLOWORLDHELLOWORLDHELLOWORLDHELLOWORLDHELLOWORLDHELLOWORLDHELLOWORLDHELLOWORLDD&quot;</pre><pre>const transfers = [{<br>                         <strong>   value: 1,</strong><br>                            address: address,<br>                            message: message<br>                  }]</pre><pre>iota.api.sendTransfer(seed, 3, 9, transfers, (error, success) =&gt; {<br>            if (error) {<br>                            console.log(error)<br>                        } else {<br>                                        console.log(success)<br>                                    }<br>})</pre><p>After executing this script you will receive a lot of information:</p><pre>[ { hash: &#39;GIXQQGFCBHMHXFSG9ABJKXHB9ZZALWGEYLWFRULFFBOSBFXFNJJQYPHPHJ9ONQMKEDNUJTTHEZSEPE999&#39;,<br>    signatureMessageFragment: &#39;SBEAKDXC9D9DEAGDTCBDSCEAMDCDIDEAVAXCEAUCCDFDEAYCIDGDHDEAQCTCRCPCIDGDTCEAXCEARCPCBDSASASASA999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999&#39;,<br>    address: &#39;HELLOWORLDHELLOWORLDHELLOWORLDHELLOWORLDHELLOWORLDHELLOWORLDHELLOWORLDHELLOWORLDD&#39;,<br>    value: 1,<br>    obsoleteTag: &#39;LG9999999999999999999999999&#39;,<br>    timestamp: 1529851449,<br>    currentIndex: 0,<br>    lastIndex: 3,<br>    bundle: &#39;AIYWAEBHLFZYDYO9KULNOSRBCZSDYJVIYHTXCFVDEOGSRFJESGLEZVJXYOSYKJENFUVBOAZGHGJHYREBY&#39;,<br>    trunkTransaction: &#39;HJLAJVBGJCCC9XRMLYOIJTPLBOELQMS9LMYGFYR9XDNWHUZYQDCZIQGNIFVXEMRBMCLEXVGKCXSUYV999&#39;,<br>    branchTransaction: &#39;SAAGHDVRNZFGBUNKUCPAW9UYZKSZBKYEWVBTGGOQMPWTOPSMWIWIEQXHFGN9WLEIDUAVQB9E9ECO99999&#39;,<br>    tag: &#39;LG9999999999999999999999999&#39;,<br>    attachmentTimestamp: 1529851456551,<br>    attachmentTimestampLowerBound: 0,<br>    attachmentTimestampUpperBound: 3812798742493,<br>    nonce: &#39;EMDIGCYYFVNXFJMWXPOMDWRUCCE&#39; },<br>  { hash: &#39;HJLAJVBGJCCC9XRMLYOIJTPLBOELQMS9LMYGFYR9XDNWHUZYQDCZIQGNIFVXEMRBMCLEXVGKCXSUYV999&#39;,<br>    signatureMessageFragment: &#39;XOFC99XBKNCJXFNLIHWBELHVHEWZPHYQ9PSMRNJKLUQE9KTPHDKPPZCDJ9IUTBANQIKFKQYREIKRBCVHYSBRAVOXZSZNOEBIBUEBDIIVYCHYXNWFALAFFZ9NCVZMIZDBRDQIHWJWSGIDCOGIX9XEBJLGJMGMLVVX9A9AMJDPENVBGFQUENEJUAEPJEKGTKVWVITGMWSDJZZSOBEEEXQLGMW9VGCYNYBCVHASOMNPFEEZ9RMFGBXNAXMESQLNVWTKYLTQBOKZZRWGDZMS9OWKJEVXNYJGXKLEHVHJQHLQKGJQBJRETKNPLQIHZLMGDAGPSEGWSYKLWKMWZXNZIDZISEYCDFTHDMTRMKY9X9FOAWNBKZNMVRMXZYVGHELCSENGSPZVVJVZLPPGCJWOBNEZDJPFYJXVDRGNOVAWHXQBAEGKENTDXVTNEGOVLKQXOCNQINCSYMVLEYRA9KZDGWUSOJLUYPHEAASGOZEXAWCNVFBGBAUSIXNKHITQWJSPLIMGUZEFNHHSBG99C9SKEMAYHRROWVFKBZTOUZFYBASHVQSXXIAJCBIKPRDGXSMZOIYCF9DNYCSSHWEXWHVAPRFLAFTJDDAHAHQIADDKEIARGR9VTK9FBNWLITPRQYQQKTAYHVFOXV9DVKLGZRNEKOOXDABDMYZRMXVTRTOHBDZZNFMGQOVIASMILNMTBYBHDUHCIFIHREI9GCEFAAFFSOLBTWFXZ9AMEOYFUREX9RBAWDBRJZLZVVBMHRZUJKQKNPT9LEEOLVVD9TLF9GVRDPYURGRVNDMRRDTVYCBDSBP9UBLBDHBZUAHUBUMSSBXSTKCBLXLKPDCAONYITBFECEMPXJVQRXNTBPKFOCFDMMGLNNERPX9BSVLWUN9PO9WOORMUEI9GLMUBERAFMND9VJIMDGAOAWUCQUTRDBEZKWLDJFXWBSEDQSDLPNJNDOTDFSUMVHMADSXMVZWCBPFASEOLOWYHUEIHWSEZ9RIKWEPCOQJZMZEECHKLTZCTUDMWOO9ALYKVYYVXQAQFZRCD9LGVAWUEJDF9ZPWUDJHQHEEVJGPESMIGEAWMRGS9OWTJHORIQJVSRNIKTJWIQRALGSKMXKGGKYJKPJGUQPMAVLHRLESZYDKUVQYRLWGR9LRNL9TUQWYEHDWGLJUBATGJRVHFLOKMZEYXIHAYJJMEMOQGCOFSPKYGVQPHSCMFCVDGSJXB9RIGXPCRONJWFZVJ9SHURDAGZHOWASTAHBUDZORPHMNFBVGYVEDRSWVVPKEJJTJAKVWVTXLRQYNNQO9WSLJSJLQNUNIJDN9YFJ9FAEAAECXXKEZEQFLZJLUAN9ESAIBNJFJDBQWONAFBMUJJBLJZLKTOS9GZZVFGXDTOQLYQVQPJ9XNCWAWAQATQZBEAZSTNN9YIYOEPMFQEKNKWYZJRLBBSQTQFVRWYWNGYVYSGQWCVYPFEOWMUZN9KJFQTKNIACQUVRCIGDXZ9YEYZDISDHCZGXPZWW9GHTNANGDZISFAYZKEY9TDCJNCWBBC9ARXOVTXNRGCH9HEU9T9XZQHULGAFPMWGNM9ORSLKSHRGTUCSUXCPIGIJLKYVARPQYTQXTXE9PSXTVDSLLDBLYGH9NB9CUSPAPL9PP9UDOYMOUKGGYHBKQGUPKPBUNSXDTVPSLGEPYAQKA99SIV9KJXMYHCOUPOSQHUKNTVDPDJBNWSKSURQCZRLZCVHBPKVNXVYMHZRWMPWTA9RQACNOSATNEMGKJWXITWZJJLLHUBN9ZMNDSMWOHG9ZECEPUSOZLVGMGPWJCJDKKTHTSONIUGISFHY99NGNAOYWQO9KOCHJDAWAGWP9TRASYYSQWDLTDIJMOVACUV9CUZYDNXSBNJGDYOVHAIJZMLKHFWHXRFRUTCWDJKYHYORLYSN9VRSTLJVWKWB9LANRDFYZZJKSFKF9IQFWPRJWDKGEJALFXLS9ISCSMVYLMXCVNLESVJAGXUBMOLXQZGPR9IACTCJROR9ANHKBHMJGOMTR9SFJYXOJWIMRISIEHSFAPTEXNOOJDOAVCCNMWLKQE9DDBZVFOXCBPYOV9CGNPRTAHXWQZ9MWVWTERZ9ZKTOEXLAPPWBDQVTBIKTXRKWK9FRDEYXLHUKKIP9TEMJFZ9PG9GXUUNALJQJQNSLOSG9BLPMF9RLXCCCOPCBKAZO9GYW&#39;,<br>    address: &#39;FBTICMZPRTLDFYZZSMBABZTBULMWZVRKZPXTFJEIOPUJLFQDIOPWHKCXKIBPYBGXBSHZIBRYUBMYCRGHA&#39;,<br>    value: -1000,<br>    obsoleteTag: &#39;999999999999999999999999999&#39;,<br>    timestamp: 1529851453,<br>    currentIndex: 1,<br>    lastIndex: 3,<br>    bundle: &#39;AIYWAEBHLFZYDYO9KULNOSRBCZSDYJVIYHTXCFVDEOGSRFJESGLEZVJXYOSYKJENFUVBOAZGHGJHYREBY&#39;,<br>    trunkTransaction: &#39;GKNBKDZM9XOEEDYWHLFLYGTW9YCEWQFZGC9FWRTRRLIBIBADFSITNOZAQBWKG9OTTJOKGNSQLJHVMZ999&#39;,<br>    branchTransaction: &#39;SAAGHDVRNZFGBUNKUCPAW9UYZKSZBKYEWVBTGGOQMPWTOPSMWIWIEQXHFGN9WLEIDUAVQB9E9ECO99999&#39;,<br>    tag: &#39;999999999999999999999999999&#39;,<br>    attachmentTimestamp: 1529851456539,<br>    attachmentTimestampLowerBound: 0,<br>    attachmentTimestampUpperBound: 3812798742493,<br>    nonce: &#39;SFDLLPLZQ9GVBGPFHKVBCHPZ9W9&#39; },<br>  { hash: &#39;GKNBKDZM9XOEEDYWHLFLYGTW9YCEWQFZGC9FWRTRRLIBIBADFSITNOZAQBWKG9OTTJOKGNSQLJHVMZ999&#39;,<br>    signatureMessageFragment: &#39;DMYOLFZUNASYKIVELBBALIJWLITJTTAHPAGKCHMQNGWENOYWESBIMLRMKEHRCWWZCREVIYKTCDWBZYVKXZKXLZUCIAE9KNZMISVDLHEVSMKCAVUJ9ABTM9TQZXKPMRNRL9WLHPMHCFBPBHDPEQ9RANDVPAWPPFIWOYJAETGDCTYDSLDBYTB9BAS9GDPBWRHLQNGLJFFOJGJPFYNGFDAJVKVMVZXQSL9XCWUVZMKYIRKGQBBCQUWZNDWGBIMYHHIU9DMLH9STGQLGSANRYDOAAHLVLUBHEWOS9YDANVSIIXNCADJMWEZLDYNZLHTQ9CSBPZWWUBKGZIARYOHUHKKOEALUDJTBMZAWYMLSCBIASZUFHBRDLDCSSMAANAGNKUFEMYQLJCZDJQXHZGDTRKETCVJF9UACUZPUNBCZPGRPMUEVPNCUAMTTGWTAC9MXPSMESRFFRYOBOU9IXOLJCXHGOHUHLKIEDRJIXSFFSXAWGAZ9Z9HAKVXWMNMPAWOUALDOSGNHCPBSAGLWSBLSMJDFZJOMPQDWNJXXROJQYWYQAPMTZYDVCKBOFI9UMAZUCBUAOYRYCKPZZTNIVC9QLHZRLWYAMIUMSUIZQZUBQRVZQXBWC9QNDUIUGV9YEZRJXKJSJNOB9NGZLFDEOJ9WGOC9N9CNJBSHCPXNCGNMUPWUWSVD9CNFTHKCRIIBXYVIPQSIYYGCXZOHWCWNUJXXUMNSXTGE9NSXTIHAHNWAPIVE9BDELWOTLLJHAACOEBCWMNQPQD9W9BNQFETNRCZPMUGUSIVSXJTONUUAUYHNAYHDVX9SJMPOUDG9FLZ9RUPFXROSQCLDWSUKCHHNZPKGPPZTMDDOKMP9QESVLTDMUNFGCRARGYIJAREEFOCUNT9ISAVMLRUACRMETNRXRK9OQALVETPSOCBWZRTMJCTEHQQ9OYTQUMEN9NGDHOGPXAP9DFTACICAPFUYEZNXQOKDBUDYRLNIFFDKKCWAHQBJLJ9ZRJXWZD99DLOCEVOPXP9QIKJRVCVVDHSOKEDTRUMPETUHIFIRAESLBR9CYCRTQHWHC9GIMJQ9NMSAGBFHWFKWUDLJLWUPVKYOSLEEWLFBPMEMBLEEYLYMYQUYZUYNCRRDITMFGBRCTGWCPWDNDAFXXAEYKDDBYVQHNCFWCOLWCGUOESFRBFQVPYKQ9TLAUFTEASHGLWORCFJZZBXIMVFVVHDJJCAHQWKMMWDNHDVCZXSLBMPXSPTZIZPNZCSDEHXNFAOY9HOWCUXEEKRSI9DUGOGYEUPSXTLT9WILQENYDOKKAMELMESWOUNBCFFBOGEZXKCGZZSPFCARQRNFBXOPAJQIISJLJSSKLJLWDAYIUWNSAJQEAYQOTW9ADV9TUHULTQHAYBOFEADTAFPHBSCESQDON9I99JFALZMOARKQYTNICNJKDLWZXORODSKJOZZFLSYGFXIMOZRXDUHPOCSTPNW9VBMSSKJQXMLQIXHSYJITC9ISEBSCUWKO99BQQUTPDMIEKGUVXIIHBOVQLGGHSDVBYDDEBCWBRYGNARRFYSWK9EEKLRIICHKFNSCRASANBIAHXDMVPPWMWXXNWLQZIPBEDYRDOHIGH9DZYIEPQTLZCRENBRXPZWEAXQHIEJTKHKXBLEBCOV9RLWRSUSPYIWINYDDTWWJXRERDTYPVEEXSUZWOGCO9IEDCZIWRBLNEPLWSPZNEMGTEYQLVKKJYMQDMSPHUFLUWBZZDMPXXLHNZH9ZGFZUXJXQWJYNXKJSSMHUNEQLFAVUNRXOJRRHGRBMZUSURCJERGEIRVZLUJVUURGXYAYQHSOCNPSSCHXNJGRRAKRMO9DZVHDKYORNZXWQVBQWXATDMWJDVBEP9COVCGJRTQLMXEXYBOKPVXUYUIWLKA9CWFFSFHXQXNXCJKGXGFYHTJFIAIMMLBY9OHUZAYXCCSSUQBL9PRXUCBQMQWDAJHFPWMG9UQNZAWEMKCUMSHIXXHRFCASPIPBW9HVPVNPSIJ9QJXKIRGKYQWLYEDHOZNEYUAJACHEX9MDWKDZJPDDSIGAFALGBPQYHSMDBVGSUUMHXFBDVDRSOMINLGMETXWQBVJVKBWPZEHWRFCU9MYMDAWAOHRQXIZFAMYOXO99MSTEOQSEBPNNMBFWKGLHWVLGIBIL9O9EVTJRLWBDQHQQCVIEYUZ9D&#39;,<br>    address: &#39;FBTICMZPRTLDFYZZSMBABZTBULMWZVRKZPXTFJEIOPUJLFQDIOPWHKCXKIBPYBGXBSHZIBRYUBMYCRGHA&#39;,<br>    value: 0,<br>    obsoleteTag: &#39;999999999999999999999999999&#39;,<br>    timestamp: 1529851453,<br>    currentIndex: 2,<br>    lastIndex: 3,<br>    bundle: &#39;AIYWAEBHLFZYDYO9KULNOSRBCZSDYJVIYHTXCFVDEOGSRFJESGLEZVJXYOSYKJENFUVBOAZGHGJHYREBY&#39;,<br>    trunkTransaction: &#39;VMJL9UVXBAPERHWIVGOMPNEHJBCTL9ABSGSMEKXCHNUW9NRAFSIVCKJFWXUDBFOMNQJHQEWZPPDRRG999&#39;,<br>    branchTransaction: &#39;SAAGHDVRNZFGBUNKUCPAW9UYZKSZBKYEWVBTGGOQMPWTOPSMWIWIEQXHFGN9WLEIDUAVQB9E9ECO99999&#39;,<br>    tag: &#39;999999999999999999999999999&#39;,<br>    attachmentTimestamp: 1529851456532,<br>    attachmentTimestampLowerBound: 0,<br>    attachmentTimestampUpperBound: 3812798742493,<br>    nonce: &#39;DFLBUPZRIRIBODBQ9RKGIEANSBH&#39; },<br>  { hash: &#39;VMJL9UVXBAPERHWIVGOMPNEHJBCTL9ABSGSMEKXCHNUW9NRAFSIVCKJFWXUDBFOMNQJHQEWZPPDRRG999&#39;,<br>    signatureMessageFragment: &#39;999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999&#39;,<br>    address: &#39;QWQLOWHRQCBFJTNVPKMHBISERXKEIFAQQIEFURQPQOXUMMXQIAHBYTT9LWEILYCTROE9FMCDZPFAZDGNZ&#39;,<br>    value: 999,<br>    obsoleteTag: &#39;999999999999999999999999999&#39;,<br>    timestamp: 1529851455,<br>    currentIndex: 3,<br>    lastIndex: 3,<br>    bundle: &#39;AIYWAEBHLFZYDYO9KULNOSRBCZSDYJVIYHTXCFVDEOGSRFJESGLEZVJXYOSYKJENFUVBOAZGHGJHYREBY&#39;,<br>    trunkTransaction: &#39;SAAGHDVRNZFGBUNKUCPAW9UYZKSZBKYEWVBTGGOQMPWTOPSMWIWIEQXHFGN9WLEIDUAVQB9E9ECO99999&#39;,<br>    branchTransaction: &#39;SAAGHDVRNZFGBUNKUCPAW9UYZKSZBKYEWVBTGGOQMPWTOPSMWIWIEQXHFGN9WLEIDUAVQB9E9ECO99999&#39;,<br>    tag: &#39;999999999999999999999999999&#39;,<br>    attachmentTimestamp: 1529851456523,<br>    attachmentTimestampLowerBound: 0,<br>    attachmentTimestampUpperBound: 3812798742493,<br>    nonce: &#39;OIFJOUHQAYDBO9ZGCHATJUZ9CQM&#39; } ]</pre><p>Lets first make sure the one 1i is deducted from our Address, by executing our showBalances.js</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/714/1*Yb6XXN93k7odRBwtphJSiw.png" /></figure><p>Looks fine. Next we can use the tangle explorer to check whether our 1i has been received by this Address.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/567/1*pp6RsE1UAF8i-m3SBvuliQ.png" /></figure><p>Congratulation! You have now</p><ul><li>your address with 1000 devnet IOTAs.</li><li>You have executed a token transaction and</li><li>you know now how to retrieve transaction information.</li><li>Most importantly you know what could happen when you expose your seed.</li></ul><p>In the next article I would like to show you what happened in the background when we transferred our 1i to the “HELLOWORLD…” address. I would like to explore a little more on the possible commands from the iota.lib.js repository and motivate some use cases.</p><p>Please get back to me if you struggle, have recommendation or just like to change something.</p><p>Cheers,<br>Jan</p><p>First article in this series: <a href="https://medium.com/coinmonks/exploring-iota-1-getting-a-linux-terminal-on-cloud-google-com-and-sending-a-transaction-d7b9f1ce100a">Exploring IOTA #1</a></p><p>Troubleshooting:</p><ul><li>Disable remote Proof of Work (PoW) by commenting the remoteCurl part in our script</li><li>IOTA changed the testnet to be deprecated and renamed it to devnet. Please change your node server</li></ul><pre><a href="https://nodes.testnet.iota.org/">https://nodes.<strong>dev</strong>net.iota.org:443</a></pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=bc8e8c91fec9" width="1" height="1" alt=""><hr><p><a href="https://medium.com/coinmonks/exploring-iota-2-retrieve-your-transaction-and-create-your-wallet-bc8e8c91fec9">Exploring IOTA #2, retrieve your transaction and create your “wallet”</a> was originally published in <a href="https://medium.com/coinmonks">Coinmonks</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>