Aduino - MSSQL

Selamlar brsbnkc,

Kütüphaneyi Arduino Uno Wifi rev.2 ile de kullanabilirsin fakat esp için verdiğim örnek kodda ufak değişiklikler yapman gerekiyor. Boş vaktimde bir örnek eklemeye çalışacağım.

Yardımcı olursan çok sevinirim. Mevcutta ki kod bloğum aşağıda paylaşıyorum, ekran çıktısı olarakta initializin tdslite yazısında kalıp devam etmiyor.
Attempting to connect to WPA SSID: FoxTrot.com.tr
You're connected to the networkSSID: FoxTrot.com.tr
BSSID: signal strength (RSSI):-50
Encryption Type:4


IP Address: 192.168.90.26
Initializing tdslite

Kod:
/**
 * ____________________________________________________
 * Example code for illustrating basic SQL operations
 *
 * Prerequisites:
 * - A board with an Ethernet shield
 * - A running SQL server (*)
 * - tdslite library installed via Library Manager
 *
 * (*) The development environment container has an embedded
 *     SQL server exposed to host at port 14333.
 *
 * Tested with Arduino Uno w/ Ethernet shield.
 *
 * @file   initialize-library.ino
 * @author mkg <[email protected]>
 * @date   06.01.2023
 *
 * SPDX-License-Identifier:    MIT
 * ____________________________________________________
 */
