• Hardware model + communication type. Arduino Uno, ESP8266 Module
• Smartphone OS: Android
• Blynk server : YES
• Blynk Library version : 1.0.1
I am running into an issue when I combine these two sketches, I thought I was safe by keeping the pre-coded Blynk ESP8266_Wifi at the top of each section, then placing the other code under it. But when I run the code, my Serial Monitor connects, but then garbled text starts typing over the connection print out and doesn’t connect to the app.
Where do I have to place my Bottle Counter sketch code within the ESP 8266 sketch? And will I have to change the delays found throughout?
Bottle Counter sketch: The bulk of the code is the sketch is from the LCD manufacturer and an IR sensor:
#include <SoftwareSerial.h>
const int TxPin = 6;
int irPin = 2;
int count = 0;
boolean state = true;
SoftwareSerial mySerial = SoftwareSerial(255, TxPin); //This code was provided by the manufacturer, Parallax, without it I cannot run my LCD display properly.
void setup() {
pinMode(TxPin, OUTPUT);
pinMode(irPin,INPUT); //IR Sensor
digitalWrite(TxPin, HIGH);
mySerial.begin(9600);
delay(100);
mySerial.write(12); // Clear
mySerial.write(17); // Turn backlight on
delay(5); // Required delay
mySerial.println("Bottle Count'r:"); // First line
mySerial.write(13); // Form feed
mySerial.println(count); // Second line
delay(3000); // Wait 3 seconds
}
void loop() {
if (!digitalRead(irPin) && state){
count++;
state = false;
mySerial.write(179);
mySerial.println(count);
}
if (digitalRead(irPin))
{
state = true;
delay(100);
}
}
ESP8266 Sketch: I’ve edited some info, but it works after much frustration…
/* Comment this out to disable prints and save space */
#define BLYNK_PRINT Serial
/* Fill-in your Template ID (only if using Blynk.Cloud) */
#define BLYNK_TEMPLATE_ID "TMPLONc65bi4"
#define BLYNK_DEVICE_NAME "Bottle Counter"
#define BLYNK_AUTH_TOKEN "x"
#include <ESP8266WiFi.h>
#include <BlynkSimpleStream.h>
#include <wl_definitions.h>
// Your WiFi credentials.
// Set password to "" for open networks.
const char* ssid = "X";
const char* pass = "X";
///////////////////////////////////////////////////////////////////////////////
// FOR ON CAMPUS //
//const char* ssid = "";
//const char* pass = "";
///////////////////////////////////////////////////////////////////////////////
// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "x";
WiFiClient wifiClient;
// This function tries to connect to the cloud using TCP
bool connectBlynk()
{
wifiClient.stop();
return wifiClient.connect(BLYNK_DEFAULT_DOMAIN, BLYNK_DEFAULT_PORT);
}
// This function tries to connect to your WiFi network
void connectWiFi()
{
Serial.print("Connecting to ");
Serial.println(ssid);
if (pass && strlen(pass)) {
WiFi.begin((char*)ssid, (char*)pass);
} else {
WiFi.begin((char*)ssid);
}
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
}
void setup()
{
// Debug console
Serial.begin(9600);
connectWiFi();
connectBlynk();
Blynk.begin(wifiClient, auth);
}
void loop()
{
// Reconnect WiFi
if (WiFi.status() != WL_CONNECTED) {
connectWiFi();
return;
}
// Reconnect to Blynk Cloud
if (!wifiClient.connected()) {
connectBlynk();
return;
}
Blynk.run();
}