brsbnkc
Üye
- Katılım
- 10 Tem 2023
- Mesajlar
- 28
- Puanları
- 1
- Yaş
- 27
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: