Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

More usage examples or ? #6

Open
mr-sneezy opened this issue Aug 17, 2021 · 21 comments
Open

More usage examples or ? #6

mr-sneezy opened this issue Aug 17, 2021 · 21 comments

Comments

@mr-sneezy
Copy link

mr-sneezy commented Aug 17, 2021

I may have bitten off more than I can chew with my own fragmented coding knowledge (or lack of) with this version.
I've compiled the example ino and loaded to the Wemos D1 Mini, and connected to the Efergy E2.
In a serial terminal at 74880 baud, I see the ESP8266 serial boot message, then some initialization message from the firmware relating to the example settings, but then nothing else after that at all. No esp AP on air to connect too for configuration...

Have I mistakenly thought that there would be an AP on air to do the MQTT configuration etc, similar to what the original code readme describes, or is there a process I've not understood to configure wifi and MQTT settings for my network or get the Efergys TX ID with the library code ?

Sorry for the long winded question.

Serial terminal output.

ets Jan 8 2013,rst cause:2, boot mode:(3,7)

load 0x4010f000, len 3460, room 16

tail 4

chksum 0xcc

load 0x3fff20b8, len 40, room 4

tail 4

chksum 0xc9

csum 0xc9

v00044b70

~ld

[00d 00:00.01s] Efergy Monitor has intitialized.

                                              [00d 00:00.01s] ADDED TX 2526 

with 20 events logged, status will change@ 80mA, report@ 60 seconds

@steven-geo
Copy link
Member

Yep, more examples are needed. This version 2 module is just the code for the Efergy Component, Wifi, MQTT is now not part of this code any more, so user can utilise the library how they need.

I have just pushed an example with Wifi and Slack if that helps. you'll need to load the MQTT module and add that back in if you need. Hopefully that gets you underway.

Documentation will happen at some point. :)

@mr-sneezy
Copy link
Author

Thanks, appreciate the new example. Having a play to see how far into it I can get.

I use Telegram for event messaging out of Home Assistant with a ton of entities, not heard of Slack before tonight so will have to see I can adapt.

BTW, how did you derive your TX ID initially to enter that into setup ?
i.e. Efergymon.setID(,12,50,90);

@steven-geo
Copy link
Member

Create a loop of Efergymon.getjsonevent() and print the json str to console, it will dump the packets received, and include an 'id' object in the json payload. I recommend labelling any transmitters you have so you can identify the tx id later.

@mr-sneezy
Copy link
Author

I stripped out the Slack code from the example and tried to work this out, but then after three or four JSON beginners tutorials on Youtube and reading stuff the ArduinoJSON website I'm still not able to work out how dump the objects from the efergy library to the arduino terminal. I've not looked at any JSON before this and it shows.
I'll ask on the Home Assistant forum if anyone has used the library, as I think it might be able to used with ESPhome if values can be accessed within it and used as sensors...

@steven-geo
Copy link
Member

Take a Look here for the JSON Object Names:
https://github.com/hardtechnology/efergy_v2/blob/master/efergy.cpp#L298

And here on how to access the fields
https://github.com/hardtechnology/efergy_v2/blob/master/examples/advanced_wifi_slack.ino#L68

That should let you get the data out into a variable of your choice. you can see in the example we are getting the 'id' object out of the son dictionary to use in our transmitter notification routine.

@mr-sneezy
Copy link
Author

mr-sneezy commented Aug 19, 2021

Thanks for the pointers, I'm trying this loop below currently as a general test if I can get the values, but getting 0's from all variables including the timestamp. (I've not shown the setup block as it's same as your examples minus the Slackpost code lines).

//  if (Efergymon.mainloop()) {
//    if (bool(Efergymon.getjsonevent()["changed"])) {
      bool tx_status = bool(Efergymon.getjsonevent()["status"]);
      int tx_id = int(Efergymon.getjsonevent()["id"]);
      int ts_now = int(Efergymon.getjsonevent()["ts"]);
      Serial.print("tx_id ");
      Serial.println(tx_id);
      Serial.print("tx_status ");
      Serial.println(tx_status);
      Serial.print("ts_now ");
      Serial.println(ts_now);
//    }
  yield();
//  }
}

@steven-geo
Copy link
Member

I notice you have the mainloop commented out, this will mean packets are not getting received, so it is possible this is just looping through empty data - This would return Null/None/False or 0 depending on the data type. Otherwise looks sensible.

@mr-sneezy
Copy link
Author

Modified to use the mainloop (I was not sure if I had to poll this or if it updated in the background).
Now have it in the loop, now however I get nothing printed after the IP address (from setup).
Does this mean my esp is not decoding ?
I have checked the bit frames out of the Efergy E2 with my oscilloscope and they are present on D0 of the Wemos at 2.5V and bit edges look sharp.

