Arduino Uno WiFi Rev2 con Modbus

Salve a tutti .
Sto tentando di collegare una sonda di temperatura alla scheda e fare comunicare il valore letto a un PLC tramite modbus TCP.
Se utilizzo Arduino Uno con shield Ethernet la comunicazione funziona utilizzando la libreria MgsModbus ed ethernet

Quando passo il programma per arduino uno wifi REV2 con la libreria WifiNINA mi si connette alla rete wifi ma non comunica sul protocollo Modbus come con la libreria ethernet....

non riesco a capire cosa sbaglio... help

QUESTO LO CKETCH

#include <SPI.h>
#include <WiFiNINA.h>
#include "MgsModbus.h"

float temp;



MgsModbus Mb;

char ssid[] = "xxxxxxxxxxx";      //  your network SSID (name)
  char pass[] = "xxxxxxxxxxxx";   // your network password
  int status = WL_IDLE_STATUS;     // the Wifi radio's stat




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

// check for the presence of the shield:
  if (WiFi.status() == WL_NO_SHIELD) {
    Serial.println("WiFi shield not present");
    // don't continue:
    while (true);
  }

  String fv = WiFi.firmwareVersion();
  if ( fv != "1.1.0" )
    Serial.println("Please upgrade the firmware");

  // attempt to connect to Wifi network:
  while ( status != WL_CONNECTED) {
    Serial.print("Attempting to connect to WPA SSID: ");
    Serial.println(ssid);
    // Connect to WPA/WPA2 network:
    status = WiFi.begin(ssid, pass);

    // wait 10 seconds for connection:
    delay(10000);
  }
  
  // you're connected now, so print out the data:
  Serial.print("You're connected to the network");
  printCurrentNet();
  printWifiData();
  Serial.print("Connected to wifi. My address:");
  IPAddress myAddress = WiFi.localIP();
  Serial.println(myAddress);



  
}








void loop(){
  
  temp = analogRead(0);
 
  Mb.MbData[0] = temp;
        Serial.print(" ppm - ");
      
  Serial.println(analogRead(0));
 

 
  Mb.MbsRun();
  delay (2000);
  
}





void printWifiData() {
  // print your WiFi shield's IP address:
  IPAddress ip = WiFi.localIP();
  Serial.print("IP Address: ");
  Serial.println(ip);

  // print your MAC address:
  byte mac[6];
  WiFi.macAddress(mac);
  Serial.print("MAC address: ");
  Serial.print(mac[5], HEX);
  Serial.print(":");
  Serial.print(mac[4], HEX);
  Serial.print(":");
  Serial.print(mac[3], HEX);
  Serial.print(":");
  Serial.print(mac[2], HEX);
  Serial.print(":");
  Serial.print(mac[1], HEX);
  Serial.print(":");
  Serial.println(mac[0], HEX);

}

void printCurrentNet() {
  // print the SSID of the network you're attached to:
  Serial.print("SSID: ");
  Serial.println(WiFi.SSID());

  // print the MAC address of the router you're attached to:
  byte bssid[6];
  WiFi.BSSID(bssid);
  Serial.print("BSSID: ");
  Serial.print(bssid[5], HEX);
  Serial.print(":");
  Serial.print(bssid[4], HEX);
  Serial.print(":");
  Serial.print(bssid[3], HEX);
  Serial.print(":");
  Serial.print(bssid[2], HEX);
  Serial.print(":");
  Serial.print(bssid[1], HEX);
  Serial.print(":");
  Serial.println(bssid[0], HEX);

  // print the received signal strength:
  long rssi = WiFi.RSSI();
  Serial.print("signal strength (RSSI):");
  Serial.println(rssi);

  // print the encryption type:
  byte encryption = WiFi.encryptionType();
  Serial.print("Encryption Type:");
  Serial.println(encryption, HEX);
  Serial.println();
}

MGSMODBUS.H

#include "Arduino.h"

#include <SPI.h>
#include <WiFiNINA.h>

#ifndef MgsModbus_h
#define MgsModbus_h

#define MbDataLen 30 // length of the MdData array
#define MB_PORT 502

enum MB_FC {
  MB_FC_NONE                     = 0,
  MB_FC_READ_COILS               = 1,
  MB_FC_READ_DISCRETE_INPUT      = 2,
  MB_FC_READ_REGISTERS           = 3,
  MB_FC_READ_INPUT_REGISTER      = 4,
  MB_FC_WRITE_COIL               = 5,
  MB_FC_WRITE_REGISTER           = 6,
  MB_FC_WRITE_MULTIPLE_COILS     = 15,
  MB_FC_WRITE_MULTIPLE_REGISTERS = 16
};

class MgsModbus
{
public:
  // general
  MgsModbus();
  word MbData[MbDataLen]; // memory block that holds all the modbus user data
  boolean GetBit(word Number);
  boolean SetBit(word Number,boolean Data); // returns true when the number is in the MbData range
  // modbus master
  void Req(MB_FC FC, word Ref, word Count, word Pos);
  void MbmRun();
  IPAddress remSlaveIP;
  // modbus slave
  void MbsRun();  
  word GetDataLen();
private: 
  // general
  MB_FC SetFC(int fc);
  // modbus master
  uint8_t MbmByteArray[260]; // send and recieve buffer
  MB_FC MbmFC;
  int MbmCounter;
  void MbmProcess();
  word MbmPos;
  word MbmBitCount;
  //modbus slave
  uint8_t MbsByteArray[260]; // send and recieve buffer
  MB_FC MbsFC;
};

#endif

Buongiorno, :slight_smile:
essendo il tuo primo post, nel rispetto del regolamento della sezione Italiana del forum (… punto 13, primo capoverso), ti chiedo cortesemente di presentarti IN QUESTO THREAD (spiegando bene quali conoscenze hai di elettronica e di programmazione ... possibilmente evitando di scrivere solo una riga di saluto) e di leggere con molta attenzione tutto il su citato REGOLAMENTO ... Grazie. :slight_smile:

Guglielmo

P.S.: Ti ricordo che, purtroppo, fino a quando non sarà fatta la presentazione nell’apposito thread, nessuno ti potrà rispondere, quindi ti consiglio di farla al più presto. :wink:

ok... scusate.... inserita la presentazone e letto attentamente il regolamento....

.....forse ho risolto....

mancava lo start del server Mb all'intero del .cpp .......

certo che non è facile trovare il problema quando l'ide non ti da errori ma il programma non fa quello che deve

pleoni73:
... certo che non è facile trovare il problema quando l'ide non ti da errori ma il programma non fa quello che deve

... che è praticamente quello che succede sempre :smiley: :smiley: :smiley:

Guglielmo

pleoni73:
certo che non è facile trovare il problema quando l'ide non ti da errori ma il programma non fa quello che deve

Veramente che io sappia il programma fa sempre quello che gli hai chiesto di fare, ne più, ne meno, ma non ha facoltà di capire quello che invece intendevi fare... :slight_smile:

Ciao, Ale.

vero.... questa volta sono stato io a "non" dirgli di fare una cosa.... e poi mi lamento anche che non la fa :slight_smile: