Changes

m
Fixed the breaklines
Line 69: Line 69:     
<code>done</code>
 
<code>done</code>
 +
 
''To use this script, replace the ‘DEVICE_FILE’, ‘SERVER_URL’, and ‘PAYLOAD’ variables with the appropriate values for your system and HTTP server.''
 
''To use this script, replace the ‘DEVICE_FILE’, ‘SERVER_URL’, and ‘PAYLOAD’ variables with the appropriate values for your system and HTTP server.''
 
Press the ‘esc’ on your keyboard to exit insert mode, then type :x, and press enter.
 
Press the ‘esc’ on your keyboard to exit insert mode, then type :x, and press enter.
Line 107: Line 108:  
This line uses '''‘ubus’''' command to call the '''‘ioman.gpio.onewire’''' service and execute the '''‘status’''' command. The output of this command is saved to the ''status'' variable.
 
This line uses '''‘ubus’''' command to call the '''‘ioman.gpio.onewire’''' service and execute the '''‘status’''' command. The output of this command is saved to the ''status'' variable.
 
[[File:Networking trb user scripts cli code explanation1.png|left]]
 
[[File:Networking trb user scripts cli code explanation1.png|left]]
  −
        Line 120: Line 119:  
After that, it checks if the value stored in the '''‘value’''' variable is equal to 0. If it is, the '''‘ubus’''' command is used to call the '''‘ioman.gpio.onewire’''' service and execute the ‘update’ command, which updates the ‘value’ parameter to 1.
 
After that, it checks if the value stored in the '''‘value’''' variable is equal to 0. If it is, the '''‘ubus’''' command is used to call the '''‘ioman.gpio.onewire’''' service and execute the ‘update’ command, which updates the ‘value’ parameter to 1.
 
[[File:Networking trb user scripts cli code explanation2.png|left]]
 
[[File:Networking trb user scripts cli code explanation2.png|left]]
  −
        Line 133: Line 130:  
This line sets the ‘BASE_DIR’ variable to the base directory for 1-wire devices.
 
This line sets the ‘BASE_DIR’ variable to the base directory for 1-wire devices.
 
[[File:Networking trb user scripts cli code explanation3.png|left]]
 
[[File:Networking trb user scripts cli code explanation3.png|left]]
 +
      Line 153: Line 151:  
Which then converts the raw temperature value to degrees Celsius by dividing it by 1000 and then formatting it with two decimal places using '''‘printf’'''. The resulting temperature value is stored in the '''‘temp’''' variable.
 
Which then converts the raw temperature value to degrees Celsius by dividing it by 1000 and then formatting it with two decimal places using '''‘printf’'''. The resulting temperature value is stored in the '''‘temp’''' variable.
 
[[File:Networking trb user scripts cli code explanation5.png|left]]
 
[[File:Networking trb user scripts cli code explanation5.png|left]]
 +
 +
      Line 160: Line 160:  
These lines define the URL of the server to which the temperature data will be sent and the payload data that will be sent with each request. The payload includes the '''‘sensor_id’''' and '''‘temp’''' variables, formatted as a JSON object.
 
These lines define the URL of the server to which the temperature data will be sent and the payload data that will be sent with each request. The payload includes the '''‘sensor_id’''' and '''‘temp’''' variables, formatted as a JSON object.
 
[[File:Networking trb user scripts cli code explanation6.png|left]]
 
[[File:Networking trb user scripts cli code explanation6.png|left]]
 +
      Line 167: Line 168:  
This line uses the '''‘curl’''' command to send an HTTP POST request to the server specified by '''‘$SERVER_URL’'''. The '''‘-X POST’''' option specifies that the request should be a POST request, and the '''‘-H “Content-Type: application/json”’''' option specifies that the payload data is in JSON format. The '''‘-d “$PAYLOAD”’''' option specifies the payload data to be sent with the request.
 
This line uses the '''‘curl’''' command to send an HTTP POST request to the server specified by '''‘$SERVER_URL’'''. The '''‘-X POST’''' option specifies that the request should be a POST request, and the '''‘-H “Content-Type: application/json”’''' option specifies that the payload data is in JSON format. The '''‘-d “$PAYLOAD”’''' option specifies the payload data to be sent with the request.
 
[[File:Networking trb user scripts cli code explanation7.png|left]]
 
[[File:Networking trb user scripts cli code explanation7.png|left]]
 +
 +
      Line 174: Line 177:  
=== Output ===
 
=== Output ===
 
[[File:Networking trb user scripts HTTP listener screenshot.png|left|800x800px]]
 
[[File:Networking trb user scripts HTTP listener screenshot.png|left|800x800px]]
 +
 +
     

Navigation menu