   serial.printf("Address: %s\n", WiFi.localIP().toString().c_str());
 }
 
-static WiFiClient connect_client() {
-  WiFiClient client;
-  if (!client.connect(HOST, PORT))
-    fatal_error("Connection to host failed");
-  return client;
-}
-
 static void delete_messages() {
   auto size = pending_messages_queue::storage_size(MAX_PENDING_MESSAGES);
   for (size_t i = 0; i < size; i++)

static constexpr size_t MAX_PENDING_MESSAGES = 4;
static constexpr size_t SAMPLES_PER_MESSAGE = 8;

// Sleep time: 30s (measured in us)
static constexpr unsigned SLEEP_TIME = 30 * 1000 * 1000;

struct message {
  time_t time;
  unsigned short samples[SAMPLES_PER_MESSAGE];
};

typedef persistent_vector<message> pending_messages_queue;
static pending_messages_queue* pending_messages;

static WiFiUDP Udp;
static constexpr unsigned short local_port = 8888;

static ntp_client ntp(Udp);

void setup() {
  Serial.begin(115200);

  serial.printf("Attempting to send %d messages\n",
      pending_messages->size());

  while (!pending_messages->empty()) {
    auto& msg = pending_messages->front();
    if (!send_message(msg))
      break;
    pending_messages->pop();
  }
}

static bool send_message(const message& msg) {
  // XXX use the same connection for all messages ???
  WiFiClient client;
  if (!client.connect(HOST, PORT))
    return false;

  // TODO check result of prints
  client.print("sensor-id: ");
  client.println(SENSOR_ID);
  client.print("time: ");
  client.println(msg.time);

//      serial.printf("time: %d\n", msg.time);
//    for (size_t s = 0; s < SAMPLES_PER_MESSAGE; s++)
//      serial.printf("sample%d: %d\n", s, msg.samples[s]);

  return true;
}

static void print_date() {
