MQTT for the android app

Started by Graham, January 27, 2019, 03:50:42 PM

Previous topic - Next topic

ClassicCrazy

#15
So I just flash  your bin file ?
I will give that a try .
The flash tool I used today from espeasy was a lot fanicer than their old tool

Larry
system 1
Classic 150 , 5s3p  Kyocera 135watt , 12s Soneil 2v 540amp lead crystal for 24v pack , Outback 3524 inverter
system 2
 5s 135w Kyocero , 3s3p 270w Kyocera  to Classic 150 ,   8s Kyocera 225w to Hawkes Bay Jakiper 48v 15kwh LiFePO4 , Outback VFX 3648 inverter
system 3
KID / Brat portable

ClassicCrazy

#16
I put all the flash tools from espeasy in the ClassicMQTT that I downloaded from your github .
When I open  up flash tool it does not find a bin file to flash. So I went back your github page and found a .bin file and downloaded that and placed it in the ClassicMQTT folder but flash tool still won't find it. If I open up your .bin folder it does not show anything. If I go to the ESPEASY mega folder for their flash - there is all kinds of .bin files in the Bin folder.
So I believe something is wrong with your Bin folder or format that it won't show up. It does not say it is a zip file so I did not unzip it - just placed it in the folder as it was .

Update - I found that I just needed to put the .bin file in the Bin folder and I think it is flashing okay now .
I flashed it - but I don't know what I am supposed to do next. I can't seem to connect to it on serial port. I tried flashing again with flash tool and put in my wifi settings but don't see it show up .
I tried just about every baud setting to try and get into it on serial terminal program via computer but nothing shows anything legible

Larry
system 1
Classic 150 , 5s3p  Kyocera 135watt , 12s Soneil 2v 540amp lead crystal for 24v pack , Outback 3524 inverter
system 2
 5s 135w Kyocero , 3s3p 270w Kyocera  to Classic 150 ,   8s Kyocera 225w to Hawkes Bay Jakiper 48v 15kwh LiFePO4 , Outback VFX 3648 inverter
system 3
KID / Brat portable

Graham

Quote from: ClassicCrazy on March 07, 2019, 10:40:38 PM
...
Update - I found that I just needed to put the .bin file in the Bin folder and I think it is flashing okay now .
I flashed it - but I don't know what I am supposed to do next. I can't seem to connect to it on serial port. I tried flashing again with flash tool and put in my wifi settings but don't see it show up .
I tried just about every baud setting to try and get into it on serial terminal program via computer but nothing shows anything legible

Larry

Are you using the ESP32 or the ESP8266?
the bin file is compiled for the ESP32 since the 8266 doesn't have enough space for the OTA feature
https://www.amazon.ca/Lidahaotin-ESP-WROOM-32-Development-Dual-Mode-Bluetooth/dp/B07JVNVS8D/ref=sr_1_4?keywords=esp32+wroom+development+board&qid=1552048619&s=gateway&sr=8-4

I was able to flash the ESP32 using the expressif flash tool http://iot-bits.com/esp32/esp32-flash-download-tool-tutorial

Once it is flashed and rebooted you should see it setup as an access point in the serial terminal, once you connect to the access point, open the web page at 192.168.4.1 and click 'Configure WIFI' to setup the wifi credentials, classic IP/Port, Blynk token and the MQTT credentials.


Graham.
Off-Grid Island cottage, Lac Simon QC Canada
370 Ahrs @ 24V (4 8L16 batteries)
4 x 250watt panels on dual axis trackers http://tinyurl.com/hfpkgr5
Classic 150, Whizbang Jr.
Android Monitor: http://tinyurl.com/lomzq3s

ClassicCrazy

oh yeah I used an esp8266 - have to get an ESP32 . Have been holding off on getting one of those since every time I get something it is outdated by a better version - ha ha !

Larry

system 1
Classic 150 , 5s3p  Kyocera 135watt , 12s Soneil 2v 540amp lead crystal for 24v pack , Outback 3524 inverter
system 2
 5s 135w Kyocero , 3s3p 270w Kyocera  to Classic 150 ,   8s Kyocera 225w to Hawkes Bay Jakiper 48v 15kwh LiFePO4 , Outback VFX 3648 inverter
system 3
KID / Brat portable

mcsarge

Graham,

I am trying to compile your ClassicMQTT code and I am having a tough time getting all the libraries and the correct versions. Do you happen to have a listing of the ones you are using?

Also, in the Classic App for MQTT, the length of the hostname is pretty short - I am hosting an MQTT server on Azure, and the host name is quite long. Any chance of opening that up for more characters? Lastly in the Classic App, the length of the field that holds the port number is short too - I use nGrok to forward port 502 outside the cellular firewall, but the port number assigned is 1 character longer than your app allows for the port number.

