Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SMS functions (send/receive) #6

Closed
grawsom opened this issue Dec 14, 2021 · 15 comments
Closed

SMS functions (send/receive) #6

grawsom opened this issue Dec 14, 2021 · 15 comments
Labels
enhancement New feature or request

Comments

@grawsom
Copy link

grawsom commented Dec 14, 2021

Have used Huawei E3372h-153 and E3372h-320 in a node-red application where I use send and recieve sms, I have used an old sms package "node-red-contrib-smstools" but is 6 years old.
But the new -320 have HiLink, have made some stuff to get it in "com mode" just for still been able to the old sms package.
I'm not a programmer but it was my wish?? to use the api in HiLink mode to get it to work this way.

I now found this where you have made the first steps - just so great.

Can we get sms send/receive functions - I will be very happy to help with testing etc.

@zinen
Copy link
Owner

zinen commented Dec 15, 2021

My router can't do sms. But if you are willing to test it out.
Try installing this new branch and give me feedback.
npm install https://github.com/zinen/node-red-contrib-huawei-router.git#send-sms

@grawsom
Copy link
Author

grawsom commented Dec 15, 2021

That was fast - I have tested, but get error 100005: Unknown and also 125003: Unknown after some tries

  • but you have me started :-)

One thing I don't understand, is the huawei-lte-api folder, it's based of https://github.com/Salamek/huawei-lte-api-ts.
But where does all the .js files come from?
And why is src now dist?
Is this tsconfig.json that does all that..
I think I have much to learn

Maybe I have to try some js CLI stuff first with the huawei-lte-api, to get the send working, and then afterwords look into receive function - "one step at a time"

@zinen
Copy link
Owner

zinen commented Dec 15, 2021

You got lucky. I had some time available today.

Now I never learned too much about typescript(.ts files). But I do know that typescript can be compiled into javascript. So when i publish to npm just must first compile the source files (src/.ts) into build files (dist/.js).

Error 100005 I dont know about. But 125003 is some sort of session error, ref.

I made this test code which is basically what I put into the node-red module you tested. But this will run from command instead of through node-red.
You will need to have node.js installed and the huawei-lte-api then save this content to a .js file and run it:

const huaweiLteApi = require('huawei-lte-api')
const TEST_PHONE_NUMBER = ['1233456']
const TEST_MESSAGE = 'Test message'
async function start () {
  try {
    const connection = new huaweiLteApi.Connection('http://admin:password@192.168.8.1/')
    await connection.ready
    const SMS = new huaweiLteApi.Sms(connection)
    const result = await SMS.sendSms(TEST_PHONE_NUMBER, TEST_MESSAGE)
    console.log(result)
  } catch (error) {
    console.error('Ended in error:')
    console.error(error)
    console.trace(error)
  }
}
start()

@grawsom
Copy link
Author

grawsom commented Dec 16, 2021

Still same result, but I have spend the day trying other solutions to try and find a way.
I believe that my LTE stick is a version that require crypt when sending sms.
I did prior use this one ref. I found on github, and this one works with the send function.
So maybe I will try and see if I can mix something together.

But still - thanks for trying.

  • Ivan

@zinen
Copy link
Owner

zinen commented Dec 16, 2021

I get a OK back in console. I guess that means I got some sort of contact to the router but no SMSs are send.

Do any of the my other node models work in node-red? Eg. can you reboot the device or turn of data?
If no I will add it to the list of unsupported routers of the API docs.

@grawsom
Copy link
Author

grawsom commented Dec 16, 2021

I know that reboot worked, but I will do some deeper testing this weekend..

@grawsom
Copy link
Author

grawsom commented Dec 18, 2021

Contacted Salamek who made the API, and it seems that encryption is not implemented yet in TS API, I got it working with send-sms via the py API om my PC (Windows). see more here
So maybe now I can get this to work in Node-Red as I hopped, and get rid of the old smstools.
Need to find out how to help via Github, because I could maybe bring some stuff/ideas to this Node-Red package also.
So "learning by doing"

@zinen
Copy link
Owner

zinen commented Dec 21, 2021

Saw that @Salamek did an update of the API to version 0.0.8 #b69111a. I included the latest changes from that API in the send-sms branch now.

You should be able to test i out now with :
npm install https://github.com/zinen/node-red-contrib-huawei-router.git#send-sms

@grawsom
Copy link
Author

grawsom commented Dec 21, 2021

@zinen I have now tested @Salamek updated API 0.0.8, but it stil fails.
Don't want to test you script before the API works, also I got an error and din't go any further.

Tested with signal, that I know worked.
Unexpected close tag Line: 107 Column: 7 Char: >

@zinen
Copy link
Owner

zinen commented Dec 29, 2021

@grawsom API has now been released to v 0.0.10 - it's suppose to fix your exact issue.

Mind testing this branch again after latest bump?

npm install https://github.com/zinen/node-red-contrib-huawei-router.git#send-sms

@grawsom
Copy link
Author

grawsom commented Dec 30, 2021

@zinen - I have now tested with 2 dongles I have E3372h-320 and firmware updated E3372h-153 (so it runs hilink mode), and it works and not.
I have put 2 node.warn in huawei-router.js, to see text and number.
If I use Inject node with payload and number it send sms ok.
If I use the 2 input fields in huawei-send-sms node I get blank for both, and therefore an error.

So it must be the parsing that goes wrong.
But I will try with "trial and error" to see if I can get it working.

But so far so god. :-)

@grawsom
Copy link
Author

grawsom commented Dec 30, 2021

Don't know how to update script, but after playing with it I came to this that works, if it's programmatily correct i don't know, but maybe it helps.

I added these 2 lines

node.phoneNumber = config.phoneNumber
node.message = config.message

So it loks like this now

const node = this
node.phoneNumber = config.phoneNumber
node.message = config.message
node.on('input', async function (msg, send, done) {

@zinen
Copy link
Owner

zinen commented Dec 30, 2021

Realized the same thing. Updated the code just now. Also removed the message field in the node properties so know only msg.payload works for defining the text content. I figured that a static text was not relevant for the SMS and if so anyways could be achived with a template node.

  1. Agree?
  2. Wanna test again?

@grawsom
Copy link
Author

grawsom commented Dec 31, 2021

  1. Yes I agree?
  2. Tested on Windows and works out of the box, will test on RPI one of the next days, but why should it not work?

Just maybe an idear to the future - make 1 node that have a dropdown for all the "service" stuff you can call via API.
Just an idear. ;-)

Also if I compare to the old smstools (6 years) in node-red that uses AT commands, it also only have phonenumber in node.

So now that there is a working sms-out (sms-send) for node-red, it's time for me to see if I can find out how to make/get a sms-in, so I can replace the smstools with hilink working dongles.

Thanks one again for making this work - and you have a happy new year.

@zinen
Copy link
Owner

zinen commented Jan 1, 2022

Sweet that it works. I will include this branch in the main code after some cleanup.

About restructuring. When you say service stuff. You mean reboot and mobile data?
If this should be done I guess I would restructure it even more:

  • connected hosts: lanhost + wlanhost
  • service: reboot + data
  • send sms
  • get sms (havn't looked into this )

The SMS-in is a nice feature but I dont know how to make it without a device to test on. There are multible steps involved in look though an inbox. I welcome a PR though.
Should you receive the last 10 texts, should you include read+unread items, should you mark them as read after returned, should you delete them after returned?

@zinen zinen mentioned this issue Jan 1, 2022
@zinen zinen closed this as completed Jan 1, 2022
@zinen zinen added the enhancement New feature or request label Feb 6, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants