DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports Events Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
Zones
Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Partner Zones AWS Cloud
by AWS Developer Relations
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Partner Zones
AWS Cloud
by AWS Developer Relations

Trending

  • Integrate Cucumber in Playwright With Java
  • Top Six React Development Tools
  • Managing Data Residency, the Demo
  • Decoding eBPF Observability: How eBPF Transforms Observability as We Know It

Trending

  • Integrate Cucumber in Playwright With Java
  • Top Six React Development Tools
  • Managing Data Residency, the Demo
  • Decoding eBPF Observability: How eBPF Transforms Observability as We Know It
  1. DZone
  2. Data Engineering
  3. Big Data
  4. Chuck Norris and the Internet of Things

Chuck Norris and the Internet of Things

Jim O' Neil user avatar by
Jim O' Neil
·
Mar. 19, 15 · Interview
Like (0)
Save
Tweet
Share
2.87K Views

Join the DZone community and get the full member experience.

Join For Free

In my last post I covered my experiences setting up the Intel Edison board and interfacing with the LCD and temperature sensor, but ran into a #fail when trying to make a REST call on site at the Intel IoT Roadshow in Somerville.

The issue was certainly network related and site-specific – a redirection to what would probably have been a network credentials dialog – but it wasn’t happening to everyone.  My resolution then was to call it a day and give it a shot at home… where it just worked.

Chuck NorrisIt occurred to me though that getting the current temperature from a web service was booooring, so rather than show you that, I opted to build the first ever (?) Chuck Norris IoT device!

ICNdb

These days there’s an API for everything, and who’d dare deny Mr. Norris his spot in the cloud! Yes indeed, there is an API targeting – what else – theInternet Chuck Norris Database. It’s a simple RESTful API that requires no registration or API keys making it quite easy to access. For instance, in your browser just navigate to

http://api.icndb.com/jokes/random?exclude=[explicit]

and you should get back a bit of JSON that includes a short joke. Feel free to leave off the query parameter if you’re ok with potentially NSFW material being returned.

Invoking the API in Node.js

Node junkies know this stuff like the back of their hand, but I had to reacclimate myself to the purely async nature of the execution flow. Basically, you provide the URL you want to fetch and then a callback routine that processes once the request has completed.. like:

  • linifyJoke takes the joke string and divides it into an array of strings that are no more than 16 characters each to facilitate display on the LCD.
  • outputLines takes that array and the current line to be output and successively writes the lines to the LCD with a delay so you can read through the joke.

There’s nothing magical about that code (and I covered writing to the LCD in my last post), but if you want to view all the gory detail, I’ve included the entire script in this gist.

On-demand Joke

Once you’ve heard one Chuck Norris joke, you’ll find you can’t get enough of them, so I realized I need to beef up my implementation to allow you to request joke after joke.

Enter the button sensor from the Grove Starter Kit. The button returns a high voltage (1) when pressed and low (0) when released, so getting the button state is a simple read from the GPIO context that’s exposed by the mraa interface.

You’ll need to continuously poll for the press though, and when pressed carried out the desired action – perhaps ignoring, as I do, subsequent presses until the current request is complete.

Here, processingRequest is a sentinel value that prevents reentry to showJoke, with the outputLinesmethod mentioned earlier having the responsibility for resetting the flag once the current joke has finished displaying.

http://codocent.com/wp-content/uploads/2015/03/WP_20150316_20_03_40_Pro1.mp4?_=1

This is not Vaporware!

IoT ChucK Internet (web browser)

Published at DZone with permission of Jim O' Neil, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

Trending

  • Integrate Cucumber in Playwright With Java
  • Top Six React Development Tools
  • Managing Data Residency, the Demo
  • Decoding eBPF Observability: How eBPF Transforms Observability as We Know It

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com

Let's be friends: