#include <ESP8266WiFi.h>
#include "Ubidots.h"
#include <DFPlayer_Mini_Mp3.h> //Library for MP3 player
const char* UBIDOTS_TOKEN = "BBFF-UoxlyL8IwelkzGn1HpYDspi3YzjCcN"; // Put here your Ubidots TOKEN
Ubidots ubidots(UBIDOTS_TOKEN, UBI_HTTP);
const char* ssid = "SINGTEL-95E6"; // The SSID (name) of the Wi-Fi network you want to connect to
const char* password = "acaenixahn"; // The password of the Wi-Fi network
#define Button1 D5 //Belly Good
#define Button2 D4 //Belly Normal
#define Button3 D3 //Belly Bad
int count1 = 0; //Counter for belly Good
int count2 = 0; //Counter for belly Normal
int count3 = 0; //Counter for belly Bad
int buttonState;
SoftwareSerial mySerial(0, 1); // RX, TX For Mp3
void setup()
{
Serial.begin(115200);
ubidots.wifiConnect(ssid, password);
// ubidots.setDebug(true); // Uncomment this line for printing debug messages
//For the Esp8266
while (!Serial)
{
; // wait for serial port to connect. Needed for native USB port only
}
WiFi.begin(ssid, password); // Connect to the network
Serial.print("Connecting to ");
Serial.print(ssid); Serial.println(" ...");
int i = 0;
while (WiFi.status() != WL_CONNECTED) { // Wait for the Wi-Fi to connect
delay(1000);
Serial.print(++i); Serial.print(' ');
}
Serial.println('\n');
Serial.println("Connection established!");
Serial.print("IP address:\t");
Serial.println(WiFi.localIP()); // Send the IP address of the ESP8266 to the computer
Serial.println("Started");
delay(100);
pinMode(Button1, INPUT_PULLUP);
pinMode(Button2, INPUT_PULLUP);
pinMode(Button3, INPUT_PULLUP);
mySerial.begin (9600); // begin the software serial mySerial
mp3_set_serial (mySerial); //set softwareSerial for DFPlayer-mini mp3 module
mp3_set_volume (100); //XD
}
void button1()
{
buttonState = digitalRead(Button1);
if(buttonState == HIGH)
{
count1++;
mp3_play(1);
Serial.println(count1);
bool bufferSent = false;
bufferSent = ubidots.send(); // Will send data to a device label that matches the device Id
if (bufferSent)
{
// Do something if values were sent properly
Serial.println("Values sent by the device");
}
}
else
{
mp3_stop();
}
}
void button2()
{
buttonState = digitalRead(Button2);
if(buttonState=HIGH)
{
count2++;
mp3_play(2);
Serial.println(count2);
bool bufferSent = false;
bufferSent = ubidots.send(); // Will send data to a device label that matches the device Id
if (bufferSent)
{
// Do something if values were sent properly
Serial.println("Values sent by the device");
}
}
else
{
mp3_stop();
}
}
void button3()
{
buttonState = digitalRead(Button3);
if(buttonState=HIGH)
{
count3++;
mp3_play(3);
Serial.println(count3);
bool bufferSent = false;
bufferSent = ubidots.send(); // Will send data to a device label that matches the device Id
if (bufferSent)
{
// Do something if values were sent properly
Serial.println("Values sent by the device");
}
}
else
{
mp3_stop();
}
}
void loop()
{
ubidots.add("Count1", count1); // Change for your variable name
ubidots.add("Count2", count2);
ubidots.add("Count3", count3);
button1();
button2();
button3();
}