please solve pulse count issues (on esp8266)

shivshankar9
Posts: 1
Joined: Sun May 20, 2018 1:07 am

please solve pulse count issues (on esp8266)

Postby shivshankar9 » Sun May 20, 2018 1:13 am

Hello everyone,
I am writing the code for nodemcu esp8266, its regarding pulse count, store and return back to nodemcu using raspberry pi as server. I am using 3 pins of nodemcu esp8266 for that. I am using D4 for pulse output, D5 pulse input and D6 use a switch ( means when only one pulse give that pin then pulse comes out from D4) when given pulse on d5 its store on server when only one pulse is given on D6 then all store pulse on server its comes out from D4 pin.
But problem is,
When I upload that code on nodemcu esp8266 and not given any power to that just given the only one pulse on pin D5 then its instant comes out from D4 pin ( I am checking with LED), please help me.
Here is my code

#include <ESP8266WiFi.h>
#include "Adafruit_MQTT.h"
#include "Adafruit_MQTT_Client.h"

int pulse = D5;
int pulse_back = D6;
int LED = D4;
int pulseState=0;
int pulse_backState=0;
int count=0;
char buf[10];
String buf2;
int realcount;
/************************* WiFi Access Point *********************************/

#define WLAN_SSID "iBall-Baton" // enter your WiFi SSID
#define WLAN_PASS "987654321" // this is your WiFi password

/************************* Adafruit.io Setup *********************************/

#define MQTT_SERVER "192.168.1.100" // change this to your Pi IP_address
#define MQTT_SERVERPORT 1883 // use 8883 for SSL
#define MQTT_USERNAME "" // empty
#define MQTT_KEY "" // empty

/************ Global State (you don't need to change this!) ******************/

WiFiClient client;

// Setup the MQTT client class by passing in the WiFi client and MQTT server and login details.
Adafruit_MQTT_Client mqtt(&client, MQTT_SERVER, MQTT_SERVERPORT, MQTT_USERNAME, MQTT_KEY);

/****************************** data stream publish/subscribe ***************************************/

Adafruit_MQTT_Publish pot_stream = Adafruit_MQTT_Publish(&mqtt, MQTT_USERNAME "/esp/pot"); // change the topic
Adafruit_MQTT_Subscribe onoffbutton = Adafruit_MQTT_Subscribe(&mqtt, MQTT_USERNAME "/feeds/N1");



/*************************** Sketch Code ************************************/
void MQTT_connect();

void setup() {
Serial.begin(9600);
delay(10);
pinMode(pulse,INPUT_PULLUP); //
pinMode(pulse_back,INPUT_PULLUP); //
pinMode(LED,OUTPUT);
digitalWrite(LED,HIGH);
Serial.println(F("Adafruit MQTT demo"));

Serial.println(); Serial.println();
Serial.print("Connecting to ");
Serial.println(WLAN_SSID);

WiFi.begin(WLAN_SSID, WLAN_PASS);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println();

Serial.println("WiFi connected");
Serial.println("IP address: "); Serial.println(WiFi.localIP());
mqtt.subscribe(&onoffbutton);



}

uint32_t x=0;

void loop()
{

MQTT_connect();

pulse_backState = digitalRead(pulse_back);
pulseState = digitalRead(pulse);

if (pulseState == LOW)
{
count=count + 10;
Serial.println(count);
pot_stream.publish(10);
delay(100);
}
if (pulse_backState == LOW)
{
pot_stream.publish("N1"); // publish to Raspberry Pi under topic "/esp/pot"
Serial.print("N1");
Adafruit_MQTT_Subscribe *subscription;
while ((subscription = mqtt.readSubscription(5000))) {
if (subscription == &onoffbutton)
{
Serial.print(F("On-Off button: "));
Serial.println((char *)onoffbutton.lastread);
buf2=(char *)onoffbutton.lastread;
Serial.println(buf2);
realcount=buf2.toInt();//integer
Serial.println(realcount);
for(int i=1;i<=realcount;i++)
{
digitalWrite(LED, HIGH);
delay(50);
digitalWrite(LED, LOW);
delay(50);
}
count=0;
realcount=0;

}
}
}
}

void MQTT_connect() {
int8_t ret;

if (mqtt.connected())
{
return;
}

Serial.print("Connecting to MQTT... ");

uint8_t retries = 3;
while ((ret = mqtt.connect()) != 0) { // connect will return 0 for connected
Serial.println(mqtt.connectErrorString(ret));
Serial.println("Retrying MQTT connection in 5 seconds...");
mqtt.disconnect();
delay(5000); // wait 5 seconds
retries--;
if (retries == 0)
{
while (1);
}
}
Serial.println("MQTT Connected!");
}

Who is online

Users browsing this forum: No registered users and 3 guests