Menu

CreateScript

Jim

Create new Script

Creates a new script in the domain of the owner identified by the apikey.

There are two kinds of scripts:

  • scripts implementing IScriptRunner are called when ever sensor data is received. They must be assigned to a device model in order to be executed. They are used to implement application specific sensor data processing like data validation, interpolation, threshold checks or triggers.
    public interface IScriptRunner {

       public void run(String apikey, 
                       String deviceName, 
                       SensorData sensor) throws ScriptException;

    }
  • scripts implementing IHttpConnectorScript are assigned to the HttpConnector and are executed automatically when ever the HttpConnector receives sensor data. They are used to transform the received sensor data to the standard Moments representation
    public interface IHttpConnectorScript {

        public String getDevice (HttpServletRequest request) throws ScriptException;

        public List<SensorData> getSensorData 
                                    (String apikey, 
                                     String deviceModel,
                                     DeviceModelManager deviceModelManager,
                                     SensorModelManager sensorModelManager,           
                                     HttpServletRequest request) 
                                throws ScriptException;
        }
    }

Path: cs-ws/resources/admin/script Method: POST

Parameters

  • apikey

Data

<script>
   <code>...</code>
   <name>...</name>
   <version>...</version>
</script>

Errors:

  • 401 UNAUTHORIZED if key is invalid or not admin key
  • 406 NOT ACCEPTABLE if the script can not be compiled
  • 409 CONFLICT if script already exists

Example

POST http://localhost/cs-ws/resources/admin/script/?apikey=1234 HTTP/1.1
<script>
   <code>import com.m2mlabs.cs.manager.IScriptRunner;
       import com.m2mlabs.cs.model.SensorData;
       class Greeter implements IScriptRunner {
          public void run(String apikey, String deviceName, SensorData sensor) throws       
              ScriptException {println (deviceName) ;
          }
       }
   </code>
   <name>TestScript3</name>
   <version>1</version>
</script>

HTTP/1.1 200 OK

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.