kopia lustrzana https://github.com/SP8EBC/ParaTNC
http client post method
rodzic
ae1fd396bf
commit
0c481f7d42
|
@ -250,7 +250,7 @@ const char * post_content = "{\
|
|||
\"rte_main_average_battery_voltage\": 123,\
|
||||
\"rte_main_wakeup_count\": 0,\
|
||||
\"rte_main_going_sleep_count\": 2,\
|
||||
\"rte_main_last_sleep_master_time\": 9}\0\0";
|
||||
\"rte_main_last_sleep_master_time\": 9}";
|
||||
|
||||
static void dupa(uint16_t http_code, char * content, uint16_t content_lenght) {
|
||||
|
||||
|
@ -716,7 +716,7 @@ int main(int argc, char* argv[]){
|
|||
main_wx_srl_ctx_ptr->te_pin = LL_GPIO_PIN_8;
|
||||
main_wx_srl_ctx_ptr->te_port = GPIOA;
|
||||
|
||||
srl_init(main_gsm_srl_ctx_ptr, USART3, srl_usart3_rx_buffer, RX_BUFFER_1_LN, srl_usart3_tx_buffer, TX_BUFFER_1_LN, 115200, 1);
|
||||
srl_init(main_gsm_srl_ctx_ptr, USART3, srl_usart3_rx_buffer, RX_BUFFER_3_LN, srl_usart3_tx_buffer, TX_BUFFER_3_LN, 115200, 1);
|
||||
#endif
|
||||
|
||||
// initialize APRS path with zeros
|
||||
|
@ -1204,8 +1204,8 @@ int main(int argc, char* argv[]){
|
|||
*
|
||||
* TEST TEST TEST TODO
|
||||
*/
|
||||
//retval = http_client_async_get("http://pogoda.cc:8080/meteo_backend/status", strlen("http://pogoda.cc:8080/meteo_backend/status"), 0xFFF0, 0x1, dupa);
|
||||
retval = http_client_async_post("http://pogoda.cc:8080/meteo_backend/status", strlen("http://pogoda.cc:8080/meteo_backend/status"), post_content, strlen(post_content), 1, dupa);
|
||||
retval = http_client_async_get("http://pogoda.cc:8080/meteo_backend/status", strlen("http://pogoda.cc:8080/meteo_backend/status"), 0xFFF0, 0x1, dupa);
|
||||
//retval = http_client_async_post("http://pogoda.cc:8080/meteo_backend/parameteo/skrzyczne/status", strlen("http://pogoda.cc:8080/meteo_backend/parameteo/skrzyczne/status"), post_content, strlen(post_content), 0, dupa);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -257,7 +257,7 @@ uint8_t http_client_async_get(char * url, uint8_t url_ln, uint16_t response_ln_l
|
|||
|
||||
// assemble headers
|
||||
current_request_ln = http_client_headers_preamble(HTTP_GET, url + split_point, url_ln - split_point, (char * )http_client_deticated_serial_context->srl_tx_buf_pointer, http_client_deticated_serial_context->srl_tx_buf_ln);\
|
||||
current_request_ln = http_client_headers_host(url + HTTP_PREFIX_LN, url_ln - split_point - HTTP_PREFIX_LN, (char * )http_client_deticated_serial_context->srl_tx_buf_pointer, http_client_deticated_serial_context->srl_tx_buf_ln, current_request_ln);
|
||||
current_request_ln = http_client_headers_host(url + HTTP_PREFIX_LN, split_point - HTTP_PREFIX_LN, (char * )http_client_deticated_serial_context->srl_tx_buf_pointer, http_client_deticated_serial_context->srl_tx_buf_ln, current_request_ln);
|
||||
current_request_ln = http_client_headers_accept((char * )http_client_deticated_serial_context->srl_tx_buf_pointer, http_client_deticated_serial_context->srl_tx_buf_ln, current_request_ln);
|
||||
current_request_ln = http_client_headers_user_agent((char * )http_client_deticated_serial_context->srl_tx_buf_pointer, http_client_deticated_serial_context->srl_tx_buf_ln, current_request_ln);
|
||||
current_request_ln = http_client_headers_terminate((char * )http_client_deticated_serial_context->srl_tx_buf_pointer, http_client_deticated_serial_context->srl_tx_buf_ln, current_request_ln);
|
||||
|
@ -344,16 +344,21 @@ uint8_t http_client_async_post(char * url, uint8_t url_ln, char * data_to_post,
|
|||
|
||||
// assemble headers
|
||||
current_request_ln = http_client_headers_preamble(HTTP_POST, url + split_point, url_ln - split_point, (char * )http_client_deticated_serial_context->srl_tx_buf_pointer, http_client_deticated_serial_context->srl_tx_buf_ln);\
|
||||
current_request_ln = http_client_headers_host(url + HTTP_PREFIX_LN, url_ln - split_point - HTTP_PREFIX_LN, (char * )http_client_deticated_serial_context->srl_tx_buf_pointer, http_client_deticated_serial_context->srl_tx_buf_ln, current_request_ln);
|
||||
current_request_ln = http_client_headers_content_ln((char * )http_client_deticated_serial_context->srl_tx_buf_pointer, http_client_deticated_serial_context->srl_tx_buf_ln, current_request_ln, data_ln);
|
||||
current_request_ln = http_client_headers_host(url + HTTP_PREFIX_LN, split_point - HTTP_PREFIX_LN, (char * )http_client_deticated_serial_context->srl_tx_buf_pointer, http_client_deticated_serial_context->srl_tx_buf_ln, current_request_ln);
|
||||
current_request_ln = http_client_headers_content_type_json((char * )http_client_deticated_serial_context->srl_tx_buf_pointer, http_client_deticated_serial_context->srl_tx_buf_ln, current_request_ln);
|
||||
current_request_ln = http_client_headers_user_agent((char * )http_client_deticated_serial_context->srl_tx_buf_pointer, http_client_deticated_serial_context->srl_tx_buf_ln, current_request_ln);
|
||||
current_request_ln = http_client_headers_accept((char * )http_client_deticated_serial_context->srl_tx_buf_pointer, http_client_deticated_serial_context->srl_tx_buf_ln, current_request_ln);
|
||||
current_request_ln = http_client_headers_content_ln((char * )http_client_deticated_serial_context->srl_tx_buf_pointer, http_client_deticated_serial_context->srl_tx_buf_ln, current_request_ln, data_ln);
|
||||
current_request_ln = http_client_headers_terminate((char * )http_client_deticated_serial_context->srl_tx_buf_pointer, http_client_deticated_serial_context->srl_tx_buf_ln, current_request_ln);
|
||||
|
||||
|
||||
// check if there is a room for the content
|
||||
if (http_client_deticated_serial_context->srl_tx_buf_ln > current_request_ln + data_ln) {
|
||||
// if yes append HTTP content
|
||||
current_request_ln = sprintf((char * )http_client_deticated_serial_context->srl_tx_buf_pointer + current_request_ln, "%s\r\n", data_to_post);
|
||||
sprintf((char * )http_client_deticated_serial_context->srl_tx_buf_pointer + current_request_ln, "%s", data_to_post);
|
||||
|
||||
// and calculate total request ln
|
||||
current_request_ln = strlen((char * )http_client_deticated_serial_context->srl_tx_buf_pointer);
|
||||
|
||||
// send data through TCP/IP connection
|
||||
connect_result = gsm_sim800_tcpip_write(http_client_deticated_serial_context->srl_tx_buf_pointer, current_request_ln, http_client_deticated_serial_context, http_client_deticated_sim800_state);
|
||||
|
|
|
@ -86,7 +86,7 @@ uint16_t http_client_headers_accept(char *output, uint16_t output_ln,
|
|||
|
||||
uint16_t out = 0;
|
||||
|
||||
snprintf(output + offset, output_ln - offset, "Accept: application/json\r\nAccept-Language: en-US,en;q=0.5\r\n");
|
||||
snprintf(output + offset, output_ln - offset, "Accept: */*\r\n");
|
||||
|
||||
out = strlen (output);
|
||||
|
||||
|
@ -106,7 +106,7 @@ uint16_t http_client_headers_terminate(char* output, uint16_t output_ln, uint16_
|
|||
uint16_t http_client_headers_content_ln(char* output, uint16_t output_ln, uint16_t offset, uint16_t content_ln) {
|
||||
uint16_t out = 0;
|
||||
|
||||
snprintf(output + offset, output_ln - offset, "Content-lenght: %d\r\n", content_ln);
|
||||
snprintf(output + offset, output_ln - offset, "Content-Length: %d\r\n", content_ln);
|
||||
|
||||
out = strlen (output);
|
||||
|
||||
|
@ -116,7 +116,7 @@ uint16_t http_client_headers_content_ln(char* output, uint16_t output_ln, uint16
|
|||
uint16_t http_client_headers_content_type_json(char* output, uint16_t output_ln, uint16_t offset) {
|
||||
uint16_t out = 0;
|
||||
|
||||
snprintf(output + offset, output_ln - offset, "Content-type: application/json\r\n");
|
||||
snprintf(output + offset, output_ln - offset, "Content-Type: application/json\r\n");
|
||||
|
||||
out = strlen (output);
|
||||
|
||||
|
|
Ładowanie…
Reference in New Issue