NodeMCU sketch to control a power strip
- Change pins and modify status_relay variable with same number of pins
int relay[] = {0, 4, 5, 16};
bool status_relay[] = {false, false, false, false};
-
To connect the device to the network visit: tzapu/WiFIManager
-
API
Description Method Endpoint Body elements To start the action described in the body POST /ps "action" and "pin" To receive the status of the relays GET /ps/status - To receive the number of the relays GET /ps/get_relay_number - To receive the type of device GET /get_type - -
Supported actions
Action Description on Turn on relay off Turn off relay -
Examples
-
Request body for "/ps":
{ "action": "YOUT_ACTION", "pin": 2 }
-
Response body for "/ps":
{ "msg": "SOME_MESSAGE" }
-
Response body for "/ps/status" (with 4 relays):
{ "relay_1": false, "relay_2": true, "relay_3": true, "relay_4": false }
- true indicates that the relay is turned on, false indicates that the relay is turned off
-
Response body for "/ps/get_relay_number" (with 4 relays):
{ "number": 4 }
-
Response body for "/get_type":
{ "type": "power_strip" }
-
- Button to reset wifi
It is possible to use any relay module (1, 2, ..., n) only by changing the pins, adding or removing them, and the whole system will adapt automatically