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

Fighting Submission Bots with Honeypot Fields

Adding a captcha isn’t always the best idea because it can kill conversions; that's where honeypot comes in.

Read Article
Placeholder image

How to Build a Microsite in One Day

Microsites rose to prominence due to the growing complexities of promoting a corporate website for marketing purposes.

Read Article
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

Using Zesty.io Headless CMS with React

A step-by-step guide for using Zesty.io as a headless CMS paired with a React front end.

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

Speak with an Expert


Chat with Us

To speak with someone in sales and marketing, use the chat popup on this page. To speak with a developer, join https://chat.zesty.io

Exploring content solutions? Looking to replatform?