void loop() {
  if (Efergymon.mainloop()) {
//    if (bool(Efergymon.getjsonevent()["changed"])) {
      bool tx_status = bool(Efergymon.getjsonevent()["status"]);
      int tx_id = int(Efergymon.getjsonevent()["id"]);
      int ts_now = int(Efergymon.getjsonevent()["ts"]);
      Serial.print("tx_id ");
      Serial.println(tx_id);
      Serial.print("tx_status ");
      Serial.println(tx_status);
      Serial.print("ts_now ");
      Serial.println(ts_now);
//    }
  yield();
  }
}

@steven-geo
Copy link
Member

steven-geo commented Aug 19, 2021

You should be getting something. Can you set this in your Arduino code? This will dump out a heap of information about the Radio RX and decoding being performed for you. This might enlighten if we are beginning to decode anything and if there are errors.

#define DEBUG 1

@steven-geo
Copy link
Member

Actually if you remove the 'if' around mainloop, as you won't have any Transmitters Identified, it will return a False and not run the code in the loop.
So run Efergymon.mainloop() but then just continue in the main loop, then you should see heaps with debug turned on as well, and be able to identify your transmitter.

@mr-sneezy
Copy link
Author

Thanks. Removed the if around the mainloop and set #define DEBUG from 0 to 1.
Oddly, not much changed in the terminal. Here's a chunk of the dump from as it finished initialization...

[00d 00:00.01s] Efergy Monitor has intitialized.
[00d 00:00.01s] ADDED TX 1234 with 12 events logged, status will change@ 50mA, report@ 90 seconds
Arduino Source File: efergy_advanced.ino
Connecting to Wifi.....Connected. (192.168.0.156)tx_id 0
tx_status 0
ts_now 0
tx_id 0
tx_status 0
ts_now 0
tx_id 0
tx_status 0
ts_now 0
tx_id 0
tx_status 0
ts_now 0
tx_id 0
tx_status 0
ts_now 0
tx_id 0
tx_status 0
ts_now 0
tx_id 0
tx_status 0
ts_now 0
tx_id 0

loop is now looking like this

void loop() {
      Efergymon.mainloop();
//    if (bool(Efergymon.getjsonevent()["changed"])) {
      bool tx_status = bool(Efergymon.getjsonevent()["status"]);
      int tx_id = int(Efergymon.getjsonevent()["id"]);
      int ts_now = int(Efergymon.getjsonevent()["ts"]);
      Serial.print("tx_id ");
      Serial.println(tx_id);
      Serial.print("tx_status ");
      Serial.println(tx_status);
      Serial.print("ts_now ");
      Serial.println(ts_now);
//    }
  yield();
//  }
}

@steven-geo
Copy link
Member

Yeah, looks like you aren't receiving any data. Double check the inpin is set correctly to D0 and physically connected. I do notice it appears you aren't in debug mode still. When starting you should see a message like below on the console to indicate debugging is on
_debug=ON - T=Timeout, S=Start, b=bit, o=Rxtimeout, L=loop routine, E=End of Packet

@mr-sneezy
Copy link
Author

OK I'll double check the signal on D0.
Here's the whole code (minus my real WiFi SSID and PW), in case I've dumb-assed it someplace.
Debug is set to 1.

// Version 2021.8.16 - August 2021

// This requires the following Libraries to be installed (see includes for links)
// ArduinoJSON 6.18.3
// ESP8266 1.0.0
// WiFiManager 0.12.0
// PubSubClient 2.6.0

//#include <FS.h>                   //this needs to be first, or it all crashes and burns...
//#include <ESP8266WiFi.h>          //https://github.com/esp8266/Arduino
//#include <DNSServer.h>
//#include <ESP8266WebServer.h>
//#include <WiFiManager.h>          //https://github.com/tzapu/WiFiManager
//#include <ArduinoJson.h>          //https://github.com/bblanchon/ArduinoJson
//#include <SPI.h>
//#include <PubSubClient.h>         //https://github.com/knolleary/pubsubclient
#include <efergy.h>

#include <ESP8266WiFi.h>
#include <WiFiClientSecure.h>

//SSL Client Variable
WiFiClientSecure client;

// slack webhook host and endpoint information
//const char* host = "hooks.slack.com";
//const char* SECRET_SlackWebhookURL = "/services/XXXXX/YYYYYYY"; //Your Slack Webhook

// Slack Channel Info, Bot User Name, and Message
//const String slack_username = "Efergy";

//SSID of your network
char ssid[] = "My_SSID";
//password of your WPA Network
char pass[] = "My passowrd";


#define DEBUG 1
#define inpin 16          //Input pin (DATA_OUT from A72C01) on pin 2 (D3) (Pin D0 on the Wemos D1 mini)
#define voltage 240

