arduino uno wifi rev2_sending data via udp + wifi

hey,

for the last two weeks i tried my best to get things working, but i failed so far and now i need help.
my coding experience is very little, so the best way for me is to frankenstein code snippets together - but that went wrong obviously.

what i want to do:
send data forth and back between arduino uno wifi rev2 and VVVV (a hybrid visual/textual live-programming environment which works finde for me)

because firmata is not supported for my board, i had to use rs232 and it actualy worked.
but when i need to send data over wifi it’s getting exponentially difficult for me.

i tested the wifi example code - it works!
i tested the example code for sending strings via udp - it worked forth, but not back (not sure, if i did something wrong)
when i put the code together nothing works as intended :confused:

variables

//-------------------------
//parsing stuff
const int bufferSize = 20; // how big is the buffer
 
char buffer[bufferSize];  // Serial buffer
char commandBuffer[10];   // array to store a command
char pinBuffer[3];        // array to store a pin number 
char valueBuffer[10];     // array to store a value
int ByteCount;            // how many bytes arrived

boolean ledON;            // state of the LED
int pinNumber;            // pinNumber
int value;                // brightness value

//------------------------------------------------------------------------------------------------------
//gyro, accelerometer
#include <Arduino_LSM6DS3.h>

//------------------------------------------------------------------------------------------------------
//Pins
int tiltPin  = 7;

//------------------------------------------------------------------------------------------------------
int delayTime  = 100;

//------------------------------------------------------------------------------------------------------
//WIFI stuff
#include <SPI.h>
#include <WiFiNINA.h>
#include <WiFiUdp.h>

int status = WL_IDLE_STATUS;
#include "arduino_secrets.h"            
///////please enter your sensitive data in the Secret tab/arduino_secrets.h
char ssid[] = SECRET_SSID;        // your network SSID (name)
char pass[] = SECRET_PASS;    // your network password (use for WPA, or use as key for WEP)
int keyIndex = 0;            // your network key Index number (needed only for WEP)

unsigned int localPort = 4444;      // local port to listen on

char packetBuffer[255]; //buffer to hold incoming packet
char  ReplyBuffer[] = "acknowledged";       // a string to send back

WiFiUDP Udp;

//------------------------------------------------------------------------------------------------------

setup and loop

void setup() 
{
  //----------------------------------------------------------------------------------------
  //pins definieren
  pinMode(tiltPin, INPUT);
    
  //----------------------------------------------------------------------------------------
  //start the serial communication at the speed of 9600 baud
  Serial.begin(9600);
  while (!Serial);

  if (!IMU.begin()) {
    Serial.println("Failed to initialize IMU!");
    while (1);
  }  

  //----------------------------------------------------------------------------------------
  //WIFI
  // check for the WiFi module:
  if (WiFi.status() == WL_NO_MODULE) {
    Serial.println("Communication with WiFi module failed!");
    // don't continue
    while (true);
  }

  String fv = WiFi.firmwareVersion();
  if (fv < WIFI_FIRMWARE_LATEST_VERSION) {
    Serial.println("Please upgrade the firmware");
  }

  // attempt to connect to Wifi network:
  while (status != WL_CONNECTED) {
    Serial.print("Attempting to connect to SSID: ");
    Serial.println(ssid);
    // Connect to WPA/WPA2 network. Change this line if using open or WEP network:
    status = WiFi.begin(ssid, pass);

    // wait 10 seconds for connection:
//    delay(10000); //what is this for??? works fine without o.O
  }
  Serial.println("Connected to wifi");
  printWifiStatus();

  Serial.println("\nStarting connection to server...");
  // if you get a connection, report back via serial:
  Udp.begin(localPort);

  //----------------------------------------------------------------------------------------
  //header im searial monitor
  //einheiten, reihenfolge der variablen
  
  Serial.print("Accelerometer sample rate = ");
  Serial.print(IMU.accelerationSampleRate());
  Serial.println(" Hz");
  Serial.println(" - in G's");
  Serial.println();
  
  Serial.print("Gyroscope sample rate = ");
  Serial.print(IMU.gyroscopeSampleRate());
  Serial.println(" Hz");
  Serial.println("xG, yG, zG - in degrees/second");
  Serial.println();

  Serial.println("xA, yA, zA, xG, yG, zG, tilt");
  Serial.println();
}

//------------------------------------------------------------------------------------------------------
//------------------------------------------------------------------------------------------------------

void loop()
{

    //send some data back to vvvv
    //the values are encoded as ASCII characters
   
    //accelerometer
    float xA, yA, zA;
    if (IMU.accelerationAvailable()) {
    IMU.readAcceleration(xA, yA, zA);
/*    
      Serial.print(xA);
      Serial.print(",");
      Serial.print(yA);
      Serial.print(",");
      Serial.print(zA);
      Serial.print(","); */ 
    }
    
    //gyroscope
    float xG, yG,zG;
    if(IMU.gyroscopeAvailable()) {
      IMU.readGyroscope(xG, yG, zG);
/*
      Serial.print(xG);
      Serial.print(",");
      Serial.print(yG);
      Serial.print(",");
      Serial.print(zG);
      Serial.print(",");  */ 
    }
   
    //tiltSensor
    bool tilt;
    tilt = digitalRead(tiltPin);
//    Serial.print(tilt);

    //the last print command sends '\r\n' at the end
    //this defines the end of the message
//    Serial.println();

    //---------------------------------------------------------------
    //send sensorData via udp
    char sensorData = char(xA) + char(",") + char(yA) + char(",") + char(zA) + char(",") +
                      char(xG) + char(",") + char(yG) + char(",") + char(zG) + char(",") +
                      char(tilt);
    Serial.println("sensorData as String: "+sensorData);
    
    Udp.beginPacket(Udp.remoteIP(), Udp.remotePort());
Serial.println(Udp.remoteIP()+" <-- Udp.remoteIP | Udp.remotePort --> "+Udp.remotePort()); //why are they null/empty in serialMonitor?
    Udp.write(sensorData);
    Udp.endPacket();
    
    Serial.println("sensorData sent!");
    Serial.println();

    //---------------------------------------------------------------

    //short break
    delay(100);
      
/*
    //read the data and parse it
    SerialParser();
    
    //if something arrived 
    if (ByteCount > 0) 
    {
      //send some data back to vvvv
      //the values are encoded as ASCII characters
      //the last print command sends '\r\n' at the end
      //this defines the end of the message
      Serial.print(millis());
      Serial.print(",");
      Serial.print(pinNumber);
      Serial.print(",");
      Serial.println(value);
      
      //set the state of the pin according to the string received from vvvv 
      if (ledON)
      {
        //write PWM signal value to the pin
        analogWrite(pinNumber, value);
      }
      else
      {
       //write digital value to the pin
       //setting 0V in this example;
       digitalWrite(pinNumber, LOW);
      }
    } 
*/  
}

pls also note, that my IDE behaves a little bit strange.
uploading works once, but not twice. the upload stucks and i think it has to do something with busy ports (had this problem before). maybe the problems have something to do with each other.

when closing the serial monitor, IDE and monitor are freezing for about 10 seconds

my solution so far: reconnecting the arduino evry time i need to upload

with verbose in preferences:

Arduino: 1.8.12 (Windows 10), Board: "Arduino Uno WiFi Rev2, ATMEGA328"

C:\Users\WomirAig\Desktop\RP_arduino\dragonStaff_02_udp_wifi\Main.ino: In function 'void loop()':

C:\Users\WomirAig\Desktop\RP_arduino\dragonStaff_02_udp_wifi\Main.ino:115:42: warning: cast from 'const char*' to 'char' loses precision [-fpermissive]

     char sensorData = char(xA) + char(",") + char(yA) + char(",") + char(zA) + char(",") +

                                          ^

C:\Users\WomirAig\Desktop\RP_arduino\dragonStaff_02_udp_wifi\Main.ino:115:65: warning: cast from 'const char*' to 'char' loses precision [-fpermissive]

     char sensorData = char(xA) + char(",") + char(yA) + char(",") + char(zA) + char(",") +

                                                                 ^

C:\Users\WomirAig\Desktop\RP_arduino\dragonStaff_02_udp_wifi\Main.ino:115:88: warning: cast from 'const char*' to 'char' loses precision [-fpermissive]

     char sensorData = char(xA) + char(",") + char(yA) + char(",") + char(zA) + char(",") +

                                                                                        ^

C:\Users\WomirAig\Desktop\RP_arduino\dragonStaff_02_udp_wifi\Main.ino:116:42: warning: cast from 'const char*' to 'char' loses precision [-fpermissive]

                       char(xG) + char(",") + char(yG) + char(",") + char(zG) + char(",") +

                                          ^

C:\Users\WomirAig\Desktop\RP_arduino\dragonStaff_02_udp_wifi\Main.ino:116:65: warning: cast from 'const char*' to 'char' loses precision [-fpermissive]

                       char(xG) + char(",") + char(yG) + char(",") + char(zG) + char(",") +

                                                                 ^

C:\Users\WomirAig\Desktop\RP_arduino\dragonStaff_02_udp_wifi\Main.ino:116:88: warning: cast from 'const char*' to 'char' loses precision [-fpermissive]

                       char(xG) + char(",") + char(yG) + char(",") + char(zG) + char(",") +

                                                                                        ^

Sketch uses 17972 bytes (36%) of program storage space. Maximum is 48640 bytes.
Global variables use 738 bytes (12%) of dynamic memory, leaving 5406 bytes for local variables. Maximum is 6144 bytes.
C:\Program Files (x86)\Arduino\hardware\tools\avr/bin/avrdude -CC:\Program Files (x86)\Arduino\hardware\tools\avr/etc/avrdude.conf -v -patmega4809 -cxplainedmini_updi -Pusb -b115200 -e -D -Uflash:w:C:\Users\WomirAig\AppData\Local\Temp\arduino_build_333611/dragonStaff_02_udp_wifi.ino.hex:i -Ufuse2:w:0x01:m -Ufuse5:w:0xC9:m -Ufuse8:w:0x02:m -Uflash:w:C:\Users\WomirAig\AppData\Local\Arduino15\packages\arduino\hardware\megaavr\1.8.6/bootloaders/atmega4809_uart_bl.hex:i 

avrdude: Version 6.3-20190619
         Copyright (c) 2000-2005 Brian Dean, http://www.bdmicro.com/
         Copyright (c) 2007-2014 Joerg Wunsch

         System wide configuration file is "C:\Program Files (x86)\Arduino\hardware\tools\avr/etc/avrdude.conf"

         Using Port                    : usb
         Using Programmer              : xplainedmini_updi
         Overriding Baud Rate          : 115200
An error occurred while uploading the sketch

This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.