master
Martin Ger 2017-12-16 10:11:42 +01:00
rodzic acfcac6843
commit f7af07080a
8 zmienionych plików z 45 dodań i 10 usunięć

Wyświetl plik

@ -66,7 +66,8 @@ In general, scripts conform to the following BNF:
<val> := <string> | <const> | #<hex-string> | $[any ASCII]* | @<num> |
gpio_in(<num>) | $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
<string> := "[any ASCII]*" | [any ASCII]*
@ -280,7 +281,8 @@ gpio_in(<num>)
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.

Plik binarny nie jest wyświetlany.

Plik binarny nie jest wyświetlany.

Wyświetl plik

@ -1,2 +1,2 @@
d8ba3e38c5c27e69d64f23cc408bceb7adeec416 0x00000.bin
94d406c685a6f15b4f2ff42c93c9ec5297d43425 0x10000.bin
033d48114a262ca73b6b505079e92bb2870b934d 0x00000.bin
efa7d3a70c006f6d7e4cd8115dfde375275324f8 0x10000.bin

Wyświetl plik

@ -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);

Wyświetl plik

@ -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.

Wyświetl plik

@ -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

Wyświetl plik

@ -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;