ENTS-tock
Environmental NeTworked Sensor firmware on Tock OS
Loading...
Searching...
No Matches
example_dirtviz.cpp
Go to the documentation of this file.
1
10#include <Arduino.h>
11#include <WiFi.h>
12
13#include "dirtviz.hpp"
14
16#define SERIAL_BAUD 115200
17
18const char ssid[] = "wifi-network-here";
19const char pass[] = "wifi-password-here";
20
21Dirtviz api("ip address here");
22
23const char data[] = "message-here";
24const size_t data_len = 21;
25
31void setup() {
32 // Start serial interface
33 Serial.begin(115200);
34 // Wait for serial connection
35 while (!Serial) {
36 delay(100);
37 }
38
39 Serial.print("SSID: ");
40 Serial.println(ssid);
41 Serial.print("Password: ");
42 Serial.println(pass);
43 Serial.print("Connecting");
44
45 // Connect to WiFi network
46 WiFi.begin(ssid, pass);
47
48 // Wait for WiFi to connect
49 while (WiFi.status() != WL_CONNECTED) {
50 delay(500);
51 Serial.print(".");
52 }
53
54 Serial.println("");
55 Serial.println("Connected!");
56 Serial.println(WiFi.localIP());
57}
58
59void loop() {
60 const uint8_t* resp_data;
61 size_t resp_data_len;
62
63 // Send example measurement
64 api.SendMeasurement((const uint8_t*)data, data_len);
65 HttpClient http_client = api.GetResponse();
66 Serial.print("Response Code: ");
67 Serial.println(http_client.ResponseCode());
68
69 // Get response data
70 Serial.println("Response:");
71 Serial.println(http_client.Data().c_str());
72
73 // wait 1s
74 delay(1000);
75}
Logic for interfacing with the Dirtviz API.
Definition dirtviz.hpp:43
unsigned int SendMeasurement(const uint8_t *meas, size_t meas_len)
Send serialized measurement to the API.
Definition dirtviz.cpp:64
HttpClient GetResponse()
Get the response from the server.
Definition dirtviz.cpp:106
HTTP request parser library.
Definition http.hpp:28
unsigned int ResponseCode()
Get the http response code.
Definition http.cpp:31
std::string Data()
Get data from Http request.
Definition http.cpp:35
const char ssid[]
const size_t data_len
void setup()
Initialization code run on startup.
const char pass[]
Dirtviz api("ip address here")
const char data[]
void loop()