<commit_before>/*
 * Test/demonstration of over-the-air update of an ESP8266 using MQTT.
 *
 * This sketch connects to an MQTT broker and subscribes to a specific topic
 * to receive OTA updates on.
 * Send the message using the mosquitto tool:
 $ mosquitto_pub -h 192.168.1.1 -t 'ota/192.168.1.13' -r -f /tmp/build*.tmp/sensor-node.cpp.bin
 *
 */

#include <ESP8266WiFi.h>
#include <WiFiClient.h>
#include <PubSubClient.h>

// Replace with your Wifi SSID and passphrase
const char* ssid = "xxxxxxxx";
const char* pass = "<PASSWORD>";

// Replace with the IP address of your MQTT server
IPAddress server_ip(192,168,1,1);

void setup() {
  Serial.begin(115200);
  Serial.println("");
  Serial.print("Arduino MQTT OTA Test ");
  Serial.println(__TIMESTAMP__);

  Serial.printf("Sketch size: %u\n", ESP.getSketchSize());
  Serial.printf("Free size: %u\n", ESP.getFreeSketchSpace());
}

WiFiClient wclient;
PubSubClient client(wclient, server_ip);

void receive_ota(const MQTT::Publish& pub) {
  uint32_t startTime = millis();
  uint32_t size = pub.payload_len();
  if (size == 0)
    return;

  Serial.print("Receiving OTA of ");
  Serial.print(size);
  Serial.println(" bytes...");

  Serial.setDebugOutput(true);
  if (ESP.updateSketch(*pub.payload_stream(), size, true, false)) {
    Serial.println("Clearing retained message.");
    client.publish(MQTT::Publish(pub.topic(), "")
                   .set_retain());
    client.disconnect();

    Serial.printf("Update Success: %u\nRebooting...\n", millis() - startTime);
    ESP.restart();
    delay(10000);
  }
<commit_msg>Close the stream once the update is finished<commit_after>/*
 * Test/demonstration of over-the-air update of an ESP8266 using MQTT.
 *
 * This sketch connects to an MQTT broker and subscribes to a specific topic
 * to receive OTA updates on.
 * Send the message using the mosquitto tool:
 $ mosquitto_pub -h 192.168.1.1 -t 'ota/192.168.1.13' -r -f /tmp/build*.tmp/sensor-node.cpp.bin
 *
 */

#include <ESP8266WiFi.h>
#include <WiFiClient.h>
#include <PubSubClient.h>

// Replace with your Wifi SSID and passphrase
const char* ssid = "xxxxxxxx";
const char* pass = "<PASSWORD>";

// Replace with the IP address of your MQTT server
IPAddress server_ip(192,168,1,1);

void setup() {
  Serial.begin(115200);
  Serial.println("");
  Serial.print("Arduino MQTT OTA Test ");
  Serial.println(__TIMESTAMP__);

  Serial.printf("Sketch size: %u\n", ESP.getSketchSize());
  Serial.printf("Free size: %u\n", ESP.getFreeSketchSpace());
}

WiFiClient wclient;
PubSubClient client(wclient, server_ip);

void receive_ota(const MQTT::Publish& pub) {
  uint32_t startTime = millis();
  uint32_t size = pub.payload_len();
  if (size == 0)
    return;

  Serial.print("Receiving OTA of ");
  Serial.print(size);
  Serial.println(" bytes...");

  Serial.setDebugOutput(true);
  if (ESP.updateSketch(*pub.payload_stream(), size, true, false)) {
    pub.payload_stream()->stop();
    Serial.println("Clearing retained message.");
    client.publish(MQTT::Publish(pub.topic(), "")
                   .set_retain());
    client.disconnect();

    Serial.printf("Update Success: %u\nRebooting...\n", millis() - startTime);
    ESP.restart();
    delay(10000);
  }

{'fraction_non_alphanumeric': 0.15135471815633758, 'fraction_numerical': 0.030520087200249145, 'mean_word_length': 3.888888888888889, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 12, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 4, 'substrings_counts': 2, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5199386', 'n_tokens_mistral': 1200, 'n_tokens_neox': 1099, 'n_words': 280}