ThingWorx WebSocket-based Edge MicroServer (WS EMS) and Lua Script Resource (LSR) > Additional Configuration of WS EMS > Configuring Duty Cycle Modulation
  
Configuring Duty Cycle Modulation
Duty cycle modulation enables developers to control the time that a WS EMS is connected to the ThingWorx platform. It defines the frequency and duration of the connection between a WS EMS and a ThingWorx platform. If you need to conserve power or bandwidth at the expense of availability/responsiveness, you can use duty cycle modulation. This feature may be useful if you have critical processes during which you want to disable communications for a device. By configuring duty cycle modulation in the duty_cycle group in the config.json file of your WS EMS, you can put the WS EMS into an offline mode.
As of v.5.4.3, duty cycle modulation keeps the WebSocket connection alive as long as there is activity within a configurable amount of time on the WS EMS ( delay_duty_cycle property). The WebSocket connection enters a duty cycle OFF state only if there have not been any messages from the ThingWorx platform in the configured number of seconds. For example, if a file transfer is in progress, you may need to keep the connection open for an additional two minutes. The duty cycle has a separate configuration group in config.json, as follows:

"duty_cycle" : {
"connect_period" " 60000,
"duty_cycle" " 100,
"delay_duty_cycle" : 60000
}
where
connect_period — Defines the period of time set for duty cycle intervals. A value of 0 means that the WS EMS is always connected. The default rate is 60000 (one minute).
duty_cycle — Determines what percentage of time during the connection period that the WS EMS is connected to the ThingWorx platform. The default value is 100 percent, which means that the WS EMS is always connected. This value is also the maximum value for this property. A value of 0 also means that the WS EMS is always connected during the connection period.
delay_duty_cycle — Defines the time interval (in milliseconds) for which the duty cycle should not be entered after receiving a message from the platform. The default value is 60000 milliseconds (one minute).
* 
If the config.json file does not have the "duty_cycle" group, the WS EMS assumes that its connection is always on (that is, duty_cycle is set to 0 or 100 percent).
The following diagram illustrates the effects of the duty cycle parameters on the connection between a WS EMS and a ThingWorx platform:
Duty cycle illustration, showing how the properties work together
In addition to the configuration file changes for duty cycle in v.5.4.3, the WS EMS has changed to enable it to track file transfers and tunnels, as well as property and service requests from the ThingWorx platform. Duty cycle will not disconnect the WS EMS from the platform if any of the following conditions are true:
A message has been received from the platform during the last delay_duty_cycle time interval.
A message has been sent to the platform but no response has been received yet.
A file transfer is pending or in progress.
A remote session (tunnel) is in progress (open).
Finally the WS EMS will not be disconnected from the ThingWorx platform immediately after starting up. Instead, the WS EMS will disconnect at the next Duty Cycle event after startup. The next Duty Cycle event is the next time when the WS EMS should connect to or disconnect from the platform.
If the WS EMS is connected to the ThingWorx platform, the next Duty Cycle event is calculated as follows:
nextDutyCycleEvent = Current time + ((connect_period * duty_cycle)/100)
For example, if the connect_period is one minute (60,000 ms) and the duty_cycle is 30 percent, the WS EMS will disconnect after 18,000 milliseconds. That is, the WS EMS will remain connected for 30 percent of the connect_period:
(30/100) * 60000 = 18000
If the WS EMS is disconnected from the platform, the next Duty Cycle event is calculated as follows:
nextDutyCycleEvent = Current time + ((connect_period * (100 duty_cycle))/100)
For example, if the connect_period is one minute (60,000 ms) and the duty_cycle is 30 percent, the WS EMS will connect after 42,000 milliseconds. That is, the WS EMS will remain disconnected for 70 percent of the connect_period:
((100 = 30)/100) * 60000 = 42000
Duty cycle is considered to be enabled if the following conditions are true:
The connect_period is greater than zero. That is, the total number of milliseconds that the WebSocket will stay connected is greater than zero. The value of 0 indicates “AlwaysOn”.
The duty_cycle is less than 100 and greater than 0. That is the percentage of the connect_period that the WS EMS remains connected to a ThingWorx platform is less than 100 and greater than 0. A value of 100 or 0 indicates “AlwaysOn”.
If an LSR pushes data (e.g., property value changes) to a WS EMS while the WS EMS is in the OFF state of a duty cycle, the data is stored in the offline message store and sent to the ThingWorx platform once the WS EMS is connected again (duty cycle ON state).