I'm reasonably new to c++. I'm currently trying to create and internet radio alarm clock on the ESP32. I've managed to play a station but I was wanting to test out changing between two stations. I've tried creating an array of Station structs to hold relevant info for each Station but I keep getting the same errors when trying to assign to the different elements in the array. It could be that it is quite a simple error but I can't figure it out and I can't see anything too similar anywhere else.
#include <Arduino.h>
#include "WiFi.h"
#include <Audio.h>
#include <string.h>
#include <SPI.h>
#define I2S_DOUT 25
#define I2S_BCLK 27
#define I2S_LRC 26
Audio audio;
#define SSID ""
#define PASSWORD ""
//function to change station
void changeStat() {
int statIndex = (statIndex+1)%2;
};
void connectToWiFi(){
Serial.print("Connecting to Wifi");
WiFi.mode(WIFI_STA);
WiFi.begin(SSID, PASSWORD);
while(WiFi.status() != WL_CONNECTED){
Serial.print('.');
delay(1000);
}
Serial.print("\n Connected \n");
Serial.println(WiFi.localIP());
}
void setup() {
Serial.begin(9600);
//Initialising array of station structures
struct Station{
char name[15];
char URL[130];
};
Station Stats[2];
int statIndex = 0;
Stats[0] = {"BBC 6Music", "http://stream.live.vc.bbcmedia.co.uk/bbc_6music"};
Stats[1] = {"BBC Rad4", "http://stream.live.vc.bbcmedia.co.uk/bbc_radio_fourlw"};
connectToWiFi();
audio.setPinout(I2S_BCLK, I2S_LRC, I2S_DOUT);
audio.setVolume(5);
audio.connecttohost(Stats[statIndex].URL);
}
void loop() {
audio.loop();
}
Specifically, the error I get on the lines Stats[0] and Stats[1] is
no match for 'operator=' (operand types are 'setup()::Station' and '<brace-enclosed initializer list>')
but I have seen lots of other people using this sort of assignment