intrelayControl(Stringcommand)
{
intrelayState=0;
//parsetherelaynumber
intrelayNumber=command.charAt(1)‐'0';
//doasanitycheck
if(relayNumber<1||relayNumber>4)return‐1;
//findoutthestateoftherelay
if(command.substring(3,7)=="HIGH")relayState=1;
elseif(command.substring(3,6)=="LOW")relayState=0;
elsereturn‐1;
//writetotheappropriaterelay
digitalWrite(relayNumber+2,relayState);
return1;
}
An example API request to this function would look something like this:
POST/v1/devices/{DEVICE_ID}/relay
#EXAMPLEREQUEST
curlhttps://api.particle.io/v1/devices/0123456789abcdef/relay\
‐daccess_token=123412341234‐dparams=r1,HIGH
Relay Shield - Specifications (v3.x.x)
Operating voltage: 7 to 20V DC
Current consumption: 150mA min to 290mA max (at 9V DC)
Relay Max Voltage: 220V AC
Relay Max Current: 10Amp at 125V AC
Relay Part Number: JS1-5V-F
Dimensions: 6.0" x 1.7"
Weight: 80 gms
Drill Template > https://docs.particle.io/assets/images/shields/relay-shield/relay-shield-template.pdf
https://docs.particle.io/datasheets/particle‐shields/#relay‐shield10‐19‐17