Important changes to forums and questions
All forums and questions are now archived. To start a new conversation or read the latest updates go to forums.mbed.com.
5 years, 8 months ago.
post a response on my rest server via a switch
Hi
I want to connect a switch to the my LPC1768 and when I press this switch , I will send a response to my rest server after getting the request.
I'm using interrupts but when I press the switch I got this error:
++ MbedOS Error Info ++
Error Status: 0x80020115 Code: 277 Module: 2
Error Message: Mutex lock failed
Location: 0x1280F
Error Value: 0xFFFFFFFA
Current Thread: rtx_idle Id: 0x1000037C Entry: 0x14ABB StackSize: 0x200 StackMem: 0x10000408 SP: 0x10007EE8
For more info, visit: https://armmbed.github.io/mbedos-error/?error=0x80020115
MbedOS Error Info
My program as follow :
- include "select-demo.h"
- if DEMO == DEMO_HTTP
- include "mbed.h"
- include "http_request.h"
- include "network-helper.h"
- include "mbed_mem_trace.h"
DigitalOut myled(LED1); InterruptIn pb(p8);
void dump_response(HttpResponse* res) { printf("Status: %d - %s\n", res->get_status_code(), res->get_status_message().c_str());
printf("Headers:\n"); for (size_t ix = 0; ix < res->get_headers_length(); ix++) { printf("\t%s: %s\n", res->get_headers_fields()[ix]->c_str(), res->get_headers_values()[ix]->c_str()); } printf("\nBody (%d bytes):\n\n%s\n", res->get_body_length(), res->get_body_as_string().c_str()); }
void pb_hit_interrupt (NetworkInterface* network) { POST request to httpbin.org
HttpRequest* post_req = new HttpRequest(network, HTTP_POST, "http://192.168.0.57:5500/status"); post_req->set_header("Content-Type", "application/json");
const char body[] = "{\"hello\":\"world\"}";
HttpResponse* post_res;
post_res = post_req->send(body, strlen(body));
if (!post_res) { printf("HttpRequest failed (error code %d)\n", post_req->get_error()); return 1; }
printf("\n- HTTP POST response -\n");
dump_response(post_res);
delete post_req; }
int main() {
pb.mode(PullUp);
char buf[10]; Connect to the network with the default networking interface if you use WiFi: see mbed_app.json for the credentials NetworkInterface* network = connect_to_default_network_interface(); if (!network) { printf("Cannot connect to the network, see serial output\n"); return 1;
}
pb.fall(&pb_hit_interrupt, network);
reafing the switch
button_state = pb.read(); button_state = !button_state;
printf("button state: %d\n", button_state); myled = button_state;
sprintf(buf, "%d", button_state);
Do a GET request to httpbin.org { By default the body is automatically parsed and stored in a buffer, this is memory heavy. To receive chunked response, pass in a callback as last parameter to the constructor. HttpRequest* get_req = new HttpRequest(network, HTTP_GET, "http://192.168.0.57:5500/status");
HttpResponse* get_res = get_req->send(); if (!get_res) { printf("HttpRequest failed (error code %d)\n", get_req->get_error()); return 1; }
printf("\n- HTTP GET response -\n");
dump_response(get_res);
delete get_req; }
wait(osWaitForever); }
- endif
Please help.
Thank you in advance
Nada
Please, I need your help as soon as possible. Really I will be appreciated.
posted by Nada Ali 19 Mar 2019