Recent Posts

Pages: [1] 2 3 ... 10
1
Hi, I am in need of a library to publish a message to Mosquitto with QoS 1 from a ESP8266. I am currently using the pubsub library which is doing fine but it has one limitation as described below.
I am working on a door sensor in which the ESP8266 powers via a ATiny by pulling CH_PD HIGH. It then publishes the message and powers itself down by pulling CH_PD LOW. I am using the pubsub library to publish the message but the issue is that it seems to be working in a async QoS 0 mode to publish the message. Most of the times, the ESP powers down before the message has been published. To avoid this I put in a delay of 1 sec and it works fine but I need a better solution. Also because this sensor will be used in a security alarm it must guarantee that the  message has been published which I think can happen if QoS 1 is implemented. I have seen many discussions on QoS >0 for pubsub library but none of them is for publishing , all of them talk about subscribing.
Can somebody suggest a way out here or point me to a library which can do this. Or maybe something else I can do to guarantee the publishing of the message?

Thanks
 My code below:

Code: [Select]
/*
/*
 * 2.0 - Initial -
 *
*/
#include "DebugMacros.h"
#include <PubSubClient.h>
#include <ESP8266WiFi.h>
#include <ESP8266mDNS.h>
ADC_MODE(ADC_VCC);

const char* ssid = "SSID";
const char* password = "PSWD";
const char* mqtt_server = "MQTT_SERVER";
const int mqtt_port = 1883;
const char *mqtt_user = "mqtt_user";
const char *mqtt_pass = "pswd";
const char *mqtt_client_name = "Main_Door_sensor"; // Client connections cant have the same connection name
const char *mqtt_topic = "home/main_door/status";
const char *mqtt__vcc_topic = "home/main_door/vcc";
IPAddress ip(192, 168, 1, 50);
IPAddress gateway(192, 168, 1, 1);
IPAddress subnet(255, 255, 255, 0);

WiFiClient espClient;
PubSubClient client(espClient);

// Variables
//Hold pin will hold CH_PD HIGH till we're executing the setup, the last step would be set it LOW which will power down the ESP
int HOLD_PIN = 0;  // defines GPIO 0 as the hold pin (will hold CH_PD high untill we power down).

void setup()
{
  #ifdef DEBUG
    Serial.begin(115200);
  #endif
  pinMode(HOLD_PIN, OUTPUT);     // sets GPIO 0 to output
  digitalWrite(HOLD_PIN, HIGH);  // sets GPIO 0 to high (this holds CH_PD high even if the PIR output goes low)
  DPRINTLN(millis());

  setup_wifi();
  client.setServer(mqtt_server, mqtt_port);
  publishMessage();
  DPRINTLN(millis());
  DPRINTLN("powering down");
  //Allow a delay to let MQTT publish the message as the publish method is asyncronous, If I dont put this, the ESP powers down before the msg is published
  delay(1000);
  digitalWrite(HOLD_PIN, LOW);  // set GPIO 0 low this takes CH_PD & powers down the ESP
}

void setup_wifi()
{

  WiFi.config(ip, gateway, subnet);
  WiFi.begin(ssid, password);
  while (WiFi.status() != WL_CONNECTED)
    {
      delay(50);
    }
  DPRINT("WiFi connected, IP Address:");
  DPRINTLN(WiFi.localIP());
}


void publishMessage() {
  // Loop until we're reconnected
  char i = 0;
  while (!client.connected())
  {
    i++;
    DPRINT("Attempting MQTT connection...");
    // Attempt to connect
    if (client.connect(mqtt_client_name,mqtt_user,mqtt_pass)) {
      DPRINTLN("connected");
      // Once connected, publish an announcement...
      client.publish(mqtt_topic, "OPEN");
      DPRINTLN("published OPEN");
     
      //measure batery voltage and publish that too
      int battery_Voltage = ESP.getVcc();
      char batt_volt[6];
      itoa(battery_Voltage, batt_volt, 10);
      client.publish(mqtt__vcc_topic, batt_volt);
      DPRINTLN("published VCC");
    }
    else
    {
      DPRINT("failed, rc=");
      DPRINT(client.state());
      DPRINTLN(" try again in 2 seconds");
      delay(1000);
    }
    if(i >=3)
      break;
  }
}


void loop()
{
  //Nothing to do here as the setup does all the work and then powers down the ESP by writing a LOW signal to CH_PD 

}


2
I've attached a diagram of the full (complete) circuit, the only thing missing is my servo has 4 pin outs the additional pin being a feedback line for the hall effect encoder (attached to pin 5).

I have a feeling that part of the confusion may be that motor might be part of a larger system or interact with a series of other motors or controls, but really it's not doing any of that. The only output is the position of the motor.

3
Programming Questions / Re: NANO PWM Read and write w/...
Last post by XRAD - Today at 04:33 am
OK thank you JML.  Because I do not know enough yet about how to incorporate arrays, I decided to try to finish building the code block style to get some LEDs blinking and it works for each channel I have tested, and then convert it to an array once I understand it.

I have several delay() of functions in  my code (One currently on PWM  5 ).  This functions, but delays the program.  I have reviewed the 'blink without delay' sketches and I think that this might work for me. The issue is inserting the 'blink without delay' code for x number of LEDs and how to define multiple 'unsigned long interval = x;'  for multiple PIN outs each with different HIGH intervals....

I will spend some time reviewing Robin2's

http://forum.arduino.cc/index.php?topic=223286.0

here is current program with delay() on PWM 5. Eventually, I may have to go to a switch case for the pin outs anyway....