//#include <Ethernet.h>
#include <WiFiNINA.h>
#include <tdslite.h>
#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 status = WL_IDLE_STATUS;     // the WiFi radio's status
// Serial output uses ~175 bytes of SRAM space
// and ~840 bytes of program memory.
#define SKETCH_ENABLE_SERIAL_OUTPUT
#if defined SKETCH_ENABLE_SERIAL_OUTPUT
#define SERIAL_PRINTF_PROGMEM(FMTPM, ...)                                                          \
    char buf [64] = {};                                                                            \
    snprintf_P(buf, sizeof(buf), FMTPM, ##__VA_ARGS__);                                            \
    Serial.print(buf);
#define SERIAL_PRINTF(FMTSTR, ...)                                                                 \
    [&]() {                                                                                        \
        /* Save format string into program */                                                      \
        /* memory to save flash space */                                                           \
        static const char __fmtpm [] PROGMEM = FMTSTR;                                             \
        SERIAL_PRINTF_PROGMEM(__fmtpm, ##__VA_ARGS__)                                              \
    }()
#define SERIAL_PRINTLNF_PROGMEM(FMTPM, ...)                                                        \
    SERIAL_PRINTF_PROGMEM(FMTPM, ##__VA_ARGS__)                                                    \
    Serial.println("");                                                                            \
    Serial.flush()
#define SERIAL_PRINTLNF(FMTSTR, ...)                                                               \
    SERIAL_PRINTF(FMTSTR, ##__VA_ARGS__);                                                          \
    Serial.println("");                                                                            \
    Serial.flush()
#define SERIAL_PRINT_U16_AS_MB(U16SPAN)                                                            \
    [](tdsl::u16char_view v) {                                                                     \
        for (const auto ch : v) {                                                                  \
            Serial.print(static_cast<char>(ch));                                                   \
        }                                                                                          \
    }(U16SPAN)
#else
#define SERIAL_PRINTF_PROGMEM(FMTPM, ...)
#define SERIAL_PRINTF(FMTSTR, ...)
#define SERIAL_PRINTLNF_PROGMEM(FMTPM, ...)
#define SERIAL_PRINTLNF(FMTSTR, ...)
#define SERIAL_PRINT_U16_AS_MB(U16SPAN)
#endif
// --------------------------------------------------------------------------------
/**
 * The network buffer.
 *
 * The library will use this buffer for network I/O.
 *
 * The buffer must be at least 512 bytes in size.
 * In order to have some headroom for fragmentation
 * it is recommended to allocate 768 bytes at least.
 *
 * The actual size need for network buffer is depends
 * on your use case.
 */
tdsl::uint8_t net_buf [4096] = {};
// --------------------------------------------------------------------------------
/**
 * The tdslite driver object.
 *
 * tdsl::arduino_driver class is a templated type
 * where the template argument is the TCP client
 * implementation compatible with Arduino's
 * EthernetClient interface.
 *
 * The client will be initialized internally.
 */
tdsl::arduino_driver<WiFiClient> driver{net_buf};
// --------------------------------------------------------------------------------
/**
 * MAC address for the ethernet interface
 */
//byte mac [] = {0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xEE};
// --------------------------------------------------------------------------------
/**
 * IP address for the ethernet interface.
 * Change it according to your network address space
 */
//IPAddress ip(192, 168, 1, 244);
// --------------------------------------------------------------------------------
/**
 * The setup function initializes Serial output,
 * Ethernet interface, tdslite library and then
 * the database tables.
 */
void setup() {
#ifdef SKETCH_ENABLE_SERIAL_OUTPUT
    Serial.begin(112500);
    while (!Serial)
        ;
#endif
    //////////////////////////
    // Initialize ethernet interface
    //////////////////////////
    // The reason we're not using DHCP here is, this is
    // a minimal example with absolute minimum space
    // requirements, so the code can work on boards with
    // tight memory constraints (i.e. Arduino Uno/Nano)
    //
    // DHCP requires UDP, UDP requires extra space.
    // We're not using DHCP here to save some program
    // memory and SRAM space.
    SERIAL_PRINTLNF("Initializing ethernet interface");
    // Try to configure ethernet interface
    // with given MAC and IP
  
   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 WPA SSID: ");
    Serial.println(ssid);
    // Connect to WPA/WPA2 network:
    status = WiFi.begin(ssid, pass);
    // wait 10 seconds for connection:
    delay(10000);
  }
  Serial.print("You're connected to the network");
  printCurrentNet();
  printWifiData();
    //////////////////////////
    // Initialize tdslite
    //////////////////////////
    // Declare a connection parameters struct. We will fill this struct
    // with the details of the SQL server/database we want to connect to.
    // We're using progmem_connection_parameters here, because we want to
    // store database connection parameters in program memory in order to
    // save some precious SRAM space.
    decltype(driver)::progmem_connection_parameters params;
    // Server's hostname or IP address.
    params.server_name = TDSL_PMEMSTR("192.168.90.7"); // WL
    // SQL server port number
    params.port        = 1433; // default port is 1433
    // SQL server login user
    params.user_name   = TDSL_PMEMSTR("sa");
    // SQL server login user password
    params.password    = TDSL_PMEMSTR("xx123xx123xx");
    // Client name(optional)
    params.client_name = TDSL_PMEMSTR("arduino uno");
    // App name(optional)
    params.app_name    = TDSL_PMEMSTR("initialize library example");
    // Database name(optional)
    params.db_name     = TDSL_PMEMSTR("master");
    // TDS packet size
    // Recommendation: Half of the network buffer.
    // This is the PDU size that TDS protocol will use.
    // Given that the example has 768 bytes of network buffer space,
    // we set this to 512 to allow some headroom for fragmentation.
    params.packet_size = {2048};
    SERIAL_PRINTLNF("Initializing tdslite");
    // Try to connect with given parameters. If connection succeeds,
    // the `result` will be e_driver_error_code::success. Otherwise,
    // the connection attempt has failed.
    auto result = driver.connect(params);
    if (not(decltype(driver)::e_driver_error_code::success == result)) {
        SERIAL_PRINTLNF("Error: Database connection failed!");
        // Database connection failed.
        while (true) {
           SERIAL_PRINTLNF("Error: Database connection failed!,Rerty");
            delay(1000);
        }
    }
    SERIAL_PRINTLNF("Setup complete, all is good!");
}
// --------------------------------------------------------------------------------
/**
 * The loop function does nothing.
 */
void loop() {
    delay(1000);
}
void printWifiData() {
  // print your board'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: ");
  //printMacAddress(mac);
}
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: ");
  //printMacAddress(bssid);
  // 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();
}

Kod kısmını revize ettim
 
Son düzenleme:
Yardımcı olursan çok sevinirim. Mevcutta ki kod bloğum aşağıda paylaşıyorum, ekran çıktısı olarakta initializin tdslite yazısında kalıp devam etmiyor.
Attempting to connect to WPA SSID: FoxTrot.com.tr
You're connected to the networkSSID: FoxTrot.com.tr
BSSID: signal strength (RSSI):-50
Encryption Type:4


IP Address: 192.168.90.26
Initializing tdslite

Kod:
/**
 * ____________________________________________________
 * Example code for illustrating basic SQL operations
 *
 * Prerequisites:
 * - A board with an Ethernet shield
 * - A running SQL server (*)
 * - tdslite library installed via Library Manager
 *
 * (*) The development environment container has an embedded
 *     SQL server exposed to host at port 14333.
 *
 * Tested with Arduino Uno w/ Ethernet shield.
 *
 * @file   initialize-library.ino
 * @author mkg <[email protected]>
 * @date   06.01.2023
 *
 * SPDX-License-Identifier:    MIT
 * ____________________________________________________
 */

//#include <Ethernet.h>
#include <WiFiNINA.h>
#include <tdslite.h>

#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 status = WL_IDLE_STATUS;     // the WiFi radio's status
// Serial output uses ~175 bytes of SRAM space
// and ~840 bytes of program memory.
#define SKETCH_ENABLE_SERIAL_OUTPUT

#if defined SKETCH_ENABLE_SERIAL_OUTPUT

#define SERIAL_PRINTF_PROGMEM(FMTPM, ...)                                                          \
    char buf [64] = {};                                                                            \
    snprintf_P(buf, sizeof(buf), FMTPM, ##__VA_ARGS__);                                            \
    Serial.print(buf);

#define SERIAL_PRINTF(FMTSTR, ...)                                                                 \
    [&]() {                                                                                        \
        /* Save format string into program */                                                      \
        /* memory to save flash space */                                                           \
        static const char __fmtpm [] PROGMEM = FMTSTR;                                             \
        SERIAL_PRINTF_PROGMEM(__fmtpm, ##__VA_ARGS__)                                              \
    }()

#define SERIAL_PRINTLNF_PROGMEM(FMTPM, ...)                                                        \
    SERIAL_PRINTF_PROGMEM(FMTPM, ##__VA_ARGS__)                                                    \
    Serial.println("");                                                                            \
    Serial.flush()

#define SERIAL_PRINTLNF(FMTSTR, ...)                                                               \
    SERIAL_PRINTF(FMTSTR, ##__VA_ARGS__);                                                          \
    Serial.println("");                                                                            \
    Serial.flush()

#define SERIAL_PRINT_U16_AS_MB(U16SPAN)                                                            \
    [](tdsl::u16char_view v) {                                                                     \
        for (const auto ch : v) {                                                                  \
            Serial.print(static_cast<char>(ch));                                                   \
        }                                                                                          \
    }(U16SPAN)
#else
#define SERIAL_PRINTF_PROGMEM(FMTPM, ...)
#define SERIAL_PRINTF(FMTSTR, ...)
#define SERIAL_PRINTLNF_PROGMEM(FMTPM, ...)
#define SERIAL_PRINTLNF(FMTSTR, ...)
#define SERIAL_PRINT_U16_AS_MB(U16SPAN)
#endif

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

/**
 * The network buffer.
 *
 * The library will use this buffer for network I/O.
 *
 * The buffer must be at least 512 bytes in size.
 * In order to have some headroom for fragmentation
 * it is recommended to allocate 768 bytes at least.
 *
 * The actual size need for network buffer is depends
 * on your use case.
 */
tdsl::uint8_t net_buf [4096] = {};

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

/**
 * The tdslite driver object.
 *
 * tdsl::arduino_driver class is a templated type
 * where the template argument is the TCP client
 * implementation compatible with Arduino's
 * EthernetClient interface.
 *
 * The client will be initialized internally.
 */
tdsl::arduino_driver<WiFiClient> driver{net_buf};

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

/**
 * MAC address for the ethernet interface
 */
//byte mac [] = {0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xEE};

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

/**
 * IP address for the ethernet interface.
 * Change it according to your network address space
 */
//IPAddress ip(192, 168, 1, 244);

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

/**
 * The setup function initializes Serial output,
 * Ethernet interface, tdslite library and then
 * the database tables.
 */
void setup() {

#ifdef SKETCH_ENABLE_SERIAL_OUTPUT
    Serial.begin(112500);
    while (!Serial)
        ;
#endif

    //////////////////////////
    // Initialize ethernet interface
    //////////////////////////

    // The reason we're not using DHCP here is, this is
    // a minimal example with absolute minimum space
    // requirements, so the code can work on boards with
    // tight memory constraints (i.e. Arduino Uno/Nano)
    //
    // DHCP requires UDP, UDP requires extra space.
    // We're not using DHCP here to save some program
    // memory and SRAM space.

    SERIAL_PRINTLNF("Initializing ethernet interface");

    // Try to configure ethernet interface
    // with given MAC and IP
  
   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 WPA SSID: ");
    Serial.println(ssid);
    // Connect to WPA/WPA2 network:
    status = WiFi.begin(ssid, pass);

    // wait 10 seconds for connection:
    delay(10000);
  }
  Serial.print("You're connected to the network");
  printCurrentNet();
  printWifiData();
    //////////////////////////
    // Initialize tdslite
    //////////////////////////

    // Declare a connection parameters struct. We will fill this struct
    // with the details of the SQL server/database we want to connect to.
    // We're using progmem_connection_parameters here, because we want to
    // store database connection parameters in program memory in order to
    // save some precious SRAM space.
    decltype(driver)::progmem_connection_parameters params;
    // Server's hostname or IP address.
    params.server_name = TDSL_PMEMSTR("192.168.90.7"); // WL
    // SQL server port number
    params.port        = 14333; // default port is 1433
    // SQL server login user
    params.user_name   = TDSL_PMEMSTR("sa");
    // SQL server login user password
    params.password    = TDSL_PMEMSTR("xx123xx123xx");
    // Client name(optional)
    params.client_name = TDSL_PMEMSTR("arduino uno");
    // App name(optional)
    params.app_name    = TDSL_PMEMSTR("initialize library example");
    // Database name(optional)
    params.db_name     = TDSL_PMEMSTR("master");
    // TDS packet size
    // Recommendation: Half of the network buffer.
    // This is the PDU size that TDS protocol will use.
    // Given that the example has 768 bytes of network buffer space,
    // we set this to 512 to allow some headroom for fragmentation.
    params.packet_size = {2048};

    SERIAL_PRINTLNF("Initializing tdslite");

    // Try to connect with given parameters. If connection succeeds,
    // the `result` will be e_driver_error_code::success. Otherwise,
    // the connection attempt has failed.
    driver.connect(params);

    /*if (not(decltype(driver)::e_driver_error_code::success == result)) {
        SERIAL_PRINTLNF("Error: Database connection failed!");
        // Database connection failed.
        while (true) {
           SERIAL_PRINTLNF("Error: Database connection failed!,Rerty");
            delay(1000);
        }
    }*/
    SERIAL_PRINTLNF("Setup complete, all is good!");
}

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

/**
 * The loop function does nothing.
 */
void loop() {
    delay(1000);
}
void printWifiData() {
  // print your board'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: ");
  //printMacAddress(mac);
}

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: ");
  //printMacAddress(bssid);

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

params.port = 14333; // default port is 1433

Port numarasını aşağıdaki gibi 1433 olarak güncelleyip dener misin?

params.port = 1433;
 
Denemiştim onu zaten geçmişte ki cevaplara bakarak tekrar denedim fakat aynı sorun devam ediyor.


params.server_name = TDSL_PMEMSTR("192.168.90.7"); // WL
// SQL server port number
params.port = 14333; // default port is 1433
// SQL server login user
params.user_name = TDSL_PMEMSTR("sa");
// SQL server login user password
params.password = TDSL_PMEMSTR("xx123xx123xx");
// Client name(optional)
params.client_name = TDSL_PMEMSTR("arduino uno");
// App name(optional)
params.app_name = TDSL_PMEMSTR("initialize library example");
// Database name(optional)
params.db_name = TDSL_PMEMSTR("master");


Veritabanına yukarıdaki bilgileri kullanarak başka bir cihazdan bağlanmayı denedin mi, bilgilerin doğru olduğundan emin misin?

Eğer eminsen veritabanı sunucusu üzerinden arduino uno ile login olmayı denerken wireshark ile pcap alıp paylaşabilir misin?
 
Wireshark için pcap gönderdim fakat çok hakim değilim tds olarak filtre koydum diğer bilgisayarlardan SQL management ile de bağlanıyorum. Veya mevcutta bilgisayarımda ki c# projesinden de bağlanıyorum
params.server_name = TDSL_PMEMSTR("192.168.90.7"); // WL
// SQL server port number
params.port = 14333; // default port is 1433
// SQL server login user
params.user_name = TDSL_PMEMSTR("sa");
// SQL server login user password
params.password = TDSL_PMEMSTR("xx123xx123xx");
// Client name(optional)
params.client_name = TDSL_PMEMSTR("arduino uno");
// App name(optional)
params.app_name = TDSL_PMEMSTR("initialize library example");
// Database name(optional)
params.db_name = TDSL_PMEMSTR("master");


Veritabanına yukarıdaki bilgileri kullanarak başka bir cihazdan bağlanmayı denedin mi, bilgilerin doğru olduğundan emin misin?

Eğer eminsen veritabanı sunucusu üzerinden arduino uno ile login olmayı denerken wireshark ile pcap alıp paylaşabilir misin?
Wireshark için pcap gönderdim fakat çok hakim değilim tds olarak filtre koydum diğer bilgisayarlardan SQL management ile de bağlanıyorum. Veya mevcutta bilgisayarımda ki c# projesinden de bağlanıyorum
 

Ekli dosyalar

  • wireshark.zip
    9.1 MB · Görüntüleme: 2
  • wireshark.zip
    9.1 MB · Görüntüleme: 1
Selamlar,

Pcap dosyaları için teşekkürler, login başarılı bir şekilde gerçekleşmiş, fakat enteresan bir şekilde kütüphane cevap mesajına tepki vermiyor gibi gözüküyor. Elindeki board'dan bugün sipariş geçip hafta içerisinde problemin ne olduğuna daha detaylı bakacağım.
 
Selamlar,

Pcap dosyaları için teşekkürler, login başarılı bir şekilde gerçekleşmiş, fakat enteresan bir şekilde kütüphane cevap mesajına tepki vermiyor gibi gözüküyor. Elindeki board'dan bugün sipariş geçip hafta içerisinde problemin ne olduğuna daha detaylı bakacağım.

Çok sevinirim benim için çok önemli teşekkür ederim.
 
Selamlar,

Cihaz bugün elime ulaştı ve sorunu tespit edebilme şansım oldu. Problem Arduino Uno WiFi r2'nin kullandığı WiFiNina kütüphanesinin WiFiClient.read(buf,size) fonksiyonunun çalışma şeklinde. Diğer ethernet/wifi kütüphaneleri .read(buf,size) fonksiyonu için "`buf` alanına `size` byte veri kopyalar" garantisini veriyor, lakin WiFiNina diğer ethernet/wifi kütüphanelerinden farklı olarak Arduino Uno için 64 byte'lik bir ara buffer kullanarak alttaki kat gelen veriyi en fazla 64 byte'lik parçalar olacak şekilde çekmesini bekliyor. Bu belirttiğim çalışma şekli de tdslite'in arduino network kodu ile şu anda uyumlu değil.

Sorunun çözümüne gelirsek, kütüphanede ufak bir revizyon yaptım ve önümüzdeki günlerde diğer board'larda da test ettikten sonra yeni resmi sürüm çıkacağım. Kütüphanenin revize edilmiş halini zip olarak ekte paylaşıyorum, test edip doğrulayabilirsen güzel olur.

Yeni sürümü resmi olarak yayımladığımda buradan bilgilendiriyor olacağım.
 

Ekli dosyalar

  • tdslite.zip
    128.6 KB · Görüntüleme: 3
Selamlar,

Cihaz bugün elime ulaştı ve sorunu tespit edebilme şansım oldu. Problem Arduino Uno WiFi r2'nin kullandığı WiFiNina kütüphanesinin WiFiClient.read(buf,size) fonksiyonunun çalışma şeklinde. Diğer ethernet/wifi kütüphaneleri .read(buf,size) fonksiyonu için "`buf` alanına `size` byte veri kopyalar" garantisini veriyor, lakin WiFiNina diğer ethernet/wifi kütüphanelerinden farklı olarak Arduino Uno için 64 byte'lik bir ara buffer kullanarak alttaki kat gelen veriyi en fazla 64 byte'lik parçalar olacak şekilde çekmesini bekliyor. Bu belirttiğim çalışma şekli de tdslite'in arduino network kodu ile şu anda uyumlu değil.

Sorunun çözümüne gelirsek, kütüphanede ufak bir revizyon yaptım ve önümüzdeki günlerde diğer board'larda da test ettikten sonra yeni resmi sürüm çıkacağım. Kütüphanenin revize edilmiş halini zip olarak ekte paylaşıyorum, test edip doğrulayabilirsen güzel olur.

Yeni sürümü resmi olarak yayımladığımda buradan bilgilendiriyor olacağım.
Çok teşekkür ederim ilgin için elimde ki board arızalandı bende yeni sipariş verdim gelmesini bekliyorum geldiği gibi deneyip haber vereceğim.
 

Forum istatistikleri

Konular
128,198
Mesajlar
915,770
Kullanıcılar
449,979
Son üye
schule48

Yeni konular

Geri
Üst