breadboard
Example project · Wi-Fi & internet

Uno R4 · HTTP and internet consent

WiFiS3 joins BreadboardNet and prints one HTTP response in Serial. It runs offline against the sandbox by default. For live weather, signed-in Pro users can select the board, choose Real internet in Wi-Fi, give consent, then restart. The secure gateway supplies HTTPS; the sketch uses the ordinary WiFiClient API. Edit the coordinates in Code.

The Uno R4 · HTTP and internet consent circuit as rendered by the simulator

What's on the bench

  • Arduino Uno R4
  • Battery

How it's wired

  • Battery · pos→Arduino Uno R4 · 5v
  • Battery · neg→Arduino Uno R4 · gnd

The code

This Arduino C++ sketch lives in the Code tab; sign in and press Compile & upload to build real firmware for the emulated board.

// SPDX-License-Identifier: MIT
// UNO R4 WiFi: one HTTP request using the public WiFiS3 client.
// Sandbox is the default. In the board's Wi-Fi inspector, signed-in Pro
// users can select Real internet, give consent, then restart this sketch.
// The secure gateway supplies HTTPS to the approved destination. This
// sketch uses WiFiClient, not WiFiSSLClient or native board TLS.
#include <WiFiS3.h>

const char HOST[] = "api.open-meteo.com";
const char PATH[] = "/v1/forecast?latitude=51.5&longitude=-0.12&current_weather=true";
WiFiClient client;

void setup() {
  Serial.begin(115200);
  Serial.println("UNO R4 HTTP: sandbox by default");
  Serial.println("Real internet: select the board, enable it in Wi-Fi, consent, then restart.");
  if (WiFi.begin("BreadboardNet") != WL_CONNECTED) {
    Serial.println("Wi-Fi join failed");
    return;
  }
  if (!client.connect(HOST, 80)) {
    Serial.println("HTTP connection failed");
    client.stop();
    return;
  }
  client.print("GET ");
  client.print(PATH);
  client.print(" HTTP/1.1\r\nHost: ");
  client.print(HOST);
  client.print("\r\nConnection: close\r\n\r\n");
  const unsigned long started = millis();
  unsigned int printed = 0;
  while (millis() - started < 15000 && (client.connected() || client.available())) {
    while (client.available() && millis() - started < 15000) {
      const int value = client.read();
      if (value >= 0 && printed < 4096) {
        Serial.write(static_cast<uint8_t>(value));
        printed++;
      }
    }
    delay(1);
  }
  const bool timedOut = millis() - started >= 15000;
  client.stop();
  Serial.println();
  Serial.println(timedOut ? "HTTP response timed out" : "HTTP request finished");
  if (printed == 4096) Serial.println("Serial output limited to 4096 bytes");
}

void loop() {}

Firmware licence

Notice: this firmware uses the LGPL-licensed Arduino core library

arduino-unor4wifi-http-gallery.bin is statically linked with ArduinoCore-renesas 1.6.0, in Breadboard's port of its UNO R4 WiFi variant to Renesas FSP 5.3.0. Parts of that core are licensed under the GNU Lesser General Public License, version 2.1 or (at your option) any later version ("the Library"). Breadboard distributes this firmware under terms that permit you to modify the work for your own use and to reverse engineer it for debugging such modifications.

Related projects