Matt
Off Grid Island in Ontario Canada (Beaverstone Bay)
Primary: Classic 150 + wbjr; 3s2p HES 270watt
Winter: SolarBoost 50 MPPT (into wbjr); 2 x Sharp NE-80EJEA 80watt
Pack: 4s2p ROLLS S6-460AGM 6V for 24V pack
Inverter/Charger: Trace DR2424
Call Sign: KG4EUF

Graham

Hi Matt,

I'm updating the code to use a more recent library, I'll post an update later today...

My development environment is
Visual Studio Code with the PlatformIO extension
it will download and install all dependencies defined in the platform.ini file


Graham.
Off-Grid Island cottage, Lac Simon QC Canada
370 Ahrs @ 24V (4 8L16 batteries)
4 x 250watt panels on dual axis trackers http://tinyurl.com/hfpkgr5
Classic 150, Whizbang Jr.
Android Monitor: http://tinyurl.com/lomzq3s

mcsarge

Graham,

I will look into using PlatformIO in VSC.

I have a Raspberry Pi local to my Classic (on a remote island in Canada) and so I am working on a python implementation of the MODBUS-to-MQTT tool. I have setup a server in the cloud using my Azure $150/month credit and have install MQTT on it and plan to have the python code publish to that.

I will need to implement the feature that you have that allows a subscriber to notify the publisher that someone is listening and so publish at a faster rate.

Many thanks for all this work! If I get the python code working, should I add it to your repository? Let me know.

Matt
Off Grid Island in Ontario Canada (Beaverstone Bay)
Primary: Classic 150 + wbjr; 3s2p HES 270watt
Winter: SolarBoost 50 MPPT (into wbjr); 2 x Sharp NE-80EJEA 80watt
Pack: 4s2p ROLLS S6-460AGM 6V for 24V pack
Inverter/Charger: Trace DR2424
Call Sign: KG4EUF

Graham

Matt,

I checked in an update to the ClassicMQTT github repo that uses a more recent Wifi library (IOTWebConf) plus an async MQTT client.

I tested it with my android app that can subscribe to mqtt,
The ESP code will start in AP mode for 30 seconds then switch to STATION if an SSID/PW is configured
The root topic is the 'Thing Name' in the setup.

Graham.

Off-Grid Island cottage, Lac Simon QC Canada
370 Ahrs @ 24V (4 8L16 batteries)
4 x 250watt panels on dual axis trackers http://tinyurl.com/hfpkgr5
Classic 150, Whizbang Jr.
Android Monitor: http://tinyurl.com/lomzq3s

mcsarge

Any idea what the password to the AP is so I can configure the device?

Matt
Off Grid Island in Ontario Canada (Beaverstone Bay)
Primary: Classic 150 + wbjr; 3s2p HES 270watt
Winter: SolarBoost 50 MPPT (into wbjr); 2 x Sharp NE-80EJEA 80watt
Pack: 4s2p ROLLS S6-460AGM 6V for 24V pack
Inverter/Charger: Trace DR2424
Call Sign: KG4EUF

ClassicCrazy

Quote from: mcsarge on December 18, 2019, 11:06:13 PM
Any idea what the password to the AP is so I can configure the device?

Matt

If it is like the other esp8266 I have used you probably don't need a password - just leave it blank or enter one of your own when you put in your wireless info. Then look for the address it connects to on the wifi and connect up to it directly - you would be able to configure it there. But not sure if this is like the others.

I dug out an esp32 board and might give this a try in the next day or two. Kind of late here now.  I am happy because I just made a CI-V control cable for my Icom 706MKIIG using just a usb to ttl board , a resistor and diode and it works ! I am trying out the digital modes . Anyway I had to boast about my electronics ability here - ha ha . 10 minutes to make it, but a few hours of digging around on the internet on how to make one.

Larry
system 1
Classic 150 , 5s3p  Kyocera 135watt , 12s Soneil 2v 540amp lead crystal for 24v pack , Outback 3524 inverter
system 2
 5s 135w Kyocero , 3s3p 270w Kyocera  to Classic 150 ,   8s Kyocera 225w to Hawkes Bay Jakiper 48v 15kwh LiFePO4 , Outback VFX 3648 inverter
system 3
KID / Brat portable

Graham

It should be 'ClassicMQTT'

Connect to the 'ClassicMQTT' access point
browse to 192.168.4.1

Once wifi is setup you can access the config page by browsing to the IP of the esp32 with 'admin' username and 'ClassicMQTT' as pw (or whatever you put in "AP Password")


more info is available at https://github.com/prampec/IotWebConf
Off-Grid Island cottage, Lac Simon QC Canada
370 Ahrs @ 24V (4 8L16 batteries)
4 x 250watt panels on dual axis trackers http://tinyurl.com/hfpkgr5
Classic 150, Whizbang Jr.
Android Monitor: http://tinyurl.com/lomzq3s

