Back
Other

Example of project

Study material for Tecnologie Digitali, shared by the Studwiz community and reviewed by moderators.

Tecnologie DigitaliOther

Document information

What's included in this study material

Study material for Tecnologie Digitali, shared by the Studwiz community and reviewed by moderators.

Import quality: text was extracted directly from the original document.

Extracted content from the document

Representative passages recognised in different parts of the material. The full extracted text remains available to search, while this compact preview makes the page easier to read.

Page 1

#include "mbed.h" #include "C12832.h" #include "Sht31.h" #include "NetworkInterface.h" #include "http_request.h" 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()); } C12832 lcd(SPI_MOSI, SPI_SCK, SPI_MISO, p8, p11); Sht31 sht31(I2C_SDA, I2C_SCL); DigitalOut led1(LED1); DigitalOut led2(LED2); int main() { printf("benvenuti nel progetto di Tecnologie Digitali 2 (modulo reti)\n"); char bodysend[200]; float stored_temp = sht31.readTemperature(); float stored_humidity = sht31.readHumidity(); { NetworkInterface *network = NetworkInterface::get_default_instance(); if (network->connect() != 0) { printf("Cannot connect to the network, see serial output"); return 1; } /* apertura della richista POST al server e identificazione dell'utente*/ { HttpRequest* post_req = new HttpRequest(network, HTTP_POST, "http://34.212.30.54:5000/api/send_id_and_get_threshold"); post_req->set_header("Content-Type", "application/json"); const char body[] = "{\"student_id\": codice_persona}"; HttpResponse* 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; } while (1) { float temp = sht31.readTemperature(); float humidity = sht31.readHumidity(); if (temp != stored_temp || humidity != stored_humidity){ /* a seconda che il server richieda la temperatura, oppure…

Preview

First page of the document.

First page: Example of project