thess/callattendant

Having problem enabling MQTT

giri-v opened this issue · 23 comments

I set:
STATUS_INDICATORS = "MQTT"

When I I found I had to add paho-mqtt but still got this error:

TypeError: init() missing 1 required positional argument: 'callback_api_version'

Not sure how to proceed. All works if I set:
STATUS_INDICATORS = "NULL"

Looks like installing a version <2.0.0 solves the problem. Otherwise it needs a minor code change as follows:

client = mqtt_client.Client()
to:

client = mqtt_client.Client(mqtt_client.CallbackAPIVersion.VERSION1)
This will configure the library to use the v1 callback API

I'd like to contribute...should I fork and make changes?

Thanks for finding this. It has been a while since I have used/tested MQTT.
I have published an update (v1.7.4 pre-release) which supports both 1.x and 2.0+ Paho MQTT versions.

Fixed by: 5dc577d

I'd like to contribute...should I fork and make changes?

Yes, please feel free to join the effort. Good, clean PRs are always welcomed

Looking forward to what you might have.

@thess, can you add a section to the documentation on how to update an installation, please?

Do you need to do a release?

I'm not sure how to update my installation to incorporate this change.

So I have something for you but I'd caveat it with: This is my first ever attempt at Python, I may have incorrectly made my changes on the trunk (instead of a dev branch as you suggested). I'll try to branch, rebase and then send you a PR in the next couple of days.

ive changed the
client = mqtt_client.Client(client_id)
to:

client = mqtt_client.Client(mqtt_client.CallbackAPIVersion.VERSION1, client_id)

but i find that the mqtt not working... i new to this fork im from the original dealing with bruce 4 years ago only learning recently he had passed and was modding the code back then for mqtt as i have my own version to deal with Home Assistant..

but is there something else to get this to work? since i cant get any message when a call comes in so not sure if the mqtt is sending even though it should be sending

@comet424 - Need more information to describe your "not working" problem. Please supply the version of CA you have installed, whether you have it in a virtual environment or not and most importantly, any log output to shed some light on your issue. You should also check which version of Paho MQTT you are using.

Integration with Home Assistant is something I would be interested in.

so as in "not working" as when i setup up the login user password leave the topic set the ip address as the host.. and set the NULL to MQTT and have a call come in... in Home assistant where i use NodeRed i have it setup both Home assistant to listen and NodRed to listen to the topic "callattendant" and nothing comes through as a message... i dunno which version of the CA i recently installed it a week and ago week half and been testing it.. i also noticed bugs in it i couldnt migrate my Database from from Bruces orginal.. sure it read able but its not properly editable the "Reasons" bugger up doesnt display it doesnt save right

im currently running in Virtual venv mode.. followed forkes instructions... i did try installing it on my VM of Ubuntu i did get it installed but it was a pain just like bruces Original it just a pain to install on Ubuntu if u wanna run it on Unraid in a VM as just a RPI4..

the Paho MQTT im using is i not sure i also installed it last week so whatever that version would be from the
https://pypi.org/project/paho-mqtt/

i had also worked on trying to add extra webpage that would work in home assistant but for cell phones as at least the Orginal Callattendant didnt scroll or fit for a cell phone... so i had worked on it but cuz i wasnt good at it... and bruce was sick i couldnt get help so i had shelved it ...

i also noticed with this forked version... a bug or so i changed the the NOMBRO to "" like i had in the orignal had to check my orginal file.. i noticed.. im in canada

but what i found is i was on the phone... and an incoming calling came in.. and the Callattendant actuallaly noticed it and picked up the phone and hung up and it was a spam call and then made me have like a 3 way call me and other caller.. and now the spam caller.. all i could figure out was the NOMBRO setting it was weird.. usually Callattendant cant notice a incomming call while im on the phone... but not sure if that was the setting or not..

oh and for me to MQTT i dont use the paho-mqqt i just the mosquitto client

and reason i posted in the other forum was i figured i probably should have wrote there and not in here for help so i figured i better write in the proper section

Supplying some log output showing the failures would go a long way towards resolving your problem. Optionally, setting

DEBUG = True

in your app.cfg will put additional diagnostic info into the log.

its been 4 yrs since i delt with log files.. where does it then report the logs as its been forever

and for how i mqtt to Home assistant this is how i do it the app.py and i was trying to get help from Bruce but cant

os.system('mosquitto_pub -t "callerid/caller" -m ' + caller["NAME"] + ' -h 192.168.0.12 -d --will-qos 1 -u "mqtt-user" -P "pass"')
os.system('mosquitto_pub -t "callerid/number" -m ' + caller["NMBR"] + ' -h 192.168.0.12 -d --will-qos 1 -u "mqtt-user" -P "pass"')
os.system('mosquitto_pub -t "callerid/TIME" -m ' + caller["TIME"] + ' -h 192.168.0.12 -d --will-qos 1 -u "mqtt-user" -P "pass"')

and i do this right below where it states logs every call to the console.. problem i wanted was i wanted to be able to send the Formated number and i tried to to edit in the modem.py where it calls the formated sub routine but i couldnt get it to work

what i wanted to do was be able to mqtt as it rings to send the Formated Number and name of the caller either name it finds or whatevers saved in the database . but never solved that issue

so i edited the app.cfg changed it to True for debug and set the Nomboro back from disabled....

Perhaps your problem with MQTT is that you are not using the version of Callattendant from this repository or it is your modifications that are not working. As you noted in #35 (comment)

ive changed the
client = mqtt_client.Client(client_id)
to:
client = mqtt_client.Client(mqtt_client.CallbackAPIVersion.VERSION1, client_id)

The reference to client_id is not in this code base.

so im this repository.. callattendant... as the orginal never had MQTT..

not sure what you mean code base... but i change the code in the mqttindicatiors from what the other guy did 3 weeks ago

[giri-v](https://github.com/giri-v)
Looks like installing a version <2.0.0 solves the problem. Otherwise it needs a minor code change as follows:

client = mqtt_client.Client(client_id)
to:

client = mqtt_client.Client(mqtt_client.CallbackAPIVersion.VERSION1, client_id)
This will configure the library to use the v1 callback API

not sure what you mean code base...

This repository has been detached from the original for a while now. I started my own version (fork) of Callattendant a couple of years ago and have not had any contact with the original author.

In any event, the code reference to client_id is not in this version of CA and is most likely an error in the problem report from giri-v. I will fix that since it is causing confusion.

ya apparently orginal author has passed away from what i been told...

i thought the client_id is in this version of CA since the orginal didnt have MQTT... and i edited the client_id in the mqttindicator.py file... as the orginal never never a mqttindicator.py file

so thats what i did i changed the line in mqttindicator.py file to client = mqtt_client.Client(mqtt_client.CallbackAPIVersion.VERSION1, client_id) but it didnt solve the issue it still wouldnt transmitt message when a call came in.. so reason i added to the discussion on how do i update or what i doing wrong if the change of the 1 line fixed the issue

and what i do is i Import the MQTT in Home assistant using Node Red.. pushing into a Sensor and then i have displays that update on value change

and this is here how i use it in NodeRed... and how it imports my 3 lines but it doesnt import the callattendant one .. from the app.cfg so not sure where the log file would be for the errors?
call
and this is how i use it in Home Assistant and then i use it with ESPHOME with screens to display as calls are coming in the pop up

The log output from CA goes to stdout. If you are running CA as a system service, the log data can be examined by journalctl -xe -u callattendant. Otherwise, it is where you directed it. You might want to try running CA from a console and capture the output directly -- It's your choice.

here is log file i exported doing the journalctl -xe -u callattendant
dont know if you can see anything if your mqtt trying to work or not
log.txt

this log dump had spam caller while i was on the phone... the call attendant picked up the phone and hung up while i was already on the phone ... so it sees the incoming call even though im already On the phone so its answering the call.. but cuz its answering the call and hanging up hts basiclly letting me be connected with the spam caller and thats with the setting NOMBRO setting i should reset that back to "" for disabled... as it says for usa but usa and canada pretty much the same but here is the log anyways...

log2.txt

i going to set it to disabled... to see if it disables from answering... as i know the orginal CA never detected a call while i was on the phone but then that could be a fluke now lol

First off, it is clear you are not running a released, unmodified, version of CA. You have made modifications that more than likely are causing the adverse behavior you are witnessing.

A couple of observations:
1 - There is something causing the RING processing to be delayed enough that CA thinks ringing has stopped when clearly it hasn't.
2 - Your added MQTT implementation may be causing delays in the thread processing of incoming calls.
3 - The setting of BLOCK_SERVICE has no effect on whether a call is answered or not. It does however change thread timing.

If you want to add callerId to the MQTT reporting, you should either wait until I add it fully debugged, debug your own implementation or you are welcome to try PR #37

On the other hand, I could be completely wrong in my analysis.
HTH

ok im rem out the 3 lines so the mqtt doesnt run... so then its orginal.

and if you wanted to know the location of my 3 lines of code it was in between these

                # Log every call to the database (and console)
                call_no = self.logger.log_caller(caller, action, reason)
                print("--> {} {}: {}".format(number, action, reason))
                



                # Gather the data used to answer the call
                if caller_permitted:


so mqtt right after the print statement... .....
and i guess ill put the mqttindicator.py client line leave it or change back to orginal
as right now i have it set to

        else:
            # Version 1.x compatibility
            #client = mqtt.Client()
            client = mqtt_client.Client(mqtt_client.CallbackAPIVersion.VERSION1, client_id)

i set it it back to client = mqtt.Client() so its back to orginal
and ill test and get a log file for ya after so its back to factory

Closing this topic. OP issue resolved by #35 (comment)

Further issues with MQTT support will be on a separate topic - please.