I am working on an integration from a ESP32 to SignalK with the goal of sending sensor values. SignalK requires you to login first then it returns a token which must be used for the PUT action. So far the login works fine and I can parse the Token out of the response.
As per the log below it is failing on permissions (401). All I can suspect is the JSON is not constructed correctly, but I am not sure how to correct it.
[20:25:15.542][D][main:366]: HTTP Login
[20:25:16.893][D][http_request.idf:043]: Received response header, name: content-type, value: application/json; charset=utf-8
[20:25:16.901][D][http_request.idf:043]: Received response header, name: content-length, value: 137
[20:25:16.901][D][text_sensor:085]: ‘Token’: Sending state ‘eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6ImVzcGhvbWUiLCJpYXQiOjE3NjM0OTM5MTZ9.5xc7c5rGR17iVxD3DQ1J73Q4O1PwHpeG5GzkbbBXLoc’
[20:25:16.912][D][main:082]: Error: Response status: 200, message {“token”:“eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6ImVzcGhvbWUiLCJpYXQiOjE3NjM0OTM5MTZ9.5xc7c5rGR17iVxD3DQ1J73Q4O1PwHpeG5GzkbbBXLoc”}
[20:25:16.917][D][binary_sensor:039]: ‘get_token’: New state is OFF
[20:25:16.918][W][component:453]: template.sensor took a long time for an operation (1481 ms)
[20:25:16.946][W][component:456]: Components should block for at most 30 ms
[20:25:16.946][W][component:453]: api took a long time for an operation (1495 ms)
[20:25:16.946][W][component:456]: Components should block for at most 30 ms
[20:25:16.947][E][component:342]: http_request cleared Error flag
[20:26:15.445][D][sensor:131]: ‘Forward Blackwater Level’: Sending state 0.00000 with 1 decimals of accuracy
[20:26:15.498][D][http_request.idf:043]: Received response header, name: content-type, value: text/plain; charset=utf-8
[20:26:15.499][D][http_request.idf:043]: Received response header, name: content-length, value: 91
[20:26:15.500][E][http_request.idf:207]: HTTP Request failed; URL: http://192.168.1.2:3000/signalk/v1/api/vessels/self/tanks/blackWater/fwd/currentLevel; Code: 401
[20:26:15.500][E][component:314]: http_request set Error flag: unspecified
[20:26:15.522][D][main:179]: Error: Response status: 401, message You do not have permission to view this resource, Please Login
[20:26:16.506][E][component:342]: http_request cleared Error flag
I got distracted with a few other boat projects, but I am not back looking at this. I tried with your suggestion and that works with Postman as per the following screen shot.
But, still getting a permission error. As you can see the Post was successful and I am able to retrieve the Token.
[13:06:05.497][D][main:374]: HTTP Login
[13:06:05.752][D][http_request.idf:043]: Received response header, name: content-type, value: application/json; charset=utf-8
[13:06:05.752][D][http_request.idf:043]: Received response header, name: content-length, value: 137
[13:06:05.752][D][text_sensor:087]: ‘Token’: Sending state ‘eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6ImVzcGhvbWUiLCJpYXQiOjE3NjQyNDUxNjV9.GeeqyZuDp1BaqNl7tqi7NxzV1QgA-nNGi5dFs2OqTZ8’
[13:06:05.753][D][main:082]: Error: Response status: 200, message {“token”:“eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6ImVzcGhvbWUiLCJpYXQiOjE3NjQyNDUxNjV9.GeeqyZuDp1BaqNl7tqi7NxzV1QgA-nNGi5dFs2OqTZ8”}
[13:06:05.762][D][binary_sensor:041]: ‘get_token’: New state is OFF
[13:06:05.781][W][component:454]: template.sensor took a long time for an operation (347 ms)
[13:06:05.804][W][component:457]: Components should block for at most 30 ms
[13:06:05.806][W][component:454]: api took a long time for an operation (377 ms)
[13:06:05.806][W][component:457]: Components should block for at most 30 ms
[13:06:06.478][E][component:343]: http_request cleared Error flag
[13:06:20.424][D][sensor:133]: ‘Forward Blackwater Level’: Sending state 0.00000 % with 1 decimals of accuracy
[13:06:20.458][D][http_request.idf:043]: Received response header, name: content-type, value: text/plain; charset=utf-8
[13:06:20.458][D][http_request.idf:043]: Received response header, name: content-length, value: 91
[13:06:20.458][E][http_request.idf:208]: HTTP Request failed; URL: http://192.168.1.4:3000/signalk/v1/api/vessels/self/tanks/blackWater/fwd/currentLevel; Code: 401
[13:06:20.458][E][component:315]: http_request set Error flag: unspecified
[13:06:20.473][D][main:174]: Error: Response status: 401, message You do not have permission to view this resource, Please Login
[13:06:21.462][E][component:343]: http_request cleared Error flag
[13:06:35.430][D][sensor:133]: ‘Forward Blackwater Level’: Sending state 0.00000 % with 1 decimals of accuracy
[13:06:35.461][D][http_request.idf:043]: Received response header, name: content-type, value: text/plain; charset=utf-8
[13:06:35.469][D][http_request.idf:043]: Received response header, name: content-length, value: 91
[13:06:35.469][E][http_request.idf:208]: HTTP Request failed; URL: http://192.168.1.4:3000/signalk/v1/api/vessels/self/tanks/blackWater/fwd/currentLevel; Code: 401
[13:06:35.469][E][component:315]: http_request set Error flag: unspecified
[13:06:35.469][D][main:174]: Error: Response status: 401, message You do not have permission to view this resource, Please Login
[13:06:36.463][E][component:343]: http_request cleared Error flag
[13:06:50.434][D][sensor:133]: ‘Forward Blackwater Level’: Sending state 0.00000 % with 1 decimals of accuracy
[13:06:50.463][D][http_request.idf:043]: Received response header, name: content-type, value: text/plain; charset=utf-8
[13:06:50.464][D][http_request.idf:043]: Received response header, name: content-length, value: 91
[13:06:50.464][E][http_request.idf:208]: HTTP Request failed; URL: http://192.168.1.4:3000/signalk/v1/api/vessels/self/tanks/blackWater/fwd/currentLevel; Code: 401
[13:06:50.472][E][component:315]: http_request set Error flag: unspecified
[13:06:50.488][D][main:174]: Error: Response status: 401, message You do not have permission to view this resource, Please Login
[13:06:51.472][E][component:343]: http_request cleared Error flag