Hi, I make project with my esp8266, pir sensor and YX5300 module (mp3 player with uart). In my projekt I want make led strip remote control on wifi, and I tray attache somthing like welcom sound. My code work a little bit, but I have few problem first is flood error. I think I don`t send any data to blynk. Am I wrong?? Second is many time broken connection with blynk server. This make becouse I have delay in my project. Is possible another way? Third problem is not working delay and frequency button. Random track button work corectly. If sombody may help I be greatfull.
indent preformatted text by 4 spaces
#define BLYNK_PRINT Serial
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <SoftwareSerial.h>
SoftwareSerial mp3(D3, D4);
static uint8_t cmdbuf[8] = {0};
void command(int8_t cmd, int16_t dat)//send 8 byte command to mp3 module
{
delay(20);
cmdbuf[0] = 0x7e; // start byte
cmdbuf[1] = 0xFF; // version
cmdbuf[2] = 0x06; // number of bytes commanded
cmdbuf[3] = cmd; // command
cmdbuf[4] = 0x00; // 0x00 = no feedback, 0x01 = feedback
cmdbuf[5] = (int8_t)(dat >> 8); // paramete DAT1
cmdbuf[6] = (int8_t)(dat); // paramete DAT2
cmdbuf[7] = 0xef; // end byte
for (uint8_t i = 0; i < 8; i++)
{
mp3.write(cmdbuf[i]);
}
}
char auth[] = "fffffff";
char ssid[] = "ffffff";
char pass[] = "fffffff";
String dayTime; //String times;
int pinData;
int inPin = D2;
boolean pirState = 0;
long randFrequency;
long randTrack;
int freq;
int track;
int T;
int curse;
WidgetLED led1(V4);//some led to tested function
WidgetLED led2(V5);
WidgetLED led3(V6);
WidgetLED led4(V7);
WidgetLED led5(V8);
WidgetLED led6(V9);
WidgetLED led7(V3);
WidgetLED led8(V2);
BLYNK_WRITE(V0) // virtual button they selected some mode
{
pinData = param.asInt();
}
BLYNK_WRITE(V10) //and another virtual button :p
{
curse = param.asInt();
}
BLYNK_WRITE(V1) //this button get data from internet
{
dayTime = param.asStr();
Serial.println("Value dayTime:");//some tested info
Serial.println(dayTime);
Serial.println("Pin data:");
Serial.println(pinData);
}
BLYNK_WRITE(V11)//next button
{
freq = param.asInt();
}
BLYNK_WRITE(V17)//virtual slider to random track
{
track = param.asInt();
}
BLYNK_WRITE(V12) // slider to change delay time
{
T = param.asInt();
}
SimpleTimer timer;
void randoms () //random frequency and track number
{
randFrequency = random(freq);
randTrack = random(1, track);
Serial.println("Random frequency");
Serial.println(randFrequency);
Serial.println("Random track");
Serial.println(randTrack);
}
void modes() //main function if correct time of day and button mode is avilable paly something
{
Serial.println("Pin data");
Serial.println(pinData);
Serial.println("Curse");
Serial.println(curse);
Serial.println("Pir state");
Serial.println(pirState);
Serial.println("Delay");
Serial.println(T);
pirState = digitalRead (inPin);
if ((curse == 1) && (pirState == 1) && (randTrack == 1)) {
led7.on();
command(0x0B, 0x0000);
command(0x09, 0x0002); // Wybieramy karte SD jako zrodlo
delay(200); // Czekamu 200ms na inicjalizacje
command(0x06, 0x001E); // Ustaw glosnosc na 30
command(0x0F, 0x0301); // Jesli chcemy miec pewnosc ze bedzie to 02/001?????.mp3
delay(T * 1000);
command(0x0A, 0x0000);
//curse mode
}
else {
led7.off();
}
if ((curse == 1) && (pirState == 1) && (randTrack == 2)) {
led7.on();
command(0x0B, 0x0000);
command(0x09, 0x0002); // Wybieramy karte SD jako zrodlo
delay(200); // Czekamu 200ms na inicjalizacje
command(0x06, 0x001E); // Ustaw glosnosc na 30
command(0x0F, 0x0302); // Jesli chcemy miec pewnosc ze bedzie to 02/001?????.mp3
delay(T * 1000);
command(0x0A, 0x0000);
}
else {
led7.off();
}
if ((curse == 1) && (pirState == 1) && (randTrack == 3)) {
led7.on();
command(0x0B, 0x0000);
command(0x09, 0x0002); // Wybieramy karte SD jako zrodlo
delay(200); // Czekamu 200ms na inicjalizacje
command(0x06, 0x001E); // Ustaw glosnosc na 30
command(0x0F, 0x0303); // Jesli chcemy miec pewnosc ze bedzie to 02/001?????.mp3
delay(T * 1000);
command(0x0A, 0x0000);
}
else {
led7.off();
}
if ((dayTime == "Daylight") && (pinData == 1) && (pirState == 1) && (randFrequency == 0) && (randTrack == 1)) {
led6.on();
command(0x0B, 0x0000);
command(0x09, 0x0002); // Wybieramy karte SD jako zrodlo
delay(200); // Czekamu 200ms na inicjalizacje
command(0x06, 0x001E); // Ustaw glosnosc na 30
command(0x0F, 0x0101); // Jesli chcemy miec pewnosc ze bedzie to 02/001?????.mp3
delay(T * 1000);
command(0x0A, 0x0000);
}
else {
led6.off();
}
if ((dayTime == "Daylight") && (pinData == 1) && (pirState == 1) && (randFrequency == 0) && (randTrack == 2)) {
led6.on();
command(0x0B, 0x0000);
command(0x09, 0x0002); // Wybieramy karte SD jako zrodlo
delay(200); // Czekamu 200ms na inicjalizacje
command(0x06, 0x001E); // Ustaw glosnosc na 30
command(0x0F, 0x0102); // Jesli chcemy miec pewnosc ze bedzie to 02/001?????.mp3
delay(T * 1000);
command(0x0A, 0x0000);
}
else {
led6.off();
}
if ((dayTime == "Daylight") && (pinData == 1) && (pirState == 1) && (randFrequency == 0) && (randTrack == 3)) {
led6.on();
command(0x0B, 0x0000);
command(0x09, 0x0002); // Wybieramy karte SD jako zrodlo
delay(200); // Czekamu 200ms na inicjalizacje
command(0x06, 0x001E); // Ustaw glosnosc na 30
command(0x0F, 0x0103); // Jesli chcemy miec pewnosc ze bedzie to 02/001?????.mp3
delay(T * 1000);
command(0x0A, 0x0000);
}
else {
led6.off();
}
if ((dayTime == "Daylight") && (pinData == 1) && (pirState == 1) && (randFrequency == 0) && (randTrack == 4)) {
led6.on();
command(0x0B, 0x0000);
command(0x09, 0x0002); // Wybieramy karte SD jako zrodlo
delay(200); // Czekamu 200ms na inicjalizacje
command(0x06, 0x001E); // Ustaw glosnosc na 30
command(0x0F, 0x0104); // Jesli chcemy miec pewnosc ze bedzie to 02/001?????.mp3
delay(T * 1000);
command(0x0A, 0x0000);
}
else {
led6.off();
}
if ((dayTime != "Daylight") && (dayTime != "Night") && (pinData == 1) && (pirState == 1) && (randFrequency == 0) && (randTrack == 1)) {
led7.on();
command(0x0B, 0x0000);
command(0x09, 0x0002); // Wybieramy karte SD jako zrodlo
delay(200); // Czekamu 200ms na inicjalizacje
command(0x06, 0x001E); // Ustaw glosnosc na 30
command(0x0F, 0x0201); // Jesli chcemy miec pewnosc ze bedzie to 02/001?????.mp3
command(0x0A, 0x0000);
}
else {
led7.off();
}
if ((dayTime != "Daylight") && (dayTime != "Night") && (pinData == 1) && (pirState == 1) && (randFrequency == 0) && (randTrack == 2)) {
led7.on();
command(0x0B, 0x0000);
command(0x09, 0x0002); // Wybieramy karte SD jako zrodlo
delay(200); // Czekamu 200ms na inicjalizacje
command(0x06, 0x001E); // Ustaw glosnosc na 30
command(0x0F, 0x0202); // Jesli chcemy miec pewnosc ze bedzie to 02/001?????.mp3
command(0x0A, 0x0000);
} //day function
else {
led7.off();
}
if ((dayTime != "Daylight") && (dayTime != "Night") && (pinData == 1) && (pirState == 1) && (randFrequency == 0) && (randTrack == 3)) {
led7.on();
command(0x0B, 0x0000);
command(0x09, 0x0002); // Wybieramy karte SD jako zrodlo
delay(200); // Czekamu 200ms na inicjalizacje
command(0x06, 0x001E); // Ustaw glosnosc na 30
command(0x0F, 0x0203); // Jesli chcemy miec pewnosc ze bedzie to 02/001?????.mp3
command(0x0A, 0x0000);
}//evning function
else {
led7.off();
}
if ((dayTime == "Night") && (pinData == 1) && (pirState == 1)) {
led8.on();
command(0x0B, 0x0000);
command(0x09, 0x0002); // Wybieramy karte SD jako zrodlo
delay(200); // Czekamu 200ms na inicjalizacje
command(0x06, 0x001E); // Ustaw glosnosc na 30
command(0x0F, 0x0304); // Jesli chcemy miec pewnosc ze bedzie to 02/001?????.mp3
delay(4000);
command(0x0A, 0x0000);
//night function
}
else {
led8.off();
}
}
void dayTimes() //this function get time of day
{
Blynk.virtualWrite(V1, "https://api.thingspeak.com/apps/thinghttp/send_request?api_key=ffffffff");
}
void setup()
{
// Debug console
Serial.begin(115200);
Blynk.begin(auth, ssid, pass);
pirState = digitalRead (inPin);
pinMode(inPin, INPUT);
randomSeed(analogRead(0));
// You can also specify server:
//Blynk.begin(auth, ssid, pass, "blynk-cloud.com", 8442);
//Blynk.begin(auth, ssid, pass, IPAddress(192,168,1,100), 8442);
timer.setInterval(5000L, randoms);
timer.setInterval(1000L, modes);
timer.setInterval(6000L, dayTimes);
// You can perform HTTPS requests even if your hardware alone can't handle SSL
// Blynk can also fetch much bigger messages,
// if hardware has enough RAM (set BLYNK_MAX_READBYTES to 4096)
//Blynk.virtualWrite(V0, "https://api.sunrise-sunset.org/json?lat=50.4495484&lng=30.5253873&date=2016-10-01");
}
void loop()
{
Blynk.run();
timer.run();
}