efergy Efergymon(inpin,DEBUG,voltage);  // Define Efergy Module to look after radio and packet decoding

void setup() {
  Efergymon.begin(74880);
  //setID (int id, int depth, unsigned long statusmA, int intervalsecs)
  // On mA Should be >10mA above Standby/Off to prevent false triggering
  Efergymon.setID(1234,12,50,90);  // log Tx 12345, depth of 12 records (@6 seconds = 2 minutes), On is considered over 40mA, report @ 120 seconds
  WiFi.begin(ssid,pass);
  char *SOURCE_FILENAME = __FILE__;
  Serial.print("\nArduino Source File: ");
  Serial.print(SOURCE_FILENAME);
  Serial.print("\nConnecting to Wifi.");
  while (WiFi.status() != WL_CONNECTED) {
    Serial.print(".");
    // wait 1 second for re-trying
    delay(1000);
  }
  Serial.print("Connected. (");
  Serial.print(WiFi.localIP());
  Serial.print(")");
  // Wait a little to allow network to stabilise
  delay(1000);
  delay(1000);
  delay(1000);
//  slackPost("#general","Power Monitor Restarted...");
}

void loop() {
      Efergymon.mainloop();
//    if (bool(Efergymon.getjsonevent()["changed"])) {
      bool tx_status = bool(Efergymon.getjsonevent()["status"]);
      int tx_id = int(Efergymon.getjsonevent()["id"]);
      int ts_now = int(Efergymon.getjsonevent()["ts"]);
      Serial.print("tx_id ");
      Serial.println(tx_id);
      Serial.print("tx_status ");
      Serial.println(tx_status);
      Serial.print("ts_now ");
      Serial.println(ts_now);
//    }
  yield();
//  }
}

@mr-sneezy
Copy link
Author

Also tried reassigning the data input pin to GPIO4 (D2), compiled and switched the cable. Same result as above.

@mr-sneezy
Copy link
Author

mr-sneezy commented Aug 22, 2021

I tried something more basic today. Created a very small sketch that just reads pin 16 (D0 efergy signal) into a boolean and then right away sets pin 4 (D2) to that boolean in a tight loop. Digital equivalent of an analogue opamp 'follower' I guess...
The data is good. The CRO shows pin 4 output mirrors the waveform seen at input pin 16 (within the loop time), so confirming the Efergy E2 RX signal is being read fine by the ESP8266.
Now need to see why Debug is not working. Does it need to be also set in the Efergy library ?

@SarahDal
Copy link

I know it's been 2 years now, but did you ever get this working? I'm also stuck on not recieving any data

@steven-geo
Copy link
Member

Hi @SarahDal It is definately working as it has been running for me for a couple of years. Haven't got back to the doco as I haven't had to touch it for a while to remind me. :) If you haven't had a look at some of the notes in this thread, please do, are you experiencing the exact same thing as mr-sneezy? I'm starting to think maybe there is a different style of receiver.

@SarahDal
Copy link

Hi Steven, thanks so much for replying! Yes exact same errors, I've gone through this thread . Also, I see that a debug level was added, but I can't seem to set this, any number after #define DEBUG just returns the same level of info as #define DEBUG 1. Is there a different way to get the different debug levels?

@steven-geo
Copy link
Member

Just Enable debug like shown here in the example scripts:

@SarahDal
Copy link

SarahDal commented Aug 7, 2023

Yes, debug is on, looks like I'm not getting any data. I can measure voltage change on the data wire, so I think there's something being sent? But all I recieve is

17:17:04.405 -> [00d 00:00.01s] DEBUG IS ON - T=Timeout, S=Start, b=bit, o=Rxtimeout, L=loop routine, E=End of Packet
17:17:04.405 -> [00d 00:00.01s] Efergy Monitor has intitialized.
17:17:04.405 -> [00d 00:00.01s] ADDED TX 12345 with 20 events logged, status will change@ 0mA, report@ 60 secondstx_id 0
17:17:05.417 -> tx_status 0
17:17:05.417 -> ts_now 0
17:17:06.425 -> tx_id 0
17:17:06.425 -> tx_status 0
17:17:06.425 -> ts_now 0
17:17:07.437 -> tx_id 0

@steven-geo
Copy link
Member

OK. The first couple of things to confirm.

  1. Are you using an actual Efergy Receiver device - as the wireless protocol won't work with the common 433MHz receivers?
  2. Check that you have done the always on mod. Guides are in the old repo still. See the image files here: https://github.com/hardtechnology/EfergyMQTT
  3. We would need to get an oscilloscope out to see if there is any data being sent to the Arduino. The only thing I'm thinking of, is maybe in different parts of the world there is a slightly different standard causing problems with the software, but no one has been able to confirm/deny this yet.

Home that helps.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants