Fixed small typo bug that fixed entire Winner_Screen() funcion.
This commit is contained in:
62
src/main.cpp
62
src/main.cpp
@@ -32,8 +32,6 @@ size_t curr_vote = 0;
|
||||
size_t final_vote[6] = {};
|
||||
int start_screen = 0;
|
||||
int ibvs_mode = 0;
|
||||
int ping_number = 0;
|
||||
unsigned long last_publish_time = 0;
|
||||
bool ibvs_mode_done = false;
|
||||
bool screenNeedsUpdate = true;
|
||||
bool configDone = false;
|
||||
@@ -44,6 +42,7 @@ bool wifi_connected = false;
|
||||
char current_screen = 'A';
|
||||
char winner = 'X';
|
||||
char Badge_ID[9];
|
||||
const char* UPLOAD_SERVER = "172.30.30.30";
|
||||
String badges;
|
||||
std::vector<String> register_badges;
|
||||
String load = "";
|
||||
@@ -60,8 +59,6 @@ ShortText item3 = {"Maybe", 4, 140};
|
||||
ShortText item4 = {"Abstain", 4, 170};
|
||||
ShortText item5 = {"Null", 4, 200};
|
||||
|
||||
//lv_image_dsc_t* dynamic_img_dsc = NULL;
|
||||
|
||||
WebServer server(80); // For web image uploader
|
||||
|
||||
#define DRAW_BUF_SIZE (SCREEN_WIDTH * SCREEN_HEIGHT / 10 * (LV_COLOR_DEPTH / 8))
|
||||
@@ -218,7 +215,11 @@ void loop() {
|
||||
|
||||
|
||||
if (vote_end) {
|
||||
char url[100];
|
||||
|
||||
message = get_winner();
|
||||
sprintf(url, "http://%s:8080/results", UPLOAD_SERVER);
|
||||
upload_results_http(url);
|
||||
mqtt_server.publish(topic_winner, message);
|
||||
vote_end = false;
|
||||
}
|
||||
@@ -434,7 +435,7 @@ void Winner_Screen() {
|
||||
if (winner == '1')
|
||||
set_var_ui_winner(item1.text);
|
||||
else if (winner == '2')
|
||||
set_var_ui_winner(item1.text);
|
||||
set_var_ui_winner(item2.text);
|
||||
else if (winner == '3')
|
||||
set_var_ui_winner(item3.text);
|
||||
else if (winner == '4')
|
||||
@@ -706,20 +707,6 @@ bool connect_wifi() {
|
||||
return true;
|
||||
}
|
||||
|
||||
void listSPIFFS() {
|
||||
Serial.println("Files in SPIFFS:");
|
||||
fs::File root = SPIFFS.open("/");
|
||||
fs::File file = root.openNextFile();
|
||||
while(file) {
|
||||
Serial.print(" ");
|
||||
Serial.print(file.name());
|
||||
Serial.print(" - ");
|
||||
Serial.print(file.size());
|
||||
Serial.println(" bytes");
|
||||
file = root.openNextFile();
|
||||
}
|
||||
}
|
||||
|
||||
void handleImageUpload() {
|
||||
HTTPUpload& upload = server.upload();
|
||||
static fs::File uploadFile;
|
||||
@@ -925,4 +912,39 @@ char get_winner() {
|
||||
return '0'; // '0' means tie
|
||||
}
|
||||
return winner; // '1'-'5' for winner
|
||||
}
|
||||
}
|
||||
|
||||
void upload_results_http(const char* server_url) {
|
||||
HTTPClient http;
|
||||
http.begin(server_url);
|
||||
http.addHeader("Content-Type", "application/json");
|
||||
|
||||
// Build JSON with results
|
||||
String json = "{";
|
||||
json += "\"question\":\"" + String(question.text) + "\",";
|
||||
json += "\"total_votes\":" + String(curr_vote) + ",";
|
||||
json += "\"num_badges\":" + String(num_badges) + ",";
|
||||
json += "\"results\":{";
|
||||
json += "\"" + String(item1.text) + "\":" + String(final_vote[1]) + ",";
|
||||
json += "\"" + String(item2.text) + "\":" + String(final_vote[2]) + ",";
|
||||
json += "\"" + String(item3.text) + "\":" + String(final_vote[3]) + ",";
|
||||
json += "\"" + String(item4.text) + "\":" + String(final_vote[4]) + ",";
|
||||
json += "\"" + String(item5.text) + "\":" + String(final_vote[5]);
|
||||
json += "},";
|
||||
json += "\"null_votes\":" + String(final_vote[0]) + ",";
|
||||
json += "\"winner\":\"" + String(message) + "\"}";
|
||||
|
||||
Serial.println("Uploading results...");
|
||||
Serial.println(json);
|
||||
|
||||
int httpCode = http.POST(json);
|
||||
|
||||
if (httpCode > 0) {
|
||||
Serial.printf("HTTP Response code: %d\n", httpCode);
|
||||
String response = http.getString();
|
||||
Serial.println("Response: " + response);
|
||||
} else {
|
||||
Serial.printf("Error on HTTP request: %s\n", http.errorToString(httpCode).c_str());
|
||||
}
|
||||
http.end();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user