mirror of
https://github.com/lumapu/ahoy.git
synced 2025-05-10 15:36:38 +02:00
* send values using mqtt
* only send command 0x80 to inverter, all replies 0x01, 0x02, 0x03 and 0x84 are received
This commit is contained in:
parent
c00be7bb35
commit
58d79beb8c
3 changed files with 52 additions and 14 deletions
|
@ -124,9 +124,9 @@ void app::loop(void) {
|
||||||
mFlagSend = false;
|
mFlagSend = false;
|
||||||
|
|
||||||
uint8_t size = 0;
|
uint8_t size = 0;
|
||||||
if((mSendCnt % 6) == 0)
|
//if((mSendCnt % 6) == 0)
|
||||||
size = mHoymiles->getTimePacket(mSendBuf, mTimestamp);
|
size = mHoymiles->getTimePacket(mSendBuf, mTimestamp);
|
||||||
else if((mSendCnt % 6) == 1)
|
/*else if((mSendCnt % 6) == 1)
|
||||||
size = mHoymiles->getCmdPacket(mSendBuf, 0x15, 0x81);
|
size = mHoymiles->getCmdPacket(mSendBuf, 0x15, 0x81);
|
||||||
else if((mSendCnt % 6) == 2)
|
else if((mSendCnt % 6) == 2)
|
||||||
size = mHoymiles->getCmdPacket(mSendBuf, 0x15, 0x80);
|
size = mHoymiles->getCmdPacket(mSendBuf, 0x15, 0x80);
|
||||||
|
@ -135,7 +135,7 @@ void app::loop(void) {
|
||||||
else if((mSendCnt % 6) == 4)
|
else if((mSendCnt % 6) == 4)
|
||||||
size = mHoymiles->getCmdPacket(mSendBuf, 0x15, 0x82);
|
size = mHoymiles->getCmdPacket(mSendBuf, 0x15, 0x82);
|
||||||
else if((mSendCnt % 6) == 5)
|
else if((mSendCnt % 6) == 5)
|
||||||
size = mHoymiles->getCmdPacket(mSendBuf, 0x15, 0x84);
|
size = mHoymiles->getCmdPacket(mSendBuf, 0x15, 0x84);*/
|
||||||
|
|
||||||
//Serial.println("sent packet: #" + String(mSendCnt));
|
//Serial.println("sent packet: #" + String(mSendCnt));
|
||||||
//dumpBuf(mSendBuf, size);
|
//dumpBuf(mSendBuf, size);
|
||||||
|
@ -150,6 +150,47 @@ void app::loop(void) {
|
||||||
if(mMqttEvt) {
|
if(mMqttEvt) {
|
||||||
mMqttEvt = false;
|
mMqttEvt = false;
|
||||||
mMqtt.isConnected(true);
|
mMqtt.isConnected(true);
|
||||||
|
char topic[20], val[10];
|
||||||
|
for(uint8_t i = 0; i < 4; i++) {
|
||||||
|
for(uint8_t j = 0; j < 5; j++) {
|
||||||
|
switch(j) {
|
||||||
|
default:
|
||||||
|
sprintf(topic, "ch%d/%s", i, "voltage");
|
||||||
|
sprintf(val, "%.3f", mDecoder->mData.ch_dc[i/2].u);
|
||||||
|
break;
|
||||||
|
case 1:
|
||||||
|
sprintf(topic, "ch%d/%s", i, "current");
|
||||||
|
sprintf(val, "%.3f", mDecoder->mData.ch_dc[i].i);
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
sprintf(topic, "ch%d/%s", i, "power");
|
||||||
|
sprintf(val, "%.3f", mDecoder->mData.ch_dc[i].p);
|
||||||
|
break;
|
||||||
|
case 3:
|
||||||
|
sprintf(topic, "ch%d/%s", i, "yield_day");
|
||||||
|
sprintf(val, "%.3f", (double)mDecoder->mData.ch_dc[i].y_d);
|
||||||
|
break;
|
||||||
|
case 4:
|
||||||
|
sprintf(topic, "ch%d/%s", i, "yield");
|
||||||
|
sprintf(val, "%.3f", mDecoder->mData.ch_dc[i].y_t);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if(0 != strncmp("0.000", val, 5)) {
|
||||||
|
mMqtt.sendMsg(topic, val);
|
||||||
|
delay(10);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
sprintf(val, "%.3f", mDecoder->mData.ch_ac.u);
|
||||||
|
mMqtt.sendMsg("ac/voltage", val);
|
||||||
|
delay(10);
|
||||||
|
sprintf(val, "%.3f", mDecoder->mData.ch_ac.i);
|
||||||
|
mMqtt.sendMsg("ac/current", val);
|
||||||
|
delay(10);
|
||||||
|
sprintf(val, "%.3f", mDecoder->mData.temp);
|
||||||
|
mMqtt.sendMsg("temperature", val);
|
||||||
|
delay(10);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -223,10 +264,10 @@ void app::sendPacket(uint8_t buf[], uint8_t len) {
|
||||||
mRadio->stopListening();
|
mRadio->stopListening();
|
||||||
|
|
||||||
#ifdef CHANNEL_HOP
|
#ifdef CHANNEL_HOP
|
||||||
if(mSendCnt % 6 == 0)
|
//if(mSendCnt % 6 == 0)
|
||||||
mSendChannel = mHoymiles->getNxtChannel();
|
mSendChannel = mHoymiles->getNxtChannel();
|
||||||
else
|
//else
|
||||||
mSendChannel = mHoymiles->getLastChannel();
|
// mSendChannel = mHoymiles->getLastChannel();
|
||||||
#else
|
#else
|
||||||
mSendChannel = mHoymiles->getDefaultChannel();
|
mSendChannel = mHoymiles->getDefaultChannel();
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -15,7 +15,7 @@
|
||||||
//-------------------------------------
|
//-------------------------------------
|
||||||
#define VERSION_MAJOR 0
|
#define VERSION_MAJOR 0
|
||||||
#define VERSION_MINOR 1
|
#define VERSION_MINOR 1
|
||||||
#define VERSION_PATCH 11
|
#define VERSION_PATCH 12
|
||||||
|
|
||||||
|
|
||||||
//-------------------------------------
|
//-------------------------------------
|
||||||
|
|
|
@ -31,9 +31,8 @@ class mqtt {
|
||||||
|
|
||||||
void sendMsg(const char *topic, const char *msg) {
|
void sendMsg(const char *topic, const char *msg) {
|
||||||
if(mAddressSet) {
|
if(mAddressSet) {
|
||||||
uint8_t len = MQTT_TOPIC_LEN + strlen(msg);
|
char top[64];
|
||||||
char top[len];
|
snprintf(top, 64, "%s/%s", mTopic, topic);
|
||||||
snprintf(top, len, "%s/%s", mTopic, topic);
|
|
||||||
|
|
||||||
if(!mClient->connected())
|
if(!mClient->connected())
|
||||||
reconnect();
|
reconnect();
|
||||||
|
@ -69,14 +68,12 @@ class mqtt {
|
||||||
void reconnect(void) {
|
void reconnect(void) {
|
||||||
if(!mClient->connected()) {
|
if(!mClient->connected()) {
|
||||||
String mqttId = "ESP-" + String(random(0xffff), HEX);
|
String mqttId = "ESP-" + String(random(0xffff), HEX);
|
||||||
if((strlen(mUser) > 0) && (strlen(mPwd) > 0)) {
|
if((strlen(mUser) > 0) && (strlen(mPwd) > 0))
|
||||||
mClient->connect(mqttId.c_str(), mUser, mPwd);
|
mClient->connect(mqttId.c_str(), mUser, mPwd);
|
||||||
}
|
else
|
||||||
else {
|
|
||||||
mClient->connect(mqttId.c_str());
|
mClient->connect(mqttId.c_str());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
WiFiClient mEspClient;
|
WiFiClient mEspClient;
|
||||||
PubSubClient *mClient;
|
PubSubClient *mClient;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue