Reader small image

You're reading from  Mastering Internet of Things

Product typeBook
Published inMar 2018
PublisherPackt
ISBN-139781788397483
Edition1st Edition
Right arrow
Author (1)
Peter Waher
Peter Waher
author image
Peter Waher

Peter Waher is the founder of Little Sister®, a standards-based distributed social network, based on the principles of edge computing, privacy & information ownership, for humans and machines. Currently, Peter advises companies on topics such as privacy, the IoT and Smart Cities. He has worked for 24 years with computers and device communication, including low-level development in assembler for resource-constrained devices to high-level system design and architecture. His award-winning applications has attracted global attention, and he has been invited to speak at prestigious events.
Read more about Peter Waher

Right arrow

Publishing sensor data


Now that we have a live connection, we're ready to publish sampled sensor data. We will first need some member variables. These will store last values, last-published values, and the timestamps of last-published values:

private double? lastLight = null; 
private bool? lastMotion = null; 
private double? lastPublishedLight = null; 
private bool? lastPublishedMotion = null; 
private DateTimelastLightPublishTime = DateTime.MinValue; 
private DateTimelastMotionPublishTime = DateTime.MinValue; 

From our sampling and event methods where we receive and calculate our most recent sensor data, we call two new methods: PublishLight() and PublishMotion(). To illustrate different ways of publishing data, these two methods will publish the corresponding sensor data fields on individual topics, as strings. They will then individually call PublishLastJson(), which will publish both fields on one topic, as a JSON object string.

Choosing relevant values

Before we publish the data, we need...

lock icon
The rest of the page is locked
Previous PageNext Page
You have been reading a chapter from
Mastering Internet of Things
Published in: Mar 2018Publisher: PacktISBN-13: 9781788397483

Author (1)

author image
Peter Waher

Peter Waher is the founder of Little Sister®, a standards-based distributed social network, based on the principles of edge computing, privacy & information ownership, for humans and machines. Currently, Peter advises companies on topics such as privacy, the IoT and Smart Cities. He has worked for 24 years with computers and device communication, including low-level development in assembler for resource-constrained devices to high-level system design and architecture. His award-winning applications has attracted global attention, and he has been invited to speak at prestigious events.
Read more about Peter Waher