-
Notifications
You must be signed in to change notification settings - Fork 1
Action semantics
The following request asks to read the state of the resource named /motor/A
{
"action":"GET",
"resource":"/motor/A"
}
A possible result:
{
"status":0,
"content":{
"forward":true,
"speed":300
}
}
It is possible to read the status of the whole NXT
{
"action":"GET",
"resource":"/"
}
A possible result:
{
"status":0,
"content":{
"motor":{
"A":{"forward":true,"speed":300},
"B":{"forward":true,"speed":300},
"C":{"forward":true,"speed":300}
},
"sensor":{
"touch1":{"isPressed":false},
"touch2":{"isPressed":true}
}
}
}
We use PUT
to overwrite the status of a resource.
{
"action":"PUT",
"resource":"/motor/A"
"payload":{"forward":true,"speed":300}
}
This request sets the speed of motor A to 300 and switches on the motor.
Resources are usually preloaded on NXT as part of NXTServer code. It is also possible to create resources dynamically when NXTServer is running. This part is still very beta and we implemented a very simple behavior. You can create resources with POST
action.
{
"action":"POST",
"resource":"/"
"payload":{
"name":"move_A_at_touch",
"trigger":{
"name":"/sensor/touch1",
"condition":{"isPressed":true}
},
"target":{
"name":"/motor/A",
"behavior":{"forward":true}
}
}
}
The request says: create a new resource named move_A_at_touch
as a child of /
resource. The behavior of the new resource is defined giving the condition which triggers the behavior. In this case, when the sensor touch1
is pressed motor A
is switched on.
Resources previously created with POST
can be deleted. Example
{
"action":"DELETE",
"resource":"/move_A_at_touch"
}
However, this kind of requests does not work at the moment because of a limitation of LeJOS. We implement resources with Hashtable
, but the implementation of Hashtable
in LeJOS does not seem to have a delete(key)
method.