-
Notifications
You must be signed in to change notification settings - Fork 636
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
Support Shelly 2.5 #1827
Support Shelly 2.5 #1827
Conversation
Not seeing any warning with the latest commit 🤷♂
Already discussed in gitter. You can use just one instance + some internal configuration. If you want to keep combined reading, this can be an optional flag (e.g. specific mode for per-relay readings, same + combined and only combined). As already mentioned in the #1822, BMX280 is one example of magnitude config. PZEM004T takes this further, using magnitude list multiple times for the reasons described here. IANAL, but I think the copyright comment should include you too? Maybe even with the comment below |
First of all, thanks for your review and your time. I would like to make those changes by myself then you just need to review it. I'm going to continue this PR tomorrow afternoon. 🎉 |
Hi @mcspr I got an error trying to use vector to read and write the current and power values.
I have let you the last code I have, but I have changed many times trying to fix it. |
I don't know how to implement energy to save it, etc... I guess it should have something generic implemented to use, or every current metering sensor it's implementing the energy in its own way ?? |
ref #1832 (comment), Sidenote: how expensive it would be to use double instead of float? I have noticed that pzem api uses it too. |
code/espurna/sensors/ADE7953Sensor.h
Outdated
_ready = true; | ||
} | ||
|
||
int Ade7953RegSize(uint16_t reg) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This might as well be static, since we don't use any member access. And we already are inside a class, Ade7953 prefix is redundant.
I was somewhat confused by the sizing function, is this mentioned somewhere in the datasheet?
Kind-of related
If it is really how it works, I tried making it more compact (idk about what is more readable though...)
const int reg_size_new(const uint16_t reg) {
const uint8_t mask = ((reg >> 8) & 0b1111); // edit: this was a redundant & 0b11111111, and is this even needed?
if (!mask || (mask & 0b1100)) {
return 1;
} else if (mask & 0b0011) {
return mask + 1;
}
return 0;
}
You can try this with ~/.platformio/packages/toolchain-xtensa/bin/xtensa-lx106-elf-gdb
(you'll need start building something with [email protected]
platform first, it will move the old one to a separate dir)
(gdb) disassemble reg_size
Dump of assembler code for function reg_size(unsigned short):
0x40201018 <+0>: extui a2, a2, 8, 4
0x4020101b <+3>: movi.n a3, 8
0x4020101d <+5>: bltu a3, a2, 0x40201069 <reg_size(unsigned short)+81>
0x40201020 <+8>: l32r a3, 0x40201014
0x40201023 <+11>: addx4 a2, a2, a3
0x40201026 <+14>: l32i.n a2, a2, 0
0x40201028 <+16>: jx a2
0x4020102b <+19>: and a6, a3, a0
0x4020102e <+22>: excw
0x40201031 <+25>: excw
0x40201034 <+28>: or a1, a0, a5
0x40201037 <+31>: and a5, a5, a4
0x4020103a <+34>: excw
0x4020103d <+37>: excw
0x40201040 <+40>: s32i.n a6, a0, 4
0x40201042 <+42>: excw
0x40201045 <+45>: excw
0x40201048 <+48>: excw
0x4020104b <+51>: and a6, a3, a4
0x4020104e <+54>: excw
0x40201051 <+57>: s8i a0, a6, 0
0x40201054 <+60>: andbc b0, b12, b0
0x40201057 <+63>: addi.n a2, a2, 1
0x40201059 <+65>: j 0x4020105e <reg_size(unsigned short)+70>
0x4020105c <+68>: movi.n a2, 0
0x4020105e <+70>: addi.n a2, a2, 1
0x40201060 <+72>: j 0x40201065 <reg_size(unsigned short)+77>
0x40201063 <+75>: movi.n a2, 0
0x40201065 <+77>: addi.n a2, a2, 1
0x40201067 <+79>: ret.n
0x40201069 <+81>: movi.n a2, 0
0x4020106b <+83>: ret.n
(gdb) disassemble reg_size_new
Dump of assembler code for function reg_size_new(unsigned short):
0x40202e9c <+0>: extui a3, a2, 8, 8
0x40202e9f <+3>: extui a5, a3, 0, 4 // edit: this is the "& 0b1111" aka bitfield extraction
0x40202ea2 <+6>: movi.n a2, 1
0x40202ea4 <+8>: beqz.n a5, 0x40202eb8 <reg_size_new(unsigned short)+28>
0x40202ea6 <+10>: movi.n a4, 12
0x40202ea8 <+12>: and a4, a3, a4
0x40202eab <+15>: bnez.n a4, 0x40202eb8 <reg_size_new(unsigned short)+28>
0x40202ead <+17>: add.n a5, a5, a2
0x40202eaf <+19>: extui a3, a3, 0, 2
0x40202eb2 <+22>: or a2, a4, a4
0x40202eb5 <+25>: movnez a2, a5, a3
0x40202eb8 <+28>: ret.n
At least what it seems like, that the code size goes down 77 bytes.
edit: ...it might also might not matter at all. i will try with full build later. current tests are with __attribute__((noinline))
an a small test project
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I need to learn more about moving bytes, I'm not really sure what reg_size does, but it seems to be a very important function.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And just to be clear about this, what happens is:
>>> '{:#06b}'.format(0x31C >> 8)
'0b0011'
>>> '{:#06b}'.format(0x21C >> 8)
'0b0010'
Then, when checking last 2 bits
>>> (0b0011 & 0b0011) + 1
4
>>> (0b0010 & 0b0011) + 1
3
So, the 0x3... prefix contains 4 bytes => 32 bits and 0x2... contains 3 bytes => 24 bits
Here you can play if you want with the new |
Should work? |
Thanks!! @mcspr I'm going to test it right now. About energy?
|
_sensorEnergyTotal(index), _sensorEnergyTotal(index, value) ? see sensor.ino |
@tonilopezmr any luck so far? is energy saving still a problem? |
I sorry I was on holidays, yes, I need to implement it, also I need to fix a problem with led in GPIO0, it's not working, as you can see the configuration it seems right, but GPIO0 is not set as |
I thought |
Sure, that's what I was thinking. And idk why I was always referring to the PZEM sensor, EmonADS1X15Sensor.h also supports multiple "ports" and is based on the EmonSensor / I2CSensor. It is analog converter, though... So, for example, rms value is manually calculated while ADE chip already does this for us. -- edit: e.g. zero line crossing cycles, depending on ac frequency (is that what they mean by half line cycles, on just one side?). and energy register, which could be avoided and approximated via power value, is expected to remain the same for some time:
-- |
Nice. BTW, while I was describing that energy accumulator, I missed that it needs to be explicitly enabled via ACCMODE, LCYCMODE and LINECYC registers. As I understood it, AENERGY... registers will contain per-cycle values and would be immediately reset to 0 after i2c read is done. Only after next cycle finishes ADE will update the register. Calibration is also missing, that is something to add later. See A/B WGAIN, A/B IGAIN Does it make sense to save the first "dev" at all? edit: Maybe it should be a sensor module option, combining all of energy values into one? Per-sensor or globally. I'll clean up flow a bit, combining with other sensors to avoid having special conditional handling per sensor type. Maybe also finally fix reset timestamping... |
I think for a first "dev" version it's fine, I have been testing this weekend and works fine, I would like to improve my knowledge about I2C and ADE, I would create an ISSUE to work on getting energy from ADE sensor, with this comment's help. can you give me more information about reading those values using cli commands? do you mean espurna commands? Thanks! |
Yes, terminal. Something to inspect sensor state, which in this case is to read configuration and value registers. edit: and write too, since energy registers need config |
@@ -462,18 +462,37 @@ void _sensorResetTS() { | |||
#endif | |||
} | |||
|
|||
double _sensorEnergyTotal() { | |||
double _sensorEnergyTotal(unsigned int index = -1) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I missed this earlier... note the unsigned
:) Fixed via #1875
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you!
📌 References
💣 Issue
🎩 What is the goal?
Integrate Shelly 2.5 with espurna to control the relay, control built-in led, read wall switch changes, get voltage, current, and temperature.
📝 How is it being implemented?
GPIO4
, Relay 2GPIO15
GPIO13
, Relay 2GPIO5
0x38
, SDAGPIO12
and SCLGPIO14
i2c.ino
because I see only support for reading and write up touint16
, Do I need to adduint32
functions version?._relay
configuration which could beALL
,RELAY_1
orRELAY_2
(this was my first attempt) to show (RELAY 1 + RELAY 2) consumption, RELAY 1 and RELAY 2. (See on the picture below)GPIO0
with a reverse signal.NTCSensor
GPIO2
i2c.ino
and I would like to remove some compile warnings 💯This is how looks like
#0
are (RELAY 1 + RELAY 2) consumption,#1
Relay 1, and#2
Relay 2.