updatePinApi - n1lby73/industrial-IOT GitHub Wiki

Overview

The Update Pin State API authorizes users to securely modify microcontroller pin states. It requires JWT authentication, facilitating specific pin updates and enabling real-time changes to the displayed state. Developers utilizing this API should consider integrating WebSocket functionality for seamless web experiences and immediate UI updates, including handling offline notifications. This supports direct state alterations and ensures prompt notifications to all connected clients upon successful updates, enhancing the overall user experience.

Endpoint URL

  • URL: https://industrialiot.onrender.com/api/updatepin
  • Method:PUT

Request Parameters

  • Headers:

    • Authorization: Bearer <ACCESS_TOKEN>
    • Content-Type: application/json
  • Body Parameters:
Parameter Type Description
pin String PIN for switch querying (required)
state String New state value (0 or 1) (required)

Responses

  • Success Response:

    • Status Code: 200 OK
    • Response Body:
      {
        "success": "pin updated successfully"
      }
      • Description: Indicates that the pin state was updated successfully.
  • Error Responses:

    • Status Code: 400 Bad Request

      • Response Body:
        {
          "error": "invalid pin name or number"
        }
      • Description: Indicates an invalid or unrecognized pin number or name provided.
    • Status Code: 503 Service Unavailable

      • Response Body:
        {
          "Alert": "ESP is offline, can't update"
        }
      • Description: Indicates that the ESP is offline, and the pin state cannot be updated.

Real-time Updates

When the pin state is successfully updated, the server emits a socket message to connected clients with the following information:

  • Socket Message: webUpdate

  • Payload:

    {
      "stateUpdated": "<NEW_STATE>"
    }

Notifies connected clients when the ESP is offline, providing information about the unknown current state.

  • Socket Message: offline

  • Payload:

    {
      "Alert": "Esp is offline. Current state unknown"
    }

Usage

  1. Request Method: PUT

  2. Endpoint URL: https://industrialiot.onrender.com/api/updatepin

  3. Header:

     Authorization: Bearer <JWT>
     Content-Type: application/json
  4. Request Body:

    {
        "pin": "<PIN_NUMBER>",
        "state": "<DESIRED_STATE}>"
    }

    Note: The state field in the request body should only contain either 0 or 1 to represent the desired state.

Additional Information

  • For details on consumed pins and functions, check here.
  • For more error message and causes, check here.
  • For other real time communication socket handler, check here
⚠️ **GitHub.com Fallback** ⚠️