Code: [Select]
[code]
int PWM1 = 2;
int PWM2 = 3;
int PWM3 = 4;
int PWM4 = 5;
int PWM5 = 6;
int PWM6 = 7;

int WAV1 = 14;
int WAV2 = 15;
int WAV3 = 16;
int WAV4 = 17;
int WAV5 = 18;
int WAV6 = 19;

unsigned long duration;

void setup()
{
  Serial.begin(19200);
  pinMode(PWM1, INPUT);
  pinMode(PWM2, INPUT);
  pinMode(PWM3, INPUT);
  pinMode(PWM4, INPUT);
  pinMode(PWM5, INPUT);
  pinMode(PWM6, INPUT);

  pinMode(WAV1, OUTPUT);
  pinMode(WAV2, OUTPUT);
  pinMode(WAV3, OUTPUT);
  pinMode(WAV4, OUTPUT);
  pinMode(WAV5, OUTPUT);
  pinMode(WAV6, OUTPUT);  
}

void loop(){
{
  duration = pulseIn(PWM1, HIGH);
  Serial.print ("PWM1  ");
  Serial.print (duration);
  
}
{
  duration = pulseIn(PWM2, HIGH);
  Serial.print ("\tPWM2  ");
   if (duration > 1851 && duration < 1950)
  {
    digitalWrite(WAV2, HIGH);
    Serial.print ("T-Full  ");
  }
  
 else
  {
  digitalWrite(WAV2, LOW);  
  Serial.print(duration);
 
}
}
{
  duration = pulseIn(PWM3, HIGH);
  Serial.print ("\tPWM3  ");
  Serial.print (duration);
 
}
{
  duration = pulseIn(PWM4, HIGH);
  Serial.print ("\tPWM4  ");
  Serial.print (duration);
 
}
{
  duration = pulseIn(PWM5, HIGH);
  Serial.print ("\tPWM5  ");
 if (duration >= 1851)
  {
    digitalWrite(WAV5, HIGH);
    delay(100);
    Serial.print ("CANFIRE");
  }
  
 else
  {
  digitalWrite(WAV5, LOW);
  Serial.print(duration);

  }
}
{
  duration = pulseIn(PWM6, HIGH);
  Serial.print ("\tPWM6  ");

   if (duration >= 1851)
  {
    digitalWrite(WAV6, HIGH);
    
    Serial.println ("MGFIRE");
  }
  
 else
  {
  digitalWrite(WAV6, LOW);
  
  Serial.println (duration);
  delay(10);
  }
}
}
[/code]
4
I have a geared stepper that rotates a wheel that has an antenna mount on it. It is to tilt the antenna when I approach  a low handing garage door, or trees.

The motor only needs to move 1/4 of a turn, from antenna up, to antenna down.  Moving the stepper is no problem, but I need it to stop at the correct place, and I have two micro switches that are in parallel, so one is when it is up, and one is when it is down.

I was thinking of using an interrupt to stop movement in either direction, but I immediately saw a problem with  that.  If there is a way do use the interrupt I would like some details to explain how.

The alternative is to just allow enough pulses to move in each direction. The motor can be turned off because the gearing on the stepper makes it very difficult to turn by hand, so I am sure with the motor off, it will hold still.

I could also put stop screws to keep the antenna from overshooting where it should stop , and hitting my roof.

I also trying to use the Easy Driver to do this, and I think that might be the easiest way  to go about moving the stepper.

Any help would be appreciated, I have been away from Arduino programming for a while, and I forgot most of what I knew.

                Thanks,  Joe
5
PWM turns on/off an output (analogWrite(pin,x)) , google duty cycle.

https://m.youtube.com/watch?v=YmPziPfaByw   

Your motor may need a certain on time to get moving.

Show us a good schematic of your circuit.   
Show us a good image of your wiring. 
Give links to components.

Posting images: 
https://forum.arduino.cc/index.php?topic=519037.0     



6
I found the reason for not showing the examples. When I select a digispark board, all examples are showing up.
Now everything is clear and operational.
Thank you very much pert for your great support.
7
I'm commanding a motor with a simple analogWrite(pin,x). When testing the motor with a different value of x (from 0-255), I've noticed some weird tendencies.

The motor will always start turning at an x value of above 200. Anything below, it will sometimes start, and sometimes it won't start (I've found that it never starts below 140, but above, it's inconsistent). At first, I assumed that it was below it's minimum required voltage. However, the inconsistency makes me think it could be something else? Also, sometimes sitting the motor down onto the table with some force will cause it to start running.

Anyone have any ideas what could be causing this or how to solve the issue? 
8
Français / Re: System de remplissage d'ea...
Last post by J-M-L - Today at 04:16 am
Qu'avez vous déjà réalisé ? Quel est votre niveau de compréhension de la programmation et  du monde arduino et des composants dont vous parlez ? et quid de la partie électronique ?
9
Project Guidance / Re: Setting unique ID using an...
Last post by bontempos - Today at 04:14 am
I have got the DS2401 ICs, but I am trying to figure out how to make each device to be associated to a specific socket.

I have 16 input sockets which can be used by each device. My goal is to connect each device on a socket and identify which device is connected there. I am thinking on using one pin associated to an OneWire object on my sketch, with the help of some 74HC595 to iterate to each socket, so I can and check if any device is present at specific location. Could it be a good solution?
10
Français / Re: Utilisation carte SD
Last post by J-M-L - Today at 04:12 am
MOSI = Master OUT Slave IN
MISO = Master IN Slave OUT

Donc oui ça doit correspondre à un Data_OUT et Data_IN mais assurez vous de voir qui est le Master (et assurez vous des tensions)
Pages: [1] 2 3 ... 10