tweak BT + start to add AirPlay

This commit is contained in:
philippe44
2019-08-16 23:22:46 -07:00
parent c3543bcf25
commit 2a770483a1
12 changed files with 155 additions and 15 deletions

View File

@@ -0,0 +1,65 @@
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include <stdlib.h>
#include "mdns.h"
#include "nvs.h"
#include "tcpip_adapter.h"
#include "esp_log.h"
#include "esp_console.h"
#include "esp_pthread.h"
#include "esp_system.h"
#include "freertos/timers.h"
#include "airplay_sink.h"
#include "trace.h"
static const char * TAG = "platform";
extern char current_namespace[];
void airplay_sink_init(void) {
const char *hostname;
char *airplay_name, sink_name[32] = CONFIG_AIRPLAY_NAME;
nvs_handle nvs;
tcpip_adapter_get_hostname(TCPIP_ADAPTER_IF_STA, &hostname);
//initialize mDNS
ESP_ERROR_CHECK( mdns_init() );
ESP_ERROR_CHECK( mdns_hostname_set(hostname) );
//structure with TXT records
mdns_txt_item_t serviceTxtData[] = {
{"am", "esp32"},
{"tp", "UDP"},
{"sm","false"},
{"sv","false"},
{"ek","1"},
{"et","0,1"},
{"md","0,1,2"},
{"cn","0,1"},
{"ch","2"},
{"ss","16"},
{"sr","44100"},
{"vn","3"},
{"txtvers","1"},
};
if (nvs_open(current_namespace, NVS_READONLY, &nvs) == ESP_OK) {
size_t len = 31;
nvs_get_str(nvs, "airplay_sink_name", sink_name, &len);
nvs_close(nvs);
}
// AirPlay wants mDNS name to be MAC@name
uint8_t mac[6];
esp_read_mac(mac, ESP_MAC_WIFI_STA);
asprintf(&airplay_name, "%02X%02X%02X%02X%02X%02X@%s", mac[3], mac[4], mac[5], mac[3], mac[4], mac[5], sink_name);
ESP_LOGI(TAG, "mdns hostname set to: [%s] with servicename %s", hostname, sink_name);
//initialize service
ESP_ERROR_CHECK( mdns_service_add(airplay_name, "_raop", "_tcp", 6000, serviceTxtData, sizeof(serviceTxtData) / sizeof(mdns_txt_item_t)) );
free(airplay_name);
}

View File

@@ -0,0 +1,22 @@
/*
This example code is in the Public Domain (or CC0 licensed, at your option.)
Unless required by applicable law or agreed to in writing, this
software is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
CONDITIONS OF ANY KIND, either express or implied.
*/
#ifndef __AIRPLAY_SINK_H__
#define __AIRPLAY_SINK_H__
#include <stdint.h>
//typedef enum { BT_SINK_CONNECTED, BT_SINK_DISCONNECTED, BT_SINK_PLAY, BT_SINK_STOP, BT_SINK_PAUSE,
//BT_SINK_RATE, BT_SINK_VOLUME, } bt_sink_cmd_t;
/**
* @brief init sink mode (need to be provided)
*/
void airplay_sink_init(void);
#endif /* __AIRPLAY_SINK_H__*/

View File

@@ -0,0 +1,10 @@
#
# Component Makefile
#
# This Makefile should, at the very least, just include $(SDK_PATH)/Makefile. By default,
# this will take the sources in the src/ directory, compile them and link them into
# lib(subdirectory_name).a in the build directory. This behaviour is entirely configurable,
# please read the SDK documents if you need to do this.
#
CFLAGS += -I$(COMPONENT_PATH)/../tools