breadboard
documentación

Proyecto de ejemplo · Wi-Fi e internet

Uno R4 · HTTP y permiso de internet

WiFiS3 se conecta a BreadboardNet e imprime una respuesta HTTP en Serial. Por defecto funciona sin conexión con el entorno de pruebas. Para el tiempo en vivo, usuarios Pro con sesión iniciada pueden seleccionar la placa, elegir Real internet en Wi-Fi, consentir y reiniciar. La pasarela segura aporta HTTPS; el sketch usa la API habitual WiFiClient. Edita las coordenadas en Code.

El circuito Uno R4 · HTTP y permiso de internet tal como lo dibuja el simulador

Componentes del montaje

  • Arduino Uno R4

El código

Este sketch de Arduino C++ está en Code; inicia sesión y pulsa Compile & upload para compilar firmware real para la placa emulada.

// 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() {}

Licencia del firmware (en inglés)

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.

Informar de un problema de traducción

Proyectos relacionados