6v6gt:
Are you connecting your Wemos? directly to the Adafruit sound card I.e. Not through the RF device mentioned in the quoted article ?
Why not for testing simply use another pin on the Wemos and set it high or low as required in you sketch?
Thanks for the idea. Yes, wired directly to the wemos. So here are my two sketches:
AP sketch with capacitive touch switch
#include <ESP8266WiFi.h>
extern "C" {
#include "user_interface.h"
}
char apName[] = "SoundFx";
char apPassword[] = "Adafruit";
void setup() {
Serial.begin(115200);
delay(100);
WiFi.softAP(apName, apPassword);
WiFi.mode(WIFI_AP);
pinMode(D1, INPUT_PULLUP); / not sure what to put here
Serial.println();
Serial.println("AP Started");
}
int value = 0;
int stations = -1;
void loop() {
int stationsNow = wifi_softap_get_station_num();
if (stations != stationsNow) {
stations = stationsNow;
Serial.print("Station count: ");
Serial.println(stations);
}
int newValue = digitalRead(D1);
if (newValue != value) {
value = newValue;
Serial.print("value=");
Serial.println(value);
struct station_info *stat_info;
struct ip_addr *IPaddress;
unsigned long uintaddress;
Serial.println("Updating connected stations...");
stat_info = wifi_softap_get_station_info();
while (stat_info != NULL) {
IPaddress = &stat_info->ip;
uintaddress = IPaddress->addr;
String host = String(ip4_addr1(&uintaddress)) + "." + ip4_addr2(&uintaddress) + "." + ip4_addr3(&uintaddress) + "." + ip4_addr4(&uintaddress);
Serial.print("connecting to ");
Serial.println(host);
// Use WiFiClient class to create TCP connections
WiFiClient client;
const int httpPort = 80;
if (!client.connect(host.c_str(), httpPort)) {
Serial.println("connection failed");
}
else {
// We now create a URI for the request
String url;
if (value == HIGH) {
url = "/LED=ON";
}
else {
url = "/LED=OFF";
}
Serial.print("Requesting URL: ");
Serial.println(url);
// This will send the request to the server
client.print(String("GET ") + url + " HTTP/1.1\r\n" +
"Host: " + host + "\r\n" +
"Connection: close\r\n\r\n");
delay(50);
// Read all the lines of the reply from server and print them to Serial
while (client.available()) {
String line = client.readStringUntil('\r');
Serial.print(line);
}
Serial.println();
Serial.println("closing connection");
}
client.flush();
client.stop();
stat_info = STAILQ_NEXT(stat_info, next);
}
Serial.println("All connected stations updated.");
}
}
Station sketch with the other wemos attached to the soundfx board:
#include <ESP8266WiFi.h>
const char* ssid = "SoundFx";
const char* password = "Adafruit";
int ledPin = D1;
int triggerPin = D4;
WiFiServer server(80);
void setup() {
Serial.begin(115200);
delay(10);
pinMode(ledPin, OUTPUT);
digitalWrite(ledPin, HIGH);
pinMode(triggerPin, OUTPUT);
digitalWrite(triggerPin, HIGH);
// Connect to WiFi network
Serial.println();
Serial.println();
Serial.print("Connecting to ");
Serial.println(ssid);
WiFi.begin(ssid, password);
WiFi.mode(WIFI_STA);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
digitalWrite(ledPin, HIGH);
Serial.print(".");
delay(50);
digitalWrite(ledPin, LOW);
}
Serial.println("");
Serial.println("WiFi connected");
// Start the server
server.begin();
Serial.print("Server started on ");
Serial.println(WiFi.localIP());
digitalWrite(ledPin, HIGH);
delay(500);
digitalWrite(ledPin, LOW);
}
void loop() {
// Check if a client has connected
WiFiClient client = server.available();
if (client) {
// Wait until the client sends some data
Serial.println("new client");
while (!client.available()) {
delay(1);
}
// Read the first line of the request
String request = client.readStringUntil('\r');
Serial.println(request);
client.flush();
// Match the request
int value = LOW;
if (request.indexOf("/LED=ON") != -1) {
digitalWrite(ledPin, HIGH);
digitalWrite(triggerPin, LOW);
value = HIGH;
}
if (request.indexOf("/LED=OFF") != -1) {
digitalWrite(ledPin, LOW);
digitalWrite(triggerPin, HIGH);
value = LOW;
}
// Set ledPin according to the request
//digitalWrite(ledPin, value);
// Return the response
client.println("HTTP/1.1 200 OK");
client.println("Content-Type: text/html");
client.println(""); // do not forget this one
client.print("Led pin is now: ");
if (value == HIGH) {
client.print("On");
} else {
client.print("Off");
}
client.println(""); // do not forget this one
client.flush();
client.stop();
Serial.println("Client disconnected");
Serial.println("");
}
}
It works somewhat. Instead of triggering the sound when the button is pressed, it loops until I press the button So I know at least it will work without the inverter chip. I just have to find the HIGH/LOW for the button press and swap the value. That should work. Then I would like to pull out all the extra code NOT needed for this project to speed up the response of whether the button is pressed or not.