http_post_imu.ino

Arduino Nicla Vision · File : http_post_imu.ino · Language : Arduino · Use case : Envoyer l’IMU vers un serveur HTTP en Wi-Fi

The Nicla Vision becomes a connected probe: every second a JSON frame of accelerations is POSTed over HTTP to a LAN server through the on-board Wi-Fi module. A plain `nc -l -p 8080` validates the sensor-to-network chain.

Hardware

An Arduino Nicla Vision (STM32H7 M7+M4, 23×23 mm) with GC2145 camera, LSM6DSOX IMU, PDM mic, ToF (VL53Lx), ESP32 Wi-Fi/BLE module and RGB LED (LEDR/G/B). A 2.4 GHz Wi-Fi network (the module does not see 5 GHz), a server or PC on the same network, the destination IP.

Wiring

No wiring. Place the board within coverage; the on-board antenna loses range behind a metal enclosure.

How it works

WiFi.begin links up; WiFiClient opens the TCP socket and the POST request is hand-written (headers + 48-byte JSON body). Content-Length must match the body, hence the sized snprintf.

Running it

Programmed from the Arduino IDE (ArduinoCore-mbed, NICLA_VISION target) over USB-C; Camera, PDM, Arduino_LSM6DSOX, WiFiNINA and ArduinoBLE libraries provided.

Variants

Move to HTTPS (WiFiSSLClient), batch 60 readings per request to spare the radio, or feed the stream to MQTT/Arduino Cloud instead of raw HTTP.

http_post_imu.ino

// Passerelle Wi-Fi : une ligne JSON d'IMU postée chaque seconde.

#include <WiFiNINA.h>
#include <Arduino_LSM6DSOX.h>

const char *SSID = "votre-reseau";
const char *PASS = "votre-cle";
const char *SERVEUR = "192.168.1.42";
const int PORT = 8080;

WiFiClient client;

void setup() {
  Serial.begin(115200);
  WiFi.begin(SSID, PASS);
  while (WiFi.status() != WL_CONNECTED) { delay(500); }
  if (!IMU.begin()) { while (1) { ; } }
}

void loop() {
  float ax, ay, az;
  if (IMU.accelerationAvailable()) {
    IMU.readAcceleration(ax, ay, az);

    if (client.connect(SERVEUR, PORT)) {
      client.print("POST /imu HTTP/1.1\r\nHost: ");
      client.print(SERVEUR);
      client.print("\r\nContent-Type: application/json");
      client.print("\r\nContent-Length: 48\r\n\r\n");
      char corps[49];
      snprintf(corps, sizeof(corps),
               "{\"ax\":%.3f,\"ay\":%.3f,\"az\":%.3f}", ax, ay, az);
      client.print(corps);
      client.stop();
      Serial.println("POST envoyé");
    } else {
      Serial.println("Serveur injoignable");
    }
  }
  delay(1000);
}

← Back to the board