mcsarge

After examining the code, the initial password is ClassicMQTT.

I was able to get the esp32 to connect to my Classic using ngrok (I had to expand the digits allowed for saving the port number) and also connect to my MQTT server.

I got some weird numbers being posted to the MQTT server. Any thoughts on this?


{
  "BatTemperature": 6536.31,
  "NetAmpHours": 0,
  "ChargeState": 0,
  "InfoFlagsBits": -1308610300,
  "ReasonForResting": 104,
  "NegativeAmpHours": -8539,
  "BatVoltage": 24.91,
  "PVVoltage": 9.41,
  "VbattRegSetPTmpComp": 30.6,
  "TotalAmpHours": 536,
  "WhizbangBatCurrent": 6553.01,
  "BatCurrent": 0.01,
  "PVCurrent": 0.01,
  "ConnectionState": 0,
  "EnergyToday": 0.01,
  "EqualizeTime": 10800,
  "SOC": 98,
  "Aux1": false,
  "Aux2": false,
  "Power": 0.01,
  "FETTemperature": 6541.61,
  "PositiveAmpHours": 16014,
  "TotalEnergy": 581.91,
  "FloatTimeTodaySeconds": 0,
  "RemainingAmpHours": 529,
  "AbsorbTime": 18000,
  "ShuntTemperature": -14.99,
  "PCBTemperature": 6550.01
}
Off Grid Island in Ontario Canada (Beaverstone Bay)
Primary: Classic 150 + wbjr; 3s2p HES 270watt
Winter: SolarBoost 50 MPPT (into wbjr); 2 x Sharp NE-80EJEA 80watt
Pack: 4s2p ROLLS S6-460AGM 6V for 24V pack
Inverter/Charger: Trace DR2424
Call Sign: KG4EUF

Graham

hmm...

I had to comment out the NetAmpHours but the other values look ok


I'm getting this in MQTT.fx subscribed to the ClassicMQTT/classic/stat/readings topic

{
  "BatTemperature": 18.81,
  "NetAmpHours": 0,
  "ChargeState": 0,
  "InfoFlagsBits": -1577046016,
  "ReasonForResting": 104,
  "NegativeAmpHours": -1399,
  "BatVoltage": 13.71,
  "PVVoltage": 16.11,
  "VbattRegSetPTmpComp": 13.6,
  "TotalAmpHours": 63,
  "WhizbangBatCurrent": 0.21,
  "BatCurrent": 0.71,
  "PVCurrent": 0.61,
  "ConnectionState": 0,
  "EnergyToday": 0.11,
  "EqualizeTime": 7200,
  "SOC": 100,
  "Aux1": false,
  "Aux2": false,
  "Power": 8.01,
  "FETTemperature": 32.11,
  "PositiveAmpHours": 2000,
  "TotalEnergy": 103.91,
  "FloatTimeTodaySeconds": 40421,
  "RemainingAmpHours": 63,
  "AbsorbTime": 7200,
  "ShuntTemperature": 24.01,
  "PCBTemperature": 40.01
}
Off-Grid Island cottage, Lac Simon QC Canada
370 Ahrs @ 24V (4 8L16 batteries)
4 x 250watt panels on dual axis trackers http://tinyurl.com/hfpkgr5
Classic 150, Whizbang Jr.
Android Monitor: http://tinyurl.com/lomzq3s

mcsarge

It looks like the 1 byte values are OK, but the 2 byte values are messed up. Battery Temp? It is negative for me now, so maybe it is that your code is not accounting for 2's complement negative numbers?

Matt
Off Grid Island in Ontario Canada (Beaverstone Bay)
Primary: Classic 150 + wbjr; 3s2p HES 270watt
Winter: SolarBoost 50 MPPT (into wbjr); 2 x Sharp NE-80EJEA 80watt
Pack: 4s2p ROLLS S6-460AGM 6V for 24V pack
Inverter/Charger: Trace DR2424
Call Sign: KG4EUF

mcsarge

Here is how I fixed this. The number in temperature is a signed 16 bit integer, so convert it to a signed int first, then divide it by the factor:

float GetFloatValue(int index, uint8_t* data, float div = 1.0) {
   index *= 2;
   int16_t temp = (data[index] << 8 | data[index + 1]);
   return  temp/div;
}

Matt
Off Grid Island in Ontario Canada (Beaverstone Bay)
Primary: Classic 150 + wbjr; 3s2p HES 270watt
Winter: SolarBoost 50 MPPT (into wbjr); 2 x Sharp NE-80EJEA 80watt
Pack: 4s2p ROLLS S6-460AGM 6V for 24V pack
Inverter/Charger: Trace DR2424
Call Sign: KG4EUF