Writing Content to Zesty.io using a Raspberry Pi

This guide will walk you through how to write to a Zesty.io consuming data from an external data source: in this case, a Raspberry Pi.

Writing Content to Zesty.io using a Raspberry Pi

Wei-En Wong 11.12.2019

This past week at our monthly Meetup, we talked about automating content submission and publishing to a Zesty.io instance.

To demonstrate this, we used a Raspberry Pi - a $35 computer the size of a business of a business card that is powered using a smartphone charger. The Raspberry Pi also runs a fully-featured Linux distribution, which includes a variety of intuitive and easy-to-use graphical user interfaces.

For the Meetup, I wrote an app using Node.js that will automatically write data to a headless content model periodically (code can be found here), which is then graphed using Chart.js. The finished product can be found here: https://meetupdemo.zesty.dev/.

I wrote the app using Node.js because Zesty provides an SDK written in Node.js (npm package can be found here). However, you can easily accomplish the same task using languages like Python, Ruby, Java or even a Bash script - using our REST API.

For process management goes, I used pm2 to run our Node.js application in the background.

Let’s dive into some code:

Let’s start with this.

Here we are loading our environment variables from .env file and initializing our SDK.

I have also implemented a function to perform scheduled publishing of our data points, using our REST API.

In my example, I set the publishAt field to now, telling the API I wish to publish the content item now. However - the publishAt value can be set to a specified time value. This also demonstrates how one would go about implementing a call to our REST API using an HTTP client library.

Finally, we are using setInterval() to create and publish a new headless data entry every 5 seconds. setInterval() takes in two parameters: a callback function and an interval value in milliseconds. The data entry contains a numeric field called moisture, which our graph is using to plot data points.

And that’s it! Easy as pie… Raspberry Pi, that is.

Experience a Headless Content Management System, Join Zesty.io.

Start a Sandbox Now

More from Mindshare: Developer How-Tos

Placeholder image

Writing Content to Zesty.io using a Raspberry Pi

This guide will walk you through how to write to a Zesty.io consuming data from an external data source: in

Read Article
Placeholder image

How To Write Google Cloud Functions with Python 3

This is my third and final article looking at new features in Google Cloud functions as Google starts to narrow

Read Article
Placeholder image

How to Build a Blog in Zesty.io

Building a blog from start to finish takes less than 10 minutes in Zesty.io! Here's how to get started.

Read Article
Placeholder image

How to Personalize Content on your Website using Your CRM

Personalizing content delivery on a site can be tricky. Deciding your data flow and what data you're going to use

Read Article
Wei-En Wong photo

Wei-En Wong

Software Engineer, Zesty.io

I'm a software engineer who likes to tinker. Backend engineer at Zesty.io. Graduated from University of Waterloo with a degree in Computer Science in 2016.... Learn More

Exploring content solutions? Looking to replatform?