Skip to content
gtfierro edited this page Sep 13, 2014 · 8 revisions

Note: this feature is currently only supported on the unitoftime branch

##How Scheduling Works in sMAP

The sMAP scheduler service takes advantage of sMAP's publish-subscribe functionality to "advertise" a schedule that other sMAP sources can choose to listen to. Schedules are defined as a set of values to be published at a certain time, e.g. "set the heating setpoint to 60 at 8:00 AM." These declarations are advertised on the advent of the epoch, and are not reasserted by the scheduler service. This allows for other service and user overrides.

The scheduler service attaches metadata tags to the values it publishes. These tags are drawn from a known ontology, so sMAP sources can execute a metadata query on those tags to discover the scheduler; this removes the need for every sMAP source to know exactly where the scheduler is. If a sMAP source wishes to be scheduled, it subscribes to a stream of setpoints. When the scheduler notes that there is an epoch change, it publishes the new setpoints, and the sMAP archiver pushes those new setpoints to any sMAP source that is listening.

##Defining a Schedule

Schedules are defined as a simple JSON object:

{
  "name" : "weekend",
  "periods" : [
          {
                  "name" : "morning",
                  "start" : "09:30",
                  "points" : [
                          {
                                  "path" : "temp_heat",
                                  "value" : 65
                          },
                          {
                                  "path" : "temp_cool",
                                  "value" : 85
                          }
                  ]
          },
          {
                  "name" : "afternoon",
                  "start" : "17:30",
                  "points" : [
                          {
                                  "path" : "temp_heat",
                                  "value" : 70
                          },
                          {
                                  "path" : "temp_cool",
                                  "value" : 80
                          }
                  ]
          },
          {
                  "name" : "evening",
                  "start" : "21:00",
                  "points" : [
                          {
                                  "path" : "temp_heat",
                                  "value" : 50
                          },
                          {
                                  "path" : "temp_cool",
                                  "value" : 90
                          }
                  ]
          }
  ]
}

this JSON object can be defined in an external file, as a web resource, or in a document store such as MongoDB.

The scheduler service parses this document to derive what values should be advertised at what times. The nested "path" refers to a URI endpoint defined in the scheduler service; the scheduled values are published on these endpoints.

# inside schedule.json
"points" : [
        {
          "path" : "temp_heat",
          "value" : 50
        },
...
# inside scheduler.py
self.add_timeseries('/temp_heat', 'F', data_type='long')

##Subscribing to a Scheduler

Clone this wiki locally