From a42f7cecb03d4e19448f06bf8e11de8c0e6f6b5a Mon Sep 17 00:00:00 2001 From: Ricardo Lima Caratti Date: Wed, 9 Oct 2024 13:44:37 -0300 Subject: [PATCH] Doc --- .../NANO33IOT_ENCODER_LCD16x2.ino | 0 .../NANO_IOT_ENCODER_LCD16x2}/Rotary.cpp | 0 .../NANO_IOT_ENCODER_LCD16x2}/Rotary.h | 0 .../QN8066_CONTROLLER/QN8066_CONTROLLER.ino | 0 .../QN8066_PYTHON/Nano33IoT_QN8066.py | 216 ++++++++++ .../NANO_CAPTIVE_PORTAL.ino | 0 .../NANO_IOT_WEB_SERVICE/README.md | 3 + examples/10_NANO_33_IOT/README.md | 34 ++ .../NANO_IOT_WEB_SERVICE/README.md | 3 + .../NANO_IOT_WEB/NANO_IOT_WEB.ino | 368 ------------------ .../NANO_IOT_WEB/README.md | 5 - 11 files changed, 256 insertions(+), 373 deletions(-) rename examples/{10_Nano33IoT/NANO33IOT_ENCODER_LCD16x2 => 10_NANO_33_IOT/NANO_IOT_ENCODER_LCD16x2}/NANO33IOT_ENCODER_LCD16x2.ino (100%) rename examples/{10_Nano33IoT/NANO33IOT_ENCODER_LCD16x2 => 10_NANO_33_IOT/NANO_IOT_ENCODER_LCD16x2}/Rotary.cpp (100%) rename examples/{10_Nano33IoT/NANO33IOT_ENCODER_LCD16x2 => 10_NANO_33_IOT/NANO_IOT_ENCODER_LCD16x2}/Rotary.h (100%) create mode 100644 examples/10_NANO_33_IOT/NANO_IOT_SOCKET/QN8066_CONTROLLER/QN8066_CONTROLLER.ino create mode 100644 examples/10_NANO_33_IOT/NANO_IOT_SOCKET/QN8066_PYTHON/Nano33IoT_QN8066.py rename examples/{99_UNDER_CONSTRUCTION => 10_NANO_33_IOT/NANO_IOT_WEB_SERVICE}/NANO_CAPTIVE_PORTAL/NANO_CAPTIVE_PORTAL.ino (100%) create mode 100644 examples/10_NANO_33_IOT/NANO_IOT_WEB_SERVICE/README.md create mode 100644 examples/10_NANO_33_IOT/README.md create mode 100644 examples/10_Nano33IoT/NANO_IOT_WEB_SERVICE/README.md delete mode 100644 examples/99_UNDER_CONSTRUCTION/NANO_IOT_WEB/NANO_IOT_WEB.ino delete mode 100644 examples/99_UNDER_CONSTRUCTION/NANO_IOT_WEB/README.md diff --git a/examples/10_Nano33IoT/NANO33IOT_ENCODER_LCD16x2/NANO33IOT_ENCODER_LCD16x2.ino b/examples/10_NANO_33_IOT/NANO_IOT_ENCODER_LCD16x2/NANO33IOT_ENCODER_LCD16x2.ino similarity index 100% rename from examples/10_Nano33IoT/NANO33IOT_ENCODER_LCD16x2/NANO33IOT_ENCODER_LCD16x2.ino rename to examples/10_NANO_33_IOT/NANO_IOT_ENCODER_LCD16x2/NANO33IOT_ENCODER_LCD16x2.ino diff --git a/examples/10_Nano33IoT/NANO33IOT_ENCODER_LCD16x2/Rotary.cpp b/examples/10_NANO_33_IOT/NANO_IOT_ENCODER_LCD16x2/Rotary.cpp similarity index 100% rename from examples/10_Nano33IoT/NANO33IOT_ENCODER_LCD16x2/Rotary.cpp rename to examples/10_NANO_33_IOT/NANO_IOT_ENCODER_LCD16x2/Rotary.cpp diff --git a/examples/10_Nano33IoT/NANO33IOT_ENCODER_LCD16x2/Rotary.h b/examples/10_NANO_33_IOT/NANO_IOT_ENCODER_LCD16x2/Rotary.h similarity index 100% rename from examples/10_Nano33IoT/NANO33IOT_ENCODER_LCD16x2/Rotary.h rename to examples/10_NANO_33_IOT/NANO_IOT_ENCODER_LCD16x2/Rotary.h diff --git a/examples/10_NANO_33_IOT/NANO_IOT_SOCKET/QN8066_CONTROLLER/QN8066_CONTROLLER.ino b/examples/10_NANO_33_IOT/NANO_IOT_SOCKET/QN8066_CONTROLLER/QN8066_CONTROLLER.ino new file mode 100644 index 0000000..e69de29 diff --git a/examples/10_NANO_33_IOT/NANO_IOT_SOCKET/QN8066_PYTHON/Nano33IoT_QN8066.py b/examples/10_NANO_33_IOT/NANO_IOT_SOCKET/QN8066_PYTHON/Nano33IoT_QN8066.py new file mode 100644 index 0000000..8c721f2 --- /dev/null +++ b/examples/10_NANO_33_IOT/NANO_IOT_SOCKET/QN8066_PYTHON/Nano33IoT_QN8066.py @@ -0,0 +1,216 @@ +# This program uses a socket connection to communicate with the ESP32 (running the +# SOCKETS_ESP32_QN8066.ino sketch) in order to control the QN8066-based transmitter. +# The socket connection uses the IP provided by your WiFi network's DHCP and obtained +# by the ESP32. Check the IP in the Arduino IDE console (Serial Monitor). +# The port numer used here is 8066 (SOCKETS_ESP32_QN8066.ino). You can change it if you need it. +# +# RDS message updates such as PTY, PS, RT, and Time are not executed immediately. +# This may depend on the receiver's update timing as well as the distribution of +# each message's timing from the connected controller. +# +# defined for the connection is 8066. +# Author: Ricardo Lima Caratti - Sep. 2024 + +import tkinter as tk +from tkinter import ttk +import socket +from datetime import datetime + +# Function to send data via socket to the ESP32. +# Change the IP below to the address indicated in the Arduino sketch linked to this application. +def send_to_esp32(field, value): + try: + # The IP information can be get usind the Arduino IDE (Serial Monitor) + esp32_ip = '10.0.0.143' # ESP32 IP - Check it in the Arduino IDE Serial Monitor (console) + esp32_port = 8066 # Defined in the ESP 32 Arduino Sketch + message = f"{field}={value}\n" + + # Connects to the ESP32 and sends the message. + with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s: + s.connect((esp32_ip, esp32_port)) + s.sendall(message.encode()) + response = s.recv(1024) + print(f'Received from ESP32 ({field}):', response.decode()) + except socket.timeout: + print(f"Connection to ESP32 timed out. The device may be offline.") + except ConnectionRefusedError: + print(f"Connection to ESP32 was refused. Is the device online?") + except socket.error as e: + print(f"Socket error occurred: {e}") + except Exception as e: + print(f"An unexpected error occurred: {e}") + +# Specific functions for each field. + +def send_frequency(): + frequency = frequency_var.get() + send_to_esp32("frequency", frequency) + +def send_rds_pty(): + selected_description = rds_pty_combobox.get() + selected_value = pty_map[selected_description] + print(f"Program Type (PTY): {selected_value} ({selected_description})") + send_to_esp32("rds_pty", selected_value) + +def send_rds_ps(): + rds_ps = rds_ps_var.get() + send_to_esp32("rds_ps", rds_ps) + +def send_rds_rt(): + rds_rt = rds_rt_var.get() + send_to_esp32("rds_rt", rds_rt) + +def send_stereo_mono(): + selected_description = stereo_mono_combobox.get() + selected_value = stereo_mono_map[selected_description] + print(f"Selected Stereo/Mono: {selected_value} ({selected_description})") + send_to_esp32("stereo_mono", selected_value) + +def send_pre_emphasis(): + selected_description = pre_emphasis_combobox.get() + selected_value = pre_emphasis_map[selected_description] # Obtém o valor numérico correspondente + print(f"Pre-Emphasis: {selected_value} ({selected_description})") + send_to_esp32("pre_emphasis", selected_value) + +def send_impedance(): + selected_description = impedance_combobox.get() # Obtém a descrição selecionada + selected_value = impedance_map[selected_description] # Obtém o valor numérico correspondente + print(f"Selected Impedance: {selected_value} ({selected_description})") + send_to_esp32("impedance", selected_value) + +def send_buffer_gain(): + selected_description = buffer_gain_combobox.get() + selected_value = buffer_gain_map[selected_description] # Obtém o valor numérico correspondente + print(f"Selected Buffer Gain: {selected_value} ({selected_description})") + send_to_esp32("buffer_gain", selected_value) + +def send_freq_dev(): + freq_dev = freq_dev_var.get() + send_to_esp32("freq_dev", freq_dev) + +def send_soft_clip(): + selected_description = soft_clip_combobox.get() + selected_value = soft_clip_map[selected_description] + print(f"Selected Soft CLip: {selected_value} ({selected_description})") + send_to_esp32("soft_clip", selected_value) + +def send_datetime(): + datetime_str = datetime_var.get() + send_to_esp32("datetime", datetime_str) + + +# Creating the main window with Tkinter. +root = tk.Tk() +root.title("ESP32 QN8066 FM Transmitter Control") +root.configure(bg='#006400') # Green + +# Fields +frequency_var = tk.StringVar(value = "106.9") +rds_pty_var = tk.StringVar(value = "No program") +rds_ps_var = tk.StringVar(value="PU2CLR") +rds_rt_var = tk.StringVar(value="QN8066 Arduino Library") +stereo_mono_var = tk.StringVar(value = "Stereo") +pre_emphasis_var = tk.StringVar(value = "70us") +buffer_gain_var = tk.StringVar(value = "6dB") +impedance_var = tk.StringVar(value = "20K") +freq_dev_var = tk.StringVar(value = "74.5") +soft_clip_var = tk.StringVar(value = "Disable") +datetime_var = tk.StringVar(value=datetime.now().strftime("%Y/%m/%d %H:%M") ) + +label_fg = '#FFFF00' +entry_bg = '#004d00' +entry_fg = '#FFFF00' + +impedance_map = { + '10K': 0, + '20K': 1, + '40K': 2, + '80K': 3 +} + +pty_map = {'No program':0, + 'News':1, + 'Information':3, + 'Sport':4, + 'Education':5, + 'Culture':7, + 'Science':8, + 'Pop Music':10, + 'Weather':16, + 'Religion':20, + 'Documentary':29, + 'Alarm':30} + +stereo_mono_map = {'Stereo':0,'Mono':1} +pre_emphasis_map = {'50us':0,'75us':1} +buffer_gain_map = {'3d{B':0,'6dB':1,'9dB':2,'12dB':3,'15dB':4,'18dB':5} +soft_clip_map = {'Disable':0,'Enable':1} + +impedance_descriptions = list(impedance_map.keys()) +pty_descriptions = list(pty_map.keys()) +stereo_mono_descriptions = list(stereo_mono_map.keys()) +pre_emphasis_descriptions = list(pre_emphasis_map.keys()) +buffer_gain_descriptions = list(buffer_gain_map.keys()) +soft_clip_descriptions = list(soft_clip_map.keys()) + +# Forms Layout +tk.Label(root, text="Transmission Frequency (MHz):", bg='#006400', fg=label_fg).grid(row=0, column=0, sticky=tk.E, padx=10, pady=5) +tk.Entry(root, textvariable=frequency_var).grid(row=0, column=1, padx=10, pady=5) +tk.Button(root, text="Set", command=send_frequency).grid(row=0, column=2, padx=10, pady=5) + +tk.Label(root, text="RDS PTY:",bg='#006400', fg=label_fg).grid(row=1, column=0, sticky=tk.E, padx=10, pady=5) + +# Combobox +rds_pty_combobox = ttk.Combobox(root, textvariable=rds_pty_var, values=pty_descriptions) +rds_pty_combobox.grid(row=1, column=1, padx=10, pady=5) +tk.Button(root, text="Set", command=send_rds_pty).grid(row=1, column=2, padx=10, pady=5) + +tk.Label(root, text="RDS PS:", bg='#006400', fg=label_fg).grid(row=2, column=0, sticky=tk.E, padx=10, pady=5) +tk.Entry(root, textvariable=rds_ps_var).grid(row=2, column=1, padx=10, pady=5) +tk.Button(root, text="Set", command=send_rds_ps).grid(row=2, column=2, padx=10, pady=5) + +tk.Label(root, text="RDS RT:", bg='#006400', fg=label_fg).grid(row=3, column=0, sticky=tk.E, padx=10, pady=5) +tk.Entry(root, textvariable=rds_rt_var).grid(row=3, column=1, padx=10, pady=5) +tk.Button(root, text="Set", command=send_rds_rt).grid(row=3, column=2, padx=10, pady=5) + +tk.Label(root, text="Stereo/Mono:", bg='#006400', fg=label_fg).grid(row=4, column=0, sticky=tk.E, padx=10, pady=5) +stereo_mono_combobox = ttk.Combobox(root, textvariable=stereo_mono_var, values= stereo_mono_descriptions) +stereo_mono_combobox.grid(row=4, column=1, padx=10, pady=5) +tk.Button(root, text="Set", command=send_stereo_mono).grid(row=4, column=2, padx=10, pady=5) + +tk.Label(root, text="Pre-Emphasis:", bg='#006400', fg=label_fg).grid(row=5, column=0, sticky=tk.E, padx=10, pady=5) +pre_emphasis_combobox = ttk.Combobox(root, textvariable=pre_emphasis_var, values=pre_emphasis_descriptions) +pre_emphasis_combobox.grid(row=5, column=1, padx=10, pady=5) +tk.Button(root, text="Set", command=send_pre_emphasis).grid(row=5, column=2, padx=10, pady=5) + +tk.Label(root, text="Impedance:", bg='#006400', fg=label_fg).grid(row=6, column=0, sticky=tk.E, padx=10, pady=5) +impedance_combobox = ttk.Combobox(root, textvariable=impedance_var, values = impedance_descriptions) + +impedance_combobox.grid(row=6, column=1, padx=10, pady=5) +tk.Button(root, text="Set", command=send_impedance).grid(row=6, column=2, padx=10, pady=5) + + +tk.Label(root, text="Buffer Gain:", bg='#006400', fg=label_fg).grid(row=7, column=0, sticky=tk.E, padx=10, pady=5) +buffer_gain_combobox = ttk.Combobox(root, textvariable=buffer_gain_var, values = buffer_gain_descriptions) + +buffer_gain_combobox.grid(row=7, column=1, padx=10, pady=5) +tk.Button(root, text="Set", command=send_buffer_gain).grid(row=7, column=2, padx=10, pady=5) + +tk.Label(root, text="Frequency Deviation (kHz):", bg='#006400', fg=label_fg).grid(row=8, column=0, sticky=tk.E, padx=10, pady=5) +freq_dev_combobox = ttk.Combobox(root, textvariable=freq_dev_var) +freq_dev_combobox['values'] = ['41.5', '60.0', '74.5','92.8','96.6', '110.4'] +freq_dev_combobox.grid(row=8, column=1, padx=10, pady=5) +tk.Button(root, text="Set", command=send_freq_dev).grid(row=8, column=2, padx=10, pady=5) + +tk.Label(root, text="Soft Clip:", bg='#006400', fg=label_fg).grid(row=9, column=0, sticky=tk.E, padx=10, pady=5) +soft_clip_combobox = ttk.Combobox(root, textvariable=soft_clip_var,values=soft_clip_descriptions) +soft_clip_combobox.grid(row=9, column=1, padx=10, pady=5) +tk.Button(root, text="Set", command=send_soft_clip).grid(row=9, column=2, padx=10, pady=5) + +tk.Label(root, text="Set Date and Time (YYYY/MM/DD HH:MM):", bg='#006400', fg=label_fg).grid(row=10, column=0, padx=10, pady=5) +tk.Entry(root, textvariable=datetime_var).grid(row=10, column=1, padx=10, pady=5) +tk.Button(root, text="Set", command=send_datetime).grid(row=10, column=2, padx=10, pady=5) + + +# Start interface +root.mainloop() diff --git a/examples/99_UNDER_CONSTRUCTION/NANO_CAPTIVE_PORTAL/NANO_CAPTIVE_PORTAL.ino b/examples/10_NANO_33_IOT/NANO_IOT_WEB_SERVICE/NANO_CAPTIVE_PORTAL/NANO_CAPTIVE_PORTAL.ino similarity index 100% rename from examples/99_UNDER_CONSTRUCTION/NANO_CAPTIVE_PORTAL/NANO_CAPTIVE_PORTAL.ino rename to examples/10_NANO_33_IOT/NANO_IOT_WEB_SERVICE/NANO_CAPTIVE_PORTAL/NANO_CAPTIVE_PORTAL.ino diff --git a/examples/10_NANO_33_IOT/NANO_IOT_WEB_SERVICE/README.md b/examples/10_NANO_33_IOT/NANO_IOT_WEB_SERVICE/README.md new file mode 100644 index 0000000..f8c1f52 --- /dev/null +++ b/examples/10_NANO_33_IOT/NANO_IOT_WEB_SERVICE/README.md @@ -0,0 +1,3 @@ +# Nano 33 IoT as Access Point, WEB Service and QN8066 Controller + +![Under Construnction...](../../../extras/images/under_construction.png) diff --git a/examples/10_NANO_33_IOT/README.md b/examples/10_NANO_33_IOT/README.md new file mode 100644 index 0000000..b9dd2b4 --- /dev/null +++ b/examples/10_NANO_33_IOT/README.md @@ -0,0 +1,34 @@ +# NANO 33 IOT and QN8066 setup + +The [Arduino Nano 33 IoT](https://docs.arduino.cc/resources/datasheets/ABX00027-datasheet.pdf) is a compact board that offers Wi-Fi and Bluetooth connectivity, making it an excellent choice for Internet of Things (IoT) projects. It is designed as an evolution of the Nano series, adding wireless connectivity while maintaining a simple and accessible interface. + +### Key Features: +1. **Microcontroller**: SAMD21 Cortex®-M0+ 32-bit ARM®. +2. **Connectivity**: + - **Wi-Fi**: NINA-W102 module (IEEE 802.11b/g/n). + - **Bluetooth 4.2**: Also integrated into the NINA-W102 module. +3. **Memory**: + - **Flash**: 256 KB. + - **SRAM**: 32 KB. +4. **Operating Voltage**: 3.3V (with 5V tolerant I/O). +5. **Input/Output Pins**: + - **14 digital pins**, 12 of which can be used as PWM outputs. + - **8 analog inputs**. + - **SPI, I2C, UART** pins are available. +6. **IMU (Inertial Measurement Unit)**: LSM6DS3, a 6-axis sensor (accelerometer and gyroscope) for motion and rotation tracking. +7. **Compact size**: Follows the Nano form factor, making it ideal for projects with limited space. + +### Compatibility with the Arduino Nano (ATmega328): +The **Arduino Nano 33 IoT** has the same pin configuration as the **Arduino Nano based on the ATmega328**, making it a great option for replacing or expanding existing projects using the classic **Arduino Nano**. This means that, in many cases, you can simply swap the board without needing to modify the existing hardware layout. Additionally, it provides the advantage of wireless connectivity (Wi-Fi and Bluetooth), enabling you to expand the capabilities of your projects. + +This pin compatibility makes the Nano 33 IoT a natural choice if you want to upgrade a project to include IoT connectivity, while keeping the simplicity of the design and enabling easy integration of new features without significant board reconfiguration. + + + + + + +## References + +* [Arduino® Nano 33 IoT](https://docs.arduino.cc/resources/datasheets/ABX00027-datasheet.pdf) +* [Connect the Arduino Nano 33 IoT with Ubidots over HTTP](https://help.ubidots.com/en/articles/3383755-connect-the-arduino-nano-33-iot-with-ubidots-over-http) \ No newline at end of file diff --git a/examples/10_Nano33IoT/NANO_IOT_WEB_SERVICE/README.md b/examples/10_Nano33IoT/NANO_IOT_WEB_SERVICE/README.md new file mode 100644 index 0000000..f8c1f52 --- /dev/null +++ b/examples/10_Nano33IoT/NANO_IOT_WEB_SERVICE/README.md @@ -0,0 +1,3 @@ +# Nano 33 IoT as Access Point, WEB Service and QN8066 Controller + +![Under Construnction...](../../../extras/images/under_construction.png) diff --git a/examples/99_UNDER_CONSTRUCTION/NANO_IOT_WEB/NANO_IOT_WEB.ino b/examples/99_UNDER_CONSTRUCTION/NANO_IOT_WEB/NANO_IOT_WEB.ino deleted file mode 100644 index 105f8f3..0000000 --- a/examples/99_UNDER_CONSTRUCTION/NANO_IOT_WEB/NANO_IOT_WEB.ino +++ /dev/null @@ -1,368 +0,0 @@ -/* - Nano 33 IoT board - -1. This sketch uses HTML form to get and process commands from external browser applications to configure the - FM transmitter based on QN8066. - - Nano 33 IoT Wire up - - | Device name | QN8066 Pin | Nano 33 IoT | - | --------------------------| -------------------- | ----------------- | - | QN8066 | | | - | | VCC | 3.3V | - | | GND | GND | - | | SDIO / SDA (pin 2) | A4 | - | | SCLK (pin 1) | A5 | - | --------------------------| ---------------------| ----------------- | - | PWM Power Controller [1] | | | - | | | D9 | - - 1. A suggestion if you intend to use PWM to control the RF output power of an amplifier. - - Prototype documentation: https://pu2clr.github.io/QN8066/ - PU2CLR QN8066 API documentation: https://pu2clr.github.io/QN8066/extras/apidoc/html/ - - By PU2CLR, Ricardo, Oct 2024. -*/ - -#include -#include // Install from https://www.arduino.cc/reference/en/libraries/wifinina/ - -#define I2C_SDA 4 // A4 -#define I2C_SCL 5 // A5 - - -// Definição da rede Wi-Fi -char ssid[] = "PU2CLR"; // Coloque o nome da sua rede Wi-Fi -char pass[] = "pu2clr123456"; // Coloque a senha da sua rede Wi-Fi - - -long rdsTimePS = millis(); -long rdsTimeRT = millis(); -long rdsDateTime = millis(); - -char ps[9] = "PU2CLR \r"; -char rt[33] = "QN8066 WEB Server control \r"; - -uint16_t currentFrequency = 1069; // 106.9 MHz -uint16_t previousFrequency = 1069; // 106.9 MHz -uint8_t currentPower = 0; - - -int status = WL_IDLE_STATUS; // Variável para armazenar o status da conexão -WiFiServer server(80); // Cria um servidor na porta 80 - -WiFiClient client; - -QN8066 tx; - -void setup() { - - Serial.begin(9600); - Serial.println("Starting WiFi!"); - - // Verifica o status do módulo Wi-Fi - if (WiFi.status() == WL_NO_MODULE) { - Serial.println("WiFi Error!"); - while (true) - ; - } - - while (status != WL_CONNECTED) { - Serial.print("Connecting to: "); - Serial.println(ssid); - status = WiFi.begin(ssid, pass); - delay(5000); - } - - // Starting Server - server.begin(); - Serial.println("Server started"); - - Serial.print("IP do Arduino: "); - Serial.println(WiFi.localIP()); -} - -void doFormParameters() { - String htmlPage = ""; - htmlPage += ""; - - htmlPage += ""; - - htmlPage += "

PU2CLR QN8066 Arduino Library

"; - htmlPage += "

FM Transmitter Configuration

"; - - - // Formulário com Ajax e solução tradicional - htmlPage += "
"; - - // Tabela para alinhar campos e botões - htmlPage += ""; - - // Frequency - htmlPage += ""; - htmlPage += ""; - htmlPage += ""; - htmlPage += ""; - htmlPage += ""; - - // Power (Not implemented so far) - htmlPage += ""; - htmlPage += ""; - htmlPage += ""; - htmlPage += ""; - htmlPage += ""; - - // Stereo / Mono - htmlPage += ""; - htmlPage += ""; - htmlPage += ""; - htmlPage += ""; - htmlPage += ""; - - // PreEmphasis - htmlPage += ""; - htmlPage += ""; - htmlPage += ""; - htmlPage += ""; - htmlPage += ""; - - // RDS PTY (ComboBox) - htmlPage += ""; - htmlPage += ""; - htmlPage += ""; - htmlPage += ""; - htmlPage += ""; - - // RDS Programa Station (PS) - htmlPage += ""; - htmlPage += ""; - htmlPage += ""; - htmlPage += ""; - htmlPage += ""; - - // RDS Radio Text (RT) - htmlPage += ""; - htmlPage += ""; - htmlPage += ""; - htmlPage += ""; - htmlPage += ""; - - // Linha do RDS DT - - htmlPage += ""; - htmlPage += ""; - htmlPage += ""; - htmlPage += ""; - htmlPage += ""; - - // Frequency Derivation list - htmlPage += ""; - htmlPage += ""; - htmlPage += ""; - htmlPage += ""; - htmlPage += ""; - - // Impedance - htmlPage += ""; - htmlPage += ""; - htmlPage += ""; - htmlPage += ""; - htmlPage += ""; - - // Buffer Gain - htmlPage += ""; - htmlPage += ""; - htmlPage += ""; - htmlPage += ""; - htmlPage += ""; - - - // Soft Clip - htmlPage += ""; - htmlPage += ""; - htmlPage += ""; - htmlPage += ""; - htmlPage += ""; - - - // Fechar tabela e botão de enviar o formulário completo (solução tradicional) - htmlPage += "
Transmission Frequency (MHz):
Power:
Stereo/Mono:
Pre-Emphasis:
RDS PTY:
RDS PS:
RDS RT:
RDS DT:
Frequency Derivation:
Input Impedance:
Buffer Gain:
Soft Clip:

"; - htmlPage += ""; - - // Close the form definition - htmlPage += "
"; - - // Script para enviar dados via Ajax (envio individual) - htmlPage += ""; - - htmlPage += ""; - client.println(htmlPage); -} - - -String getValue(String data, String field) { - int startIndex = data.indexOf(field + "=") + field.length() + 1; - int endIndex = data.indexOf('&', startIndex); - if (endIndex == -1) { - endIndex = data.length(); - } - return data.substring(startIndex, endIndex); -} - - -void doFormUpdate() { - String body = client.readString(); - Serial.println("Request: " + body); - - int nLen; - - // Processa e aplica o valor do campo correspondente - if (body.indexOf("frequency=") >= 0) { - String frequency = getValue(body, "frequency"); - currentFrequency = (uint16_t)(frequency.toFloat() * 10); - if (currentFrequency != previousFrequency) { - tx.setTX(currentFrequency); - previousFrequency = currentFrequency; - } - Serial.println("Frequency updated to: " + String(frequency) + " MHz"); - } - /* else if (field == "power") { - String power = server.arg("power"); - Serial.println("Power updated to: " + String(power)); - } else if (field == "rds_pty") { - String rds_pty = server.arg("rds_pty"); - tx.rdsSetPTY(rds_pty.toInt()); - Serial.println("RDS PTY updated to: " + String(rds_pty)); - } else if (field == "rds_ps") { - String rds_ps = server.arg("rds_ps"); - nLen = rds_ps.length(); - strncpy(ps, rds_ps.c_str(), nLen); - ps[nLen] = '\r'; - ps[nLen+1] = '\0'; - Serial.println("RDS PS updated to: " + String(ps)); - } else if (field == "rds_rt") { - String rds_rt = server.arg("rds_rt"); - nLen = rds_rt.length(); - strncpy(rt, rds_rt.c_str(), nLen); - rt[nLen] = '\r'; - rt[nLen+1] = '\0'; - Serial.println("RDS RT updated to: " + String(rt)); - } else if (field == "frequency_derivation") { - String frequency_derivation = server.arg("frequency_derivation"); - tx.setTxFrequencyDerivation(frequency_derivation.toInt()); - Serial.println("Frequency Derivation updated to: " + String(frequency_derivation)); - } else if (field == "input_impedance") { - String input_impedance = server.arg("input_impedance"); - tx.setTxInputImpedance(input_impedance.toInt()); - Serial.println("Input Impedance updated to: " + String(input_impedance)); - } else if (field == "stereo_mono") { - String stereo_mono = server.arg("stereo_mono"); - tx.setTxMono(stereo_mono.toInt()); - Serial.println("Stereo/Mono updated to: " + String(stereo_mono)); - } else if (field == "buffer_gain") { - String buffer_gain = server.arg("buffer_gain"); - tx.setTxInputBufferGain(buffer_gain.toInt()); - Serial.println("Buffer Gain updated to: " + String(buffer_gain)); - } else if (field == "pre_emphasis") { - String pre_emphasis = server.arg("pre_emphasis"); - tx.setPreEmphasis(pre_emphasis.toInt()); - Serial.println("Pre-Emphasis updated to: " + String(pre_emphasis)); - } else if (field == "soft_clip") { - String soft_clip = server.arg("soft_clip"); - tx.setTxSoftClippingEnable(soft_clip.toInt()); - Serial.println("Soft Clip updated to: " + String(soft_clip)); - } - */ - // Enviar resposta ao cliente confirmando o recebimento do campo - // server.send(200, "text/plain", field + " has been updated."); -} - - -void loop() { - // Verifica se há clientes conectados - client = server.available(); - if (client) { - Serial.println("Connected"); - String request = client.readStringUntil('\r'); - client.flush(); - // Aguarda até o cliente enviar dados - if (request.indexOf("POST") >= 0) { - while (client.available()) { - String request = client.readStringUntil('\r'); - Serial.println(request); - client.flush(); - - break; - } - - doFormUpdate(); - } else { - doFormParameters(); - } - client.stop(); - Serial.println("Connection Closed"); - } -} diff --git a/examples/99_UNDER_CONSTRUCTION/NANO_IOT_WEB/README.md b/examples/99_UNDER_CONSTRUCTION/NANO_IOT_WEB/README.md deleted file mode 100644 index 5369bb6..0000000 --- a/examples/99_UNDER_CONSTRUCTION/NANO_IOT_WEB/README.md +++ /dev/null @@ -1,5 +0,0 @@ -# Nano 33 IoT - -To compile this sketch, install the library WiFiNINA (https://www.arduino.cc/reference/en/libraries/wifinina/) - -