huawei-lte-api-ts
huawei-lte-api-ts copied to clipboard
Question - How to use "logout/close" to run a api call every 5 sec.
Let's take ref. in you example/device_info.js.
If i execute that every 5 sec. after 4 or 5 times I get a
ResponseErrorException: 108003: Already login
Just used this one for test, but if that one is not working, then the ones I want to use will neither.
Believe there must be a way to close connection/logout or something like that, but I don't know how to program that.
What I am after is a way to receive SMS's, but for that I need to "check" every X sec. I have the flow and nodes in place, but it's not bulletproff. I check every 10 sec. (but want to go lower) if there is new sms, I save that one in a folder, then I monitor that folder, and gets the information in sms, and then call the delete function
I'm trying to get it to work in the Node-red package, but must be sure that it works in the API, before taking it further.
You need to reuse the connection save it to a variable. E.g. only call the function with login credentials once.
Another repo but line 30 shows running the logout function.
@zinen I'm no programmer, but maybe you can help me, or show me in the right direction. I have forked you and made my own changes to try somthing out. You can get it here
This code you should be able to run over and over again without hitting the routers limit of 5 active sessions due to the logout at the end. Tests on my router proves that any sessions is killed after 5 minutes of inactivity.
const huaweiLteApi = require('huawei-lte-api')
// Varible globaly scoped
let connection
async function sendSMS(inputText) {
try {
connection = new huaweiLteApi.Connection('http://admin:[email protected]/')
await connection.ready
// Phone number must be an array of strings
const resultSendSMS = await new huaweiLteApi.Sms(connection).sendSms(['12345678'], inputText)
console.log('result for send SMS =', resultSendSMS)
} catch (error) {
console.error('Ended in error:')
console.error(error)
} finally {
// finallyCode - Code block to be executed regardless of the try result
const resultLogout = await new huaweiLteApi.User(connection).logout()
console.log('result from logout=',resultLogout)
connection = null
}
}
sendSMS('My message to send')
@Salamek When looking at the normal API, there is a command client.user.logout()
.
Where is that in TS package?
Because I think maybe this is my problem here.
@zinen