diff --git a/SCRIPTING.md b/SCRIPTING.md index 7fb3b8e..9eea9f2 100644 --- a/SCRIPTING.md +++ b/SCRIPTING.md @@ -66,7 +66,8 @@ In general, scripts conform to the following BNF: := | | # | $[any ASCII]* | @ | gpio_in() | $adc | $this_item | $this_data | $this_serial | - $this_gpio | $this_http_code | $this_http_body | $timestamp | $weekday + $this_gpio | $timestamp | $weekday | + $this_http_code | $this_http_host | $this_http_path | $this_http_body := "[any ASCII]*" | [any ASCII]* @@ -280,7 +281,8 @@ gpio_in() Reads the current boolean input value of the given GPIO pin. This pin has to be defined as input before using the "gpio_pinmode" action. ``` -$adc | $this_item | $this_data | $this_serial | $this_gpio | $timestamp | $weekday | $this_http_body | $this_http_code +$adc | $this_item | $this_data | $this_serial | $this_gpio | $timestamp | $weekday | +$this_http_host | $this_http_path | $this_http_code | $this_http_body ``` Special variables: - $adc gives you the current value of the ADC (analog to digital input pin) @@ -288,7 +290,7 @@ Special variables: - $this_serial contains the serial input string in an "on serial" clause. - $this_gpio contains the state of the GPIO in an "on gpio_interrupt" clause. - $timestamp contains the current time of day in "hh:mm:ss" format. If no NTP sync happened the time will be reported as "99:99:99". $weekday returns the day of week as three letters ("Mon","Tue",...). -- $this_http_body and $this_http_code are only defined inside the "on http_response" clause and contain the body of an HTTP response and the HTTP return code. +- $this_http_code, $this_http_host, $this_http_path, and $this_http_body are only defined inside the "on http_response" clause and contain the HTTP return code, the URL host and path of the request, and the body of an HTTP response. ## Operators Operators are used to combine values and expressions. diff --git a/firmware/0x00000.bin b/firmware/0x00000.bin index 3bdee57..9a79b8f 100644 Binary files a/firmware/0x00000.bin and b/firmware/0x00000.bin differ diff --git a/firmware/0x10000.bin b/firmware/0x10000.bin index ad9862b..2d40db2 100644 Binary files a/firmware/0x10000.bin and b/firmware/0x10000.bin differ diff --git a/firmware/sha1sums b/firmware/sha1sums index 91ec1c0..11d5ed5 100644 --- a/firmware/sha1sums +++ b/firmware/sha1sums @@ -1,2 +1,2 @@ -d8ba3e38c5c27e69d64f23cc408bceb7adeec416 0x00000.bin -94d406c685a6f15b4f2ff42c93c9ec5297d43425 0x10000.bin +033d48114a262ca73b6b505079e92bb2870b934d 0x00000.bin +efa7d3a70c006f6d7e4cd8115dfde375275324f8 0x10000.bin diff --git a/httpclient/httpclient.c b/httpclient/httpclient.c index 0c45516..f57cc05 100644 --- a/httpclient/httpclient.c +++ b/httpclient/httpclient.c @@ -339,7 +339,7 @@ static void ICACHE_FLASH_ATTR disconnect_callback(void * arg) } if (req->user_callback != NULL) { // Callback is optional. - req->user_callback(body, http_status, req->buffer, body_size); + req->user_callback(req->hostname, req->path, body, http_status, req->buffer, body_size); } os_free(req->buffer); @@ -367,7 +367,7 @@ static void ICACHE_FLASH_ATTR dns_callback(const char * hostname, ip_addr_t * ad if (addr == NULL) { os_printf("DNS failed for %s\n", hostname); if (req->user_callback != NULL) { - req->user_callback("", -1, "", 0); + req->user_callback(req->hostname, req->path, "", -1, "", 0); } os_free(req->buffer); os_free(req->post_data); diff --git a/httpclient/httpclient.h b/httpclient/httpclient.h index 89b8e6b..3088cb5 100644 --- a/httpclient/httpclient.h +++ b/httpclient/httpclient.h @@ -22,7 +22,7 @@ * A successful request corresponds to an HTTP status code of 200 (OK). * More info at http://en.wikipedia.org/wiki/List_of_HTTP_status_codes */ -typedef void (* http_callback)(char * response_body, int http_status, char * response_headers, int body_size); +typedef void (* http_callback)(char* hostname, char* path, char * response_body, int http_status, char * response_headers, int body_size); /* * Download a web page from its URL. diff --git a/scripts/script.http b/scripts/script.http index 8e55d43..778107e 100644 --- a/scripts/script.http +++ b/scripts/script.http @@ -10,6 +10,7 @@ do on http_response do + println "called url: " | $this_http_host | $this_http_path println "return code: " | $this_http_code println $this_http_body diff --git a/user/lang.c b/user/lang.c index 3711784..d715ef5 100644 --- a/user/lang.c +++ b/user/lang.c @@ -77,8 +77,10 @@ int interpreter_gpioval; #ifdef HTTPC bool in_http_statement; int interpreter_http_status; +char *interpreter_http_path; +char *interpreter_http_hostname; -void interpreter_http_reply(char *response_body, int http_status, char *response_headers, int body_size); +void interpreter_http_reply(char *hostname, char *path, char *response_body, int http_status, char *response_headers, int body_size); #endif static os_timer_t timers[MAX_TIMERS]; @@ -1686,6 +1688,34 @@ int ICACHE_FLASH_ATTR parse_value(int next_token, char **data, int *data_len, Va *data_type = STRING_T; return next_token + 1; } + + else if (is_token(next_token, "$this_http_host")) { + static char codebuf[4]; + lang_debug("val $this_http_host\r\n"); + + if (!in_http_statement) + return syntax_error(next_token, "undefined $this_http_host"); + if (interpreter_status == HTTP_RESPONSE) { + *data = interpreter_http_hostname; + *data_len = os_strlen(interpreter_http_hostname); + *data_type = STRING_T; + } + return next_token + 1; + } + + else if (is_token(next_token, "$this_http_path")) { + static char codebuf[4]; + lang_debug("val $this_http_path\r\n"); + + if (!in_http_statement) + return syntax_error(next_token, "undefined $this_http_path"); + if (interpreter_status == HTTP_RESPONSE) { + *data = interpreter_http_path; + *data_len = os_strlen(interpreter_http_path); + *data_type = STRING_T; + } + return next_token + 1; + } #endif #ifdef NTP else if (is_token(next_token, "$timestamp")) { @@ -1902,7 +1932,7 @@ int ICACHE_FLASH_ATTR interpreter_serial_input(const char *data, int data_len) { } #ifdef HTTPC -void ICACHE_FLASH_ATTR interpreter_http_reply(char *response_body, int http_status, char *response_headers, int body_size) { +void ICACHE_FLASH_ATTR interpreter_http_reply(char *hostname, char *path, char *response_body, int http_status, char *response_headers, int body_size) { if (!script_enabled) return; @@ -1911,6 +1941,8 @@ void ICACHE_FLASH_ATTR interpreter_http_reply(char *response_body, int http_stat interpreter_status = HTTP_RESPONSE; interpreter_topic = response_headers; interpreter_http_status = http_status; + interpreter_http_hostname = hostname; + interpreter_http_path = path; interpreter_data = response_body; interpreter_data_len = body_size;