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
uint16_t statusPacketIdSub = 0;
String commandTopic;
String temperatureTopic;
String humidityTopic;
String pressureTopic;
String bme280Topic;
void setup() {
// gpio configuration
@ -72,10 +70,8 @@ void setup() {
bme280.printValues();
//Configure the MQTT topics
commandTopic = "esp32-node/cmd/" + iot.hostname + "/command";
temperatureTopic = "esp32-node/stat/" + iot.hostname + "/temperature";
humidityTopic = "esp32-node/stat/" + iot.hostname + "/humidity";
pressureTopic = "esp32-node/stat/" + iot.hostname + "/pressure";
commandTopic = "esp32-node/cmd/" + iot.hostname + "/play";
bme280Topic = "esp32-node/stat/" + iot.hostname + "/bme280";
//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...
@ -116,13 +112,15 @@ void onMqttConnect(bool sessionPresent) {
void transmitStatus() {
DEBUG_PRINTLN(__func__);
char sensorC[6];
sprintf(sensorC, "%04i", bme280.readTemperature());
statusPacketIdSub = iot.mqtt.publish(temperatureTopic.c_str(), 1, true, sensorC);
sprintf(sensorC, "%04i", bme280.readHumidity());
statusPacketIdSub = iot.mqtt.publish(humidityTopic.c_str(), 1, true, sensorC);
sprintf(sensorC, "%04i", bme280.readPressure());
statusPacketIdSub = iot.mqtt.publish(pressureTopic.c_str(), 1, true, sensorC);
StaticJsonBuffer<200> jsonBuffer;
JsonObject& root = jsonBuffer.createObject();
root["temperature"] = bme280.readTemperature();
root["humidity"] = bme280.readHumidity();
root["pressure"] = bme280.readPressure();
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__);
//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);
/* 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());
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());
@ -60,8 +60,8 @@ MainMenu::MainMenu() {
string_list = {
"PLAY",
"Radio Stations",
"test",
"test3",
"Toggle Light",
"Test2",
"\xAB Return"};
if (mp3.playing) {
string_list[0] = "STOP";
@ -69,7 +69,7 @@ MainMenu::MainMenu() {
}
uint8_t MainMenu::select() {
String topic = "esp32-node/stat/" + iot.hostname + "/blabla";
String topic = "esp32-node/cmd/" + iot.hostname + "/button";
switch (current_pos) {
case 0:
if (mp3.playing) {
@ -83,10 +83,10 @@ uint8_t MainMenu::select() {
return current_pos;
break;
case 2:
iot.mqtt.publish(topic.c_str(), 1, true, "test" );
iot.mqtt.publish(topic.c_str(), 1, true, "light" );
break;
case 3:
iot.mqtt.publish(topic.c_str(), 1, true, "foo" );
iot.mqtt.publish(topic.c_str(), 1, true, "test2" );
break;
case 4:
menuChange = eMainScreen;
@ -112,6 +112,7 @@ StationMenu::StationMenu() {
"Live Ireland",
"Ye Ol Celtic Pub",
"Gone Country - NZCMR",
"xd0.de MPD",
"\xAB Return"};
}
@ -148,6 +149,9 @@ uint8_t StationMenu::select() {
mp3.start("http://192.99.41.102:5044/stream");
break;
case 10:
mp3.start("http://172.16.75.17:8000/mopidy");
break;
case 11:
menuChange = eMainMenu;
return current_pos;
break;

Loading…
Cancel
Save