No data retrieved with AGI

Dialplan
exten => 123,1,Answer()
same => n,AGI(/var/lib/asterisk/agi-bin/roomdata.py)
same => n,NoOp(TEMP: ${TEMP}) ; Log the value of TEMP for debugging purposes
same => n,Playback(current-temp1)
same => n,SayAlpha(${TEMP})
same => n,Hangup()

#!/usr/bin/python3

#import agi
import MySQLdb
import sys
from asterisk.agi import AGI
#import MySQLdb

agi = AGI()

mysql = MySQLdb.connect(host=“localhost”,user=“asterisk”,passwd=“YouNeedAReallyGoodPasswordHereToo”,db=“asterisk”)

db = mysql.cursor()

db.execute(“”“SELECT temperature FROM temperature ORDER BY id DESC LIMIT 1"”")

new_temp= db.fetchone()
db.close

new_temperature = int(new_temp[0])

agi.set_variable(“TEMP”,new_temperature)

– <PJSIP/SOFTPHONE_B-00000018>AGI Script /var/lib/asterisk/agi-bin/roomdata.py completed, returning 0
– Executing [123@sets:3] NoOp(“PJSIP/SOFTPHONE_B-00000018”, "TEMP: ") in new stack
– Executing [123@sets:4] Playback(“PJSIP/SOFTPHONE_B-00000018”, “current-temp1”) in new stack
– <PJSIP/SOFTPHONE_B-00000018> Playing ‘current-temp1.slin’ (language ‘en’)
– Executing [123@sets:5] SayAlpha(“PJSIP/SOFTPHONE_B-00000018”, “”) in new stack
– Executing [123@sets:6] Hangup(“PJSIP/SOFTPHONE_B-00000018”, “”) in new stack
== Spawn extension (sets, 123, 6) exited non-zero on ‘PJSIP/SOFTPHONE_B-00000018’

so im able to get the temperature data from the esp32 and in the database, however im trying to use the agi to repeat the data to the call. My playback message gets cut off when the extension is dial then it just hangs up. Im not sure what is wrong, any help here?

agi set debug on may yield clues.

This channel variable is empty. I suggest you set it to a static test value and then check again using agi.set_variable("TEMP", 13455) If it still doesn’t work, verify in your Python script how to set an Asterisk channel variable."

-- Launched AGI Script /var/lib/asterisk/agi-bin/roomdata.py

<PJSIP/SOFTPHONE_B-00000020>AGI Tx >> agi_request: /var/lib/asterisk/agi-bin/roomdata.py
<PJSIP/SOFTPHONE_B-00000020>AGI Tx >> agi_channel: PJSIP/SOFTPHONE_B-00000020
<PJSIP/SOFTPHONE_B-00000020>AGI Tx >> agi_language: en
<PJSIP/SOFTPHONE_B-00000020>AGI Tx >> agi_type: PJSIP
<PJSIP/SOFTPHONE_B-00000020>AGI Tx >> agi_uniqueid: 1714173623.64
<PJSIP/SOFTPHONE_B-00000020>AGI Tx >> agi_version: 20.5.2
<PJSIP/SOFTPHONE_B-00000020>AGI Tx >> agi_callerid: SOFTPHONE_B
<PJSIP/SOFTPHONE_B-00000020>AGI Tx >> agi_calleridname: unknown
<PJSIP/SOFTPHONE_B-00000020>AGI Tx >> agi_callingpres: 0
<PJSIP/SOFTPHONE_B-00000020>AGI Tx >> agi_callingani2: 0
<PJSIP/SOFTPHONE_B-00000020>AGI Tx >> agi_callington: 0
<PJSIP/SOFTPHONE_B-00000020>AGI Tx >> agi_callingtns: 0
<PJSIP/SOFTPHONE_B-00000020>AGI Tx >> agi_dnid: 123
<PJSIP/SOFTPHONE_B-00000020>AGI Tx >> agi_rdnis: unknown
<PJSIP/SOFTPHONE_B-00000020>AGI Tx >> agi_context: sets
<PJSIP/SOFTPHONE_B-00000020>AGI Tx >> agi_extension: 123
<PJSIP/SOFTPHONE_B-00000020>AGI Tx >> agi_priority: 2
<PJSIP/SOFTPHONE_B-00000020>AGI Tx >> agi_enhanced: 0.0
<PJSIP/SOFTPHONE_B-00000020>AGI Tx >> agi_accountcode:
<PJSIP/SOFTPHONE_B-00000020>AGI Tx >> agi_threadid: 140552356960000
this is all the debug gives

it still doesnt return a value, and there isn much documentation im seeing on this. Is there any other way i could get this done?

Using PHP

echo "SET VARIABLE $variableName \"$variableValue\"\n";

Same old problem as before — Asterisk redirecting stderr to /dev/null, so you cannot see any error messages?

You can redirect it back to somewhere sensible by putting something like this near the top of your code (choose any suitable filename/directory):

log = open("/tmp/agi_try.log", "w")
os.dup2(log.fileno(), 2)
log.close()
del log

Now you have a file which should hopefully contain some clues after your program dies.

Another option is to use FastAGI. That way you run your own process, and you get to control where all its I/O goes.

i used php instead and it worked @ambiorixg12 @ldo @sedwards

I’m sorry to hear that …