Hendrik Langer 7 years ago
parent
commit
af0aae4b41
  1. 31
      src/main.cpp
  2. 16
      src/screen.cpp

31
src/main.cpp

@ -48,9 +48,7 @@ uint32_t lastTransmit = 0;
//Variables for the mqtt packages and topics //Variables for the mqtt packages and topics
uint16_t statusPacketIdSub = 0; uint16_t statusPacketIdSub = 0;
String commandTopic; String commandTopic;
String temperatureTopic; String bme280Topic;
String humidityTopic;
String pressureTopic;
void setup() { void setup() {
// gpio configuration // gpio configuration
@ -72,10 +70,8 @@ void setup() {
bme280.printValues(); bme280.printValues();
//Configure the MQTT topics //Configure the MQTT topics
commandTopic = "esp32-node/cmd/" + iot.hostname + "/command"; commandTopic = "esp32-node/cmd/" + iot.hostname + "/play";
temperatureTopic = "esp32-node/stat/" + iot.hostname + "/temperature"; bme280Topic = "esp32-node/stat/" + iot.hostname + "/bme280";
humidityTopic = "esp32-node/stat/" + iot.hostname + "/humidity";
pressureTopic = "esp32-node/stat/" + iot.hostname + "/pressure";
//Set up the Callbacks for the MQTT instance. Refer to the Async MQTT Client documentation //Set up the Callbacks for the MQTT instance. Refer to the Async MQTT Client documentation
// TODO: We should do this actually _before_ connecting the mqtt client... // TODO: We should do this actually _before_ connecting the mqtt client...
@ -116,13 +112,15 @@ void onMqttConnect(bool sessionPresent) {
void transmitStatus() { void transmitStatus() {
DEBUG_PRINTLN(__func__); DEBUG_PRINTLN(__func__);
char sensorC[6]; StaticJsonBuffer<200> jsonBuffer;
sprintf(sensorC, "%04i", bme280.readTemperature()); JsonObject& root = jsonBuffer.createObject();
statusPacketIdSub = iot.mqtt.publish(temperatureTopic.c_str(), 1, true, sensorC); root["temperature"] = bme280.readTemperature();
sprintf(sensorC, "%04i", bme280.readHumidity()); root["humidity"] = bme280.readHumidity();
statusPacketIdSub = iot.mqtt.publish(humidityTopic.c_str(), 1, true, sensorC); root["pressure"] = bme280.readPressure();
sprintf(sensorC, "%04i", bme280.readPressure());
statusPacketIdSub = iot.mqtt.publish(pressureTopic.c_str(), 1, true, sensorC); char sensorBuf[root.measureLength()+1];
root.printTo(sensorBuf, sizeof(sensorBuf));
statusPacketIdSub = iot.mqtt.publish(bme280Topic.c_str(), 1, true, sensorBuf);
} }
@ -131,7 +129,10 @@ void onMqttMessage(char* topic, char* payload, AsyncMqttClientMessageProperties
DEBUG_PRINTLN(__func__); DEBUG_PRINTLN(__func__);
//Since we only subscribed to one topic, we only have to compare the payload //Since we only subscribed to one topic, we only have to compare the payload
if (strcmp(payload, "true") == 0) { if (strcmp(payload, "ON") == 0) {
mp3.start();
} else if (strcmp(payload, "OFF") == 0) {
mp3.stop();
} }
} }

16
src/screen.cpp

@ -22,7 +22,7 @@ void SelectionList::draw() {
u8g2.drawLine(0,header_height,u8g2.getDisplayWidth(),header_height); u8g2.drawLine(0,header_height,u8g2.getDisplayWidth(),header_height);
/* draw menu items */ /* draw menu items */
u8g2.setFont(u8g2_font_8x13B_tr); u8g2.setFont(u8g2_font_8x13B_tf);
int length = std::min(visible, (uint8_t)string_list.size()); int length = std::min(visible, (uint8_t)string_list.size());
for (int i=0; i<length; i++) { for (int i=0; i<length; i++) {
u8g2.drawUTF8(item_x_offset,header_height+2+(i+1)*item_height,string_list[top_item+i].c_str()); u8g2.drawUTF8(item_x_offset,header_height+2+(i+1)*item_height,string_list[top_item+i].c_str());
@ -60,8 +60,8 @@ MainMenu::MainMenu() {
string_list = { string_list = {
"PLAY", "PLAY",
"Radio Stations", "Radio Stations",
"test", "Toggle Light",
"test3", "Test2",
"\xAB Return"}; "\xAB Return"};
if (mp3.playing) { if (mp3.playing) {
string_list[0] = "STOP"; string_list[0] = "STOP";
@ -69,7 +69,7 @@ MainMenu::MainMenu() {
} }
uint8_t MainMenu::select() { uint8_t MainMenu::select() {
String topic = "esp32-node/stat/" + iot.hostname + "/blabla"; String topic = "esp32-node/cmd/" + iot.hostname + "/button";
switch (current_pos) { switch (current_pos) {
case 0: case 0:
if (mp3.playing) { if (mp3.playing) {
@ -83,10 +83,10 @@ uint8_t MainMenu::select() {
return current_pos; return current_pos;
break; break;
case 2: case 2:
iot.mqtt.publish(topic.c_str(), 1, true, "test" ); iot.mqtt.publish(topic.c_str(), 1, true, "light" );
break; break;
case 3: case 3:
iot.mqtt.publish(topic.c_str(), 1, true, "foo" ); iot.mqtt.publish(topic.c_str(), 1, true, "test2" );
break; break;
case 4: case 4:
menuChange = eMainScreen; menuChange = eMainScreen;
@ -112,6 +112,7 @@ StationMenu::StationMenu() {
"Live Ireland", "Live Ireland",
"Ye Ol Celtic Pub", "Ye Ol Celtic Pub",
"Gone Country - NZCMR", "Gone Country - NZCMR",
"xd0.de MPD",
"\xAB Return"}; "\xAB Return"};
} }
@ -148,6 +149,9 @@ uint8_t StationMenu::select() {
mp3.start("http://192.99.41.102:5044/stream"); mp3.start("http://192.99.41.102:5044/stream");
break; break;
case 10: case 10:
mp3.start("http://172.16.75.17:8000/mopidy");
break;
case 11:
menuChange = eMainMenu; menuChange = eMainMenu;
return current_pos; return current_pos;
break; break;

Loading…
Cancel
Save