| Line 1: |
Line 1: |
| − | <span style="color: #B22A2A; font-size: 24px; display: inline-block; margin-top: 15px; margin-bottom: 0px;"><strong>About this trigger</strong></span> | + | <pre class="header-style">The HTTP Server Request trigger creates a local HTTP server on your device that can trigger macros based on specific HTTP requests. This allows external devices on the same local network to trigger macros by sending HTTP requests to your device.</pre> |
| | | | |
| − | <pre style="background-color: #ACC8E5; color: #112A46; border-radius: 10px; padding: 10px; margin-top: 5px; margin-bottom: 5px;">
| + | ''' Options ''' |
| − | This trigger will create a local HTTP Server and can trigger based on specific HTTP requests.
| |
| | | | |
| − | A local HTTP server, or localhost, is a personal web server URL that can be configured to serve content over HTTP and be accessible from a device on the same local network. | + | * '''Identifier''': A unique path identifier for this trigger. The full URL will be: http://[device_ip]:[port]/[identifier]. Supports magic text. |
| − | </pre>
| |
| | | | |
| − | <pre style="background-color: #FFFF99; color: #112A46; border-radius: 10px; padding: 10px; margin-top: 5px; margin-bottom: 5px;">
| + | * '''IP Address Whitelist''': Restrict which IP addresses can trigger this macro. Multiple entries can be added. Supports wildcards and magic text. Leave empty to allow all IP addresses. |
| − | Please note the following:
| |
| | | | |
| − | * You cannot access from anywhere other than the local network. | + | * '''Variable Whitelist''': When configured, only the specified variables can be updated via the HTTP request parameters. Variables not in the whitelist will be blocked with a warning logged. |
| | | | |
| − | * Anyone who knows this url will be able to access (local network only) to prevent this from happening define an IP whitelist. | + | * '''Send Response''': When enabled, the trigger sends a response to the HTTP client. |
| | + | ** '''Response Text''': The text content to send in the response. Supports magic text. |
| | + | ** '''Response Code''': The HTTP status code to return (e.g., 200 OK, 404 Not Found, etc.) |
| | + | ** '''Header Parameters''': Additional HTTP headers to include in the response. |
| | | | |
| − | * That your device's IP address can change. Consider assigning a static IP address to prevent this happening. | + | * '''Save Body to Variable''': Store the HTTP request body content into a string variable, optionally with dictionary keys for structured data. |
| − | </pre>
| |
| | | | |
| − | <span style="color: #B22A2A; font-size: 18px; display: inline-block; margin-top: 15px; margin-bottom: 15px;"><strong>Send Response </strong></span>
| + | * '''Save Body to File''': Save the HTTP request body to a file. |
| | + | ** '''Directory''': The directory path where the file will be saved. Supports magic text. |
| | + | ** '''Filename''': The filename to use. Supports magic text. |
| | | | |
| − | <pre style="background-color: #ACC8E5; color: #112A46; border-radius: 10px; padding: 10px; margin-top: 5px; margin-bottom: 5px;">
| + | ''' HTTP Server Settings ''' |
| − | When you access the url, the trigger will automatically respond with a personalised text response.
| |
| − | </pre>
| |
| | | | |
| − | ''See also: [https://macrodroidforum.com/wiki/index.php/Action:_HTTP_Server HTTP Server Action].''
| + | The HTTP server port can be configured in MacroDroid Settings. Click the "HTTP Server Settings" link in the trigger configuration to access these settings. |
| | | | |
| − | <span style="color: #B22A2A; font-size: 18px; display: inline-block; margin-top: 15px; margin-bottom: 15px;"><strong>Response Code</strong></span>
| + | ''' Examples ''' |
| | | | |
| − | <pre style="background-color: #ACC8E5; color: #112A46; border-radius: 10px; padding: 10px; margin-top: 5px; margin-bottom: 5px;"> | + | ''Example 1: Simple Macro Trigger'' |
| − | Supports response code
| + | <pre class="trigger-style">Triggers |
| − | and only responds to a simple custom text or magic text.
| |
| − | </pre>
| |
| | | | |
| − | ''See also: [https://en.wikipedia.org/wiki/List_of_HTTP_status_codes HTTP Status Code (Wikipedia)].''<br/>
| + | HTTP Server Request - toggle_flashlight</pre> |
| | + | <pre class="action-style">Actions |
| | | | |
| | + | Torch Toggle</pre> |
| | | | |
| − | <span style="color: #B22A2A; font-size: 18px; display: inline-block; margin-top: 15px; margin-bottom: 15px;"><strong>IP address whitelist </strong></span>
| + | Toggles the flashlight when an HTTP request is made to: http://192.168.1.100:8080/toggle_flashlight |
| | | | |
| − | <pre style="background-color: #ACC8E5; color: #112A46; border-radius: 10px; padding: 10px;">
| + | ''Example 2: Update Variable via HTTP'' |
| − | It can support one or more IP addresses so that the HTTP Server is only accessible from specific IP addresses.
| + | <pre class="trigger-style">Triggers |
| − | Also supports magic text '...'.
| |
| − | </pre>
| |
| − | ''See also: [[magic text|Magic text list]] '' | |
| − | </pre> | |
| | | | |
| − | <span style="color: #B22A2A; font-size: 18px; display: inline-block; margin-top: 15px; margin-bottom: 15px;"><strong>Save body to string variable </strong></span> | + | HTTP Server Request - set_status</pre> |
| | + | <pre class="action-style">Actions |
| | | | |
| − | <pre style="background-color: #ACC8E5; color: #112A46; border-radius: 10px; padding: 10px;"> | + | Popup Message - Status updated to: [v=status]</pre> |
| − | If your HTTP POST request contains any text format, you can save it in any string variable.
| + | |
| | + | Updates a variable by making a request like: http://192.168.1.100:8080/set_status?status=active |
| | + | |
| | + | ''' Magic Text ''' |
| | + | |
| | + | When this trigger fires, the following magic text values are available: |
| | + | * Request IP address |
| | + | * Query parameters string |
| | + | * HTTP headers |
| | + | |
| | + | ''' Notes ''' |
| | + | |
| | + | * The HTTP server only operates on the local network - it is not accessible from the internet. |
| | + | * The device's IP address may change (e.g., when reconnecting to WiFi). Consider using a static IP assignment on your router for consistent access. |
| | + | * Use the IP whitelist feature to restrict access to trusted devices for security. |
| | + | * The variable whitelist feature prevents unauthorized variable modifications when variables are passed via URL parameters. |
| | + | * Multiple triggers can share the same HTTP server (running on the same port) with different identifiers. |
| | + | * The server supports GET and POST requests. |
| | + | * Body content from POST requests can be saved to a variable or file. |
| | + | * On Android 11+, saving body to file requires "All Files Access" permission. |
| | + | |
| | + | ''' URL Parameter Format ''' |
| | + | |
| | + | To set variables via URL parameters, use the format: |
| | + | <code>http://[ip]:[port]/[identifier]?variable_name=value&another_var=value2</code> |
| | + | |
| | + | ''' See Also ''' |
| | + | |
| | + | * [[Action:_HTTP_Server_Response|HTTP Server Response Action]] |
| | + | * [[Trigger:_Webhook_(URL)|Webhook Trigger]] |
| | + | * [[Magic_text|Magic Text]] |