THIS PROJECT IS UNDER UPDATING PROCESS. I WILL PUBLISH THE FULL SCHEMATIC IN NEXT FEW DAYS.
This sketch is an evolution/implementation of the code of SHARPALS. With his help (a lot) I integrated new functionalities to make more smart and domotic oriented his code.
This is the link of the original project:
https://www.hackster.io/sharpals/esp32-webradio-with-analogcontrol-8f7b3b
I'm just an hobbyist not a developer so, the code is far from to be perfect and professional.
Feel free to implement and modify it, keeping the original credits.I removed the lcd section, because I will use this sketch for give a new life to an old radio keeping the original external design.
I hope you will enjoy it.
THIS SOFTWARE IS NOT INTENDED FOR COMMERCIAL USE.********************
Know issues:- When SmartRadio go into AP mode, the first time that you connect to the generated SSID, it will reboot. Wait 30 secs, and connect to it again.
- Webserver is unstable and cause hangs on other routines (New client open session stuck) (audio stream, ftpserver and so on) when you use it connected via browser.
Sometimes if you click on the main buttons, it's start to work again. Anyway this sketch is optimized to work with pot control knob or via Home Assistant scripts. So it's not a big problem.
- Rotary encoder is not superfast... If you turn the knob really fast doesn't work well. Maybe the library used is not using the hdrw interrupts. But it's works quite well anyway.
Feel free to fix/implement it
*********************
Main Functionalities:- Analog tuning via 10k potentiometer (GPIO36)
- Volume control with rotary encoder. (ROTARY_PIN1 GPIO 15, ROTARY_PIN2 GPIO 4) Switch ON/OFF function via encoder switch button (GPIO14, connect it to GND with a 10k resistor).
- Switch on button (Play/pause the radio, ON/OFF the led, and power ON/OFF the amplifier. Amplifier relay pin is GPIO 26).
- Up to 3 WIFI networks credentials preset.
- Up to 16 stations preset.
- Web interface available for control and administration (Setup/select stations, WIFI credential, MQTT Broker, Mute/Unmute, Play/Pause).
- WIFI scanner.
- Increse/decrease WIFI power. Modify into the code WiFi.setTxPower(WIFI_POWER_5dBm). If you don't needed comment it //
- Playback buffer
- Autoreconnect, in case of buffer underflow.
- FTP access. Credentials USER: user PWD: user
- MQTT client embedded. ON/OFF the SmartRadio from Home Assistant (Able to use Google Home via HA script).
- Reset procedure (Press 3 sec. and release the button switch GPIO14 to reboot the SmartRadio, press 10 sec. and release it to delete pwd.txt and mqtt.txt files).
- Power safe mode (Light sleep) when not connected to WIFI or MQTT broker (power consumpion less than a normal LED).
- Reconnect automatically to MQTT broker every 6 min. if unavailable (In the meanwhile, if the Smartradio is in OFF status, it go into light sleep mode. Web controls NOT available).
- Reconnect automatically to WIFI network every 5 min. if unavailable. (In the meanwhile go into light sleep mode)
- Press the switch ON button (GPIO14) to play the audio stream. Reset/Reboot process DON'T switch ON the SmartRadio automatically (To avoid unwanted behaviours after power cut)
********************
First configuration:If no WIFI networks are available or configured, an access point (AP) is set up. The AP remain available for 5 minutes.
Sometimes when you try to connect to the AP (SMART_RADIO_IP: 10.0.0.1) the first time, due to a bug, the SmartRadio reboot. Please wait 30 sec. and try again to connect to it.
SSID: SMART_RADIO_IP: 10.0.0.1
IP: 10.0.0.1
Only the first time after the reboot the AP will be ON. If the radio loose the connectivity (wifi off/unreacheable) NO AP will be setup again, until you reboot the SmartRadio.
Wifi credential embedded in the code, if you have any problem to access via AP for the first configuration.
SSID: testwifi
PWD: 12345678
Led codes:
Slow flashing: Try to connect to the WIFI networks (3 preset available), if the wifi networks are unavailable or not configured correctly, start the AP. Only the first time after reboot.
Fast flashing: Once connected, the device can be accessed via FTP or HTTP browser.
Attention, if you change the settings on the web interface, you have to click the SUBMIT button.
After insert the WIFI/MQTT credential, you have to click the SUBMIT button, the settings will be saved immediately into pwd.txt/mqtt.txt files. Restart the SmartRadio via the website button.
For the station list, the save button must then be clicked as well.
As soon as a new url is entered, the radio tries to reach it, so you can check if everything is OK.
The files used are:
pwd.txt : user and password for the WIFI networks
mqtt.txt : ipaddress/dns of your MQTT broker
stations.txt : web radio stations list
********************
How to reset the SmartRadio:Delete pwd.txt and mqtt.txt files (where is stored the WIFI credentials and MQTT broker ipadress):
Just press the switch ON button (GPIO14) for 10 secs. and release it.
Reboot SmartRadio
Just press the switch ON button (GPIO14) for 3 secs. and release it.
*********************
How to connect with FTP server:Program: Filezilla
port: 21
user: user
password: user
Encryption: only use plain FTP (insecure)
Sometimes hang before list/download/upload files. Could help if in the meanwhile you connect via webrowser to SmartRadio ip address and navigate trough the menus.
All the files, must keep the format to be correctly read (parse) from the code. I preset a list of italian web radios (Autogenerated from the code at the first boot). Enjoy.
**********************
Initial VOLUME is setup at 75 (0-99). Change it in the code if needed.
#define VOLUME 75
**********************
Example for controlling a Smart_Radio using an MQTT switch button.Add this to your configuration.yaml in Home assistant:
switch:
- platform: mqtt
name: smartradio
state_topic: "radio/status"
command_topic: "radio/switch"
qos: 1
payload_on: "ON"
payload_off: "OFF"
state_on: "ON"
state_off: "OFF"
optimistic: true
----------------------------------------------------------------------------------
Example to set an automation alarm on working day at 9:00h via Home Assistantalias: Alarm Smart Radio
description: 'SmartRadio 9:00h Mon-Fri'
trigger:
- platform: time
at: '09:00'
condition:
- condition: and
conditions:
- condition: time
weekday:
- mon
- tue
- wed
- thu
- fri
action:
- service: switch.turn_on
data: {}
entity_id: switch.smartradio
mode: single
---------------------------------------------------------------------------------
Example for change stations via Home Assistant script:Add this to your configuration.yaml in Home assistant:
rest_command:
smartradio_station7:
url: http://YOUR_SMART_RADIO_IP_ADDRESS/station7
payload: '?station7'
Add this to your scrips in Home assistant:
alias: Smart Radio - YOUR STATION NAME
sequence:
- service: rest_command.smartradio_station7
data: {}
mode: single
----------------------------------------------------------------------------------
Example to mute audio from Home Assistant:rest_command:
smartradio_mute:
url: http://YOUR_SMART_RADIO_IP_ADDRESS/mute
payload: '?mute'
Add this to your scrips in Home assistant:
alias: Smart Radio - YOUR STATION NAME
sequence:
- service: rest_command.smartradio_mute
data: {}
mode: single
----------------------------------------------------------------------------------
Troubleshooting:
Subscribe the topic:
mosquitto_sub -h 127.0.0.1 -t radio/switch
If you have any problem to persistent/retain status in the topic. Reset it with this command from the terminal:
sudo mosquitto_pub -h 127.0.0.1 -t radio/switch -n -r -d
If the SmartRadio loose the connection with the MQTT broker, when reconnect, the radio keep the current status.
ex: Smartradio is OFF, loose the connection (wifi or MQTT broker), when automatically reconnected, the status of the radio will remain OFF.
Certain web radios transmitt with AAC codec. If you are using the VS1053 module board, you can't decode it. Buy the module board VS1053B !!
Comments
Please log in or sign up to comment.