nickiv / node-red-huawei-sms

Node-RED module to send and receive SMS from Huawei LTE USB Stick
1 stars 0 forks source link

New feature - SMS deletion #1

Closed PandCall closed 9 months ago

PandCall commented 9 months ago

Hi I love your module. I can now read SMS messages. I'd like you to think about upgrading your module to include the possibility of deleting the SMS after reading or deleting them periodically. Regards

nickiv commented 9 months ago

Hi, @PandCall! Glad you find it useful. Could you please clarify? Current implementation do delete incoming messages right after reading them. You see otherwise? Please give some details.

PandCall commented 9 months ago

I'll get back to you as soon as I fix my Home Assistant. After a reboot, node-red no longer launches with an error message telling me that /var/spool/sms/incoming does not exist. I've uninstalled node-red and reinstalled it, but now I can't launch it. I've restored a backup, still no node-red launch. Then I manually deleted all folders and configuration files that referred to node-red-huawei-sms. I'll be back as soon as node-red restarts properly. Regards

nickiv commented 9 months ago

Ok, will wait. This module has nothing to do with /var/spool/sms/incoming. It does not use filesystem at all. It uses http to interact with stick. So I recommend you to review other recent changes to your setup.

PandCall commented 9 months ago

I'm reinstalling the whole system and restoring the backup to an earlier date when everything was working. It's a bit long, but it should be fine. Once that's done, I'll do the system updates and then step by step I'll redo the installation for the SMS. Regards

PandCall commented 9 months ago

The system has been up and everything seems to be working properly again. I'm checking that everything is stable before making any further modifications, and I'll get back to you with more details about your module.

PandCall commented 9 months ago

Now the system is stable and I can start testing again. But I keep getting this message Error: No csrf token in /html/index.html And so it blocks the reading of SMS messages However, I can read the router information with another module in Home assistant or node-red. Do you have any idea why? Regards

nickiv commented 9 months ago

Most likely you have different device or different firmware version. Can you get to the web interface of the stick and look there for "Device information" page? Even if it is slightly different it still can be incompatible as this is not stable official API. Below I will attach the page of my device.

I would like to make my module universal. If you can record a network trace and send it to me, I can try to support it. Here is the manual how to do that: https://learn.microsoft.com/en-us/azure/azure-web-pubsub/howto-troubleshoot-network-trace#collect-a-network-trace-in-the-browser-browser-based-apps-only . You need to open a blank page, start the trace and then go to your stick address, log in and send or get sms by clicking the interface. When I get the trace I can tell you if I can add support. Thanks in advance!

device-info
PandCall commented 9 months ago

Sure, My system is not in production, it's in Lab mode. I can therefore run any kind of test. At this time, it's being used in Home assistant with the NODE-RED version included in the packages. Would you prefer me to run the tests in a direct Linux/Node-Red environment or under Home assistant? I'll run the tests as soon as I can Regards

nickiv commented 9 months ago

Well, what I need for now you can do just with browser.

  1. Go to Device Info page to get the version info.
  2. Record a network trace of browser-stick interaction while logging in and sending sms. To do that you do not need NR or HA, just plug your stick in your computer.
PandCall commented 9 months ago

LTE-4G-USB

PandCall commented 9 months ago

image

PandCall commented 9 months ago

If I attach the HAR file here, is it public or private? Regards

nickiv commented 9 months ago

It appears that you cannot share file privately via Github. But not a big deal though! I made new version 0.0.6 please give it a try. I did publish it, after some time there shoul be Update available in Manage Palette!

PandCall commented 9 months ago

After updating and restarting, node-red no longer starts with this log.

` Welcome to Node-RED

21 Dec 18:39:30 - [info] Node-RED version: v3.1.0 21 Dec 18:39:30 - [info] Node.js version: v18.18.2 21 Dec 18:39:30 - [info] Linux 6.1.58-haos-raspi arm64 LE 21 Dec 18:39:32 - [info] Loading palette nodes 21 Dec 18:39:32 - [warn] [node-red-contrib-home-assistant-websocket] Node module cannot be loaded on this version. Requires: >=3.1.1 21 Dec 18:39:36 - [info] Dashboard version 3.6.2 started at /endpoint/ui 21 Dec 18:39:39 - [info] Settings file : /etc/node-red/config.js 21 Dec 18:39:39 - [info] Context store : 'default' [module=memory] 21 Dec 18:39:39 - [info] User directory : /config/ 21 Dec 18:39:39 - [warn] Projects disabled : editorTheme.projects.enabled=false 21 Dec 18:39:39 - [info] Flows file : /config/flows.json 21 Dec 18:39:39 - [info] Server now running at http://127.0.0.1:46836/ 21 Dec 18:39:40 - [info] Starting flows [18:39:40] INFO: Starting NGinx... 21 Dec 18:39:40 - [info] [remote-access:f86af2c9431e2ec1] Server: InstanceHash: 21 Dec 18:39:40 - [info] [remote-access:f86af2c9431e2ec1] Configuration incomplete. 21 Dec 18:39:40 - [info] Started flows 21 Dec 18:39:40 - [info] [zigbee2mqtt-server:3f1ad22ac377d3f8] MQTT Connected 21 Dec 18:39:40 - [info] [mqtt-broker:NAS] Connected to broker: mqtt://192.168.69.3:1883 21 Dec 18:39:40 - [info] [zigbee2mqtt-server:3f1ad22ac377d3f8] MQTT Subscribed to: "zigbee2mqtt/# 2023-12-21 17:39:41 [error] [HuaweiMdm 192.168.8.1] Error: <?xml version="1.0" encoding="UTF-8"?>108003 at fsm.malfunctionStr (/config/node_modules/@nickiv/node-red-huawei-sms/huawei-modem.js:138:31) at fsm.http_success (/config/node_modules/@nickiv/node-red-huawei-sms/huawei-modem.js:208:18) at fsm.handle (/config/node_modules/machina/lib/webpack:/src/BehavioralFsm.js:135:1) at fsm.Fsm. [as handle] (/config/node_modules/machina/lib/webpack:/src/Fsm.js:80:1) at IncomingMessage.emit (node:events:529:35) at endReadableNT (node:internal/streams/readable:1368:12) at processTicksAndRejections (node:internal/process/task_queues:82:21) 2023-12-21 17:39:41 [error] [Huawei SmsRcv 192.168.8.1] Error: <?xml version="1.0" encoding="UTF-8"?>108003 at fsm.malfunctionStr (/config/node_modules/@nickiv/node-red-huawei-sms/huawei-modem.js:138:31) at fsm.http_success (/config/node_modules/@nickiv/node-red-huawei-sms/huawei-modem.js:208:18) at fsm.handle (/config/node_modules/machina/lib/webpack:/src/BehavioralFsm.js:135:1) at fsm.Fsm. [as handle] (/config/node_modules/machina/lib/webpack:/src/Fsm.js:80:1) at IncomingMessage.emit (node:events:529:35) at endReadableNT (node:internal/streams/readable:1368:12) at processTicksAndRejections (node:internal/process/task_queues:82:21) 2023-12-21 17:40:01 [error] [HuaweiMdm 192.168.8.1] Error: <?xml version="1.0" encoding="UTF-8"?>108003 at fsm.malfunctionStr (/config/node_modules/@nickiv/node-red-huawei-sms/huawei-modem.js:138:31) at fsm.http_success (/config/node_modules/@nickiv/node-red-huawei-sms/huawei-modem.js:208:18) at fsm.handle (/config/node_modules/machina/lib/webpack:/src/BehavioralFsm.js:135:1) at fsm.Fsm. [as handle] (/config/node_modules/machina/lib/webpack:/src/Fsm.js:80:1) at IncomingMessage.emit (node:events:529:35) at endReadableNT (node:internal/streams/readable:1368:12) at processTicksAndRejections (node:internal/process/task_queues:82:21) 2023-12-21 17:40:01 [error] [Huawei SmsRcv 192.168.8.1] Error: <?xml version="1.0" encoding="UTF-8"?>108003 at fsm.malfunctionStr (/config/node_modules/@nickiv/node-red-huawei-sms/huawei-modem.js:138:31) at fsm.http_success (/config/node_modules/@nickiv/node-red-huawei-sms/huawei-modem.js:208:18) at fsm.handle (/config/node_modules/machina/lib/webpack:/src/BehavioralFsm.js:135:1) at fsm.Fsm. [as handle] (/config/node_modules/machina/lib/webpack:/src/Fsm.js:80:1) at IncomingMessage.emit (node:events:529:35) at endReadableNT (node:internal/streams/readable:1368:12) at processTicksAndRejections (node:internal/process/task_queues:82:21) 2023-12-21 17:40:21 [error] [HuaweiMdm 192.168.8.1] Error: <?xml version="1.0" encoding="UTF-8"?>108003 at fsm.malfunctionStr (/config/node_modules/@nickiv/node-red-huawei-sms/huawei-modem.js:138:31) at fsm.http_success (/config/node_modules/@nickiv/node-red-huawei-sms/huawei-modem.js:208:18) at fsm.handle (/config/node_modules/machina/lib/webpack:/src/BehavioralFsm.js:135:1) at fsm.Fsm. [as handle] (/config/node_modules/machina/lib/webpack:/src/Fsm.js:80:1) at IncomingMessage.emit (node:events:529:35) at endReadableNT (node:internal/streams/readable:1368:12) at processTicksAndRejections (node:internal/process/task_queues:82:21) 2023-12-21 17:40:21 [error] [Huawei SmsRcv 192.168.8.1] Error: <?xml version="1.0" encoding="UTF-8"?>108003 at fsm.malfunctionStr (/config/node_modules/@nickiv/node-red-huawei-sms/huawei-modem.js:138:31) at fsm.http_success (/config/node_modules/@nickiv/node-red-huawei-sms/huawei-modem.js:208:18) at fsm.handle (/config/node_modules/machina/lib/webpack:/src/BehavioralFsm.js:135:1) at fsm.Fsm. [as handle] (/config/node_modules/machina/lib/webpack:/src/Fsm.js:80:1) at IncomingMessage.emit (node:events:529:35) at endReadableNT (node:internal/streams/readable:1368:12) at processTicksAndRejections (node:internal/process/task_queues:82:21) 2023-12-21 17:40:41 [error] [HuaweiMdm 192.168.8.1] Error: <?xml version="1.0" encoding="UTF-8"?>108003 at fsm.malfunctionStr (/config/node_modules/@nickiv/node-red-huawei-sms/huawei-modem.js:138:31) at fsm.http_success (/config/node_modules/@nickiv/node-red-huawei-sms/huawei-modem.js:208:18) at fsm.handle (/config/node_modules/machina/lib/webpack:/src/BehavioralFsm.js:135:1) at fsm.Fsm. [as handle] (/config/node_modules/machina/lib/webpack:/src/Fsm.js:80:1) at IncomingMessage.emit (node:events:529:35) at endReadableNT (node:internal/streams/readable:1368:12) at processTicksAndRejections (node:internal/process/task_queues:82:21) 2023-12-21 17:40:41 [error] [Huawei SmsRcv 192.168.8.1] Error: <?xml version="1.0" encoding="UTF-8"?>108003 at fsm.malfunctionStr (/config/node_modules/@nickiv/node-red-huawei-sms/huawei-modem.js:138:31) at fsm.http_success (/config/node_modules/@nickiv/node-red-huawei-sms/huawei-modem.js:208:18) at fsm.handle (/config/node_modules/machina/lib/webpack:/src/BehavioralFsm.js:135:1) at fsm.Fsm. [as handle] (/config/node_modules/machina/lib/webpack:/src/Fsm.js:80:1) at IncomingMessage.emit (node:events:529:35) at endReadableNT (node:internal/streams/readable:1368:12) at processTicksAndRejections (node:internal/process/task_queues:82:21) 2023-12-21 17:41:01 [error] [HuaweiMdm 192.168.8.1] Error: <?xml version="1.0" encoding="UTF-8"?>108003 at fsm.malfunctionStr (/config/node_modules/@nickiv/node-red-huawei-sms/huawei-modem.js:138:31) at fsm.http_success (/config/node_modules/@nickiv/node-red-huawei-sms/huawei-modem.js:208:18) at fsm.handle (/config/node_modules/machina/lib/webpack:/src/BehavioralFsm.js:135:1) at fsm.Fsm. [as handle] (/config/node_modules/machina/lib/webpack:/src/Fsm.js:80:1) at IncomingMessage.emit (node:events:529:35) at endReadableNT (node:internal/streams/readable:1368:12) at processTicksAndRejections (node:internal/process/task_queues:82:21) 2023-12-21 17:41:01 [error] [Huawei SmsRcv 192.168.8.1] Error: <?xml version="1.0" encoding="UTF-8"?>108003 at fsm.malfunctionStr (/config/node_modules/@nickiv/node-red-huawei-sms/huawei-modem.js:138:31) at fsm.http_success (/config/node_modules/@nickiv/node-red-huawei-sms/huawei-modem.js:208:18) at fsm.handle (/config/node_modules/machina/lib/webpack:/src/BehavioralFsm.js:135:1) at fsm.Fsm. [as handle] (/config/node_modules/machina/lib/webpack:/src/Fsm.js:80:1) at IncomingMessage.emit (node:events:529:35) at endReadableNT (node:internal/streams/readable:1368:12) at processTicksAndRejections (node:internal/process/task_queues:82:21) [18:42:22] INFO: Service Node-RED exited with code 1 (by signal 0) s6-rc: info: service legacy-services: stopping s6-rc: info: service legacy-services successfully stopped s6-rc: info: service nginx: stopping [18:42:22] INFO: Service NGINX exited with code 0 (by signal 0) s6-rc: info: service nginx successfully stopped s6-rc: info: service init-nginx: stopping s6-rc: info: service nodered: stopping s6-rc: info: service init-nginx successfully stopped s6-rc: info: service nodered successfully stopped s6-rc: info: service init-nodered: stopping s6-rc: info: service init-nodered successfully stopped s6-rc: info: service init-customizations: stopping s6-rc: info: service init-customizations successfully stopped s6-rc: info: service legacy-cont-init: stopping s6-rc: info: service legacy-cont-init successfully stopped s6-rc: info: service fix-attrs: stopping s6-rc: info: service base-addon-log-level: stopping s6-rc: info: service fix-attrs successfully stopped s6-rc: info: service base-addon-log-level successfully stopped s6-rc: info: service base-addon-banner: stopping s6-rc: info: service base-addon-banner successfully stopped s6-rc: info: service s6rc-oneshot-runner: stopping s6-rc: info: service s6rc-oneshot-runner successfully stopped `

PandCall commented 9 months ago

Node-Red restarts by removing this line from the modules

image

And of course my Flow SMS displays an error because the Node is missing. Regards

nickiv commented 9 months ago

I will look in to it. The error 108003: "user already logged in" tells us that there is another session. Do you have other software that use the stick API at the same time? It seems unlikely, but plz check. For now I don't get how it could break NR completely.

PandCall commented 9 months ago

Yes, in HA there is a module : https://www.home-assistant.io/integrations/huawei_lte image which is connected to the router to access other information that you don't give, such as Upload Download Data On/Off Wifi On/Off Etc.

PandCall commented 9 months ago

I disabled the HA module But randomly node-red down and when it manages to restart there's this message image and it loops Up/down node-red service

nickiv commented 9 months ago

Ok, thanks. For now I can tell you this.

  1. Stick does not allow to have more than one session. So you will not be able to use my module and HA integration. This limit is not like hard limit, sometimes it works, but then fails.
  2. This error tends to destabilize the stick. So to fix it you need to reconnect stick or reboot host.
  3. I cannot figure out how my module can take down NR. Trying different scenarios, but no luck yet.
nickiv commented 9 months ago

@PandCall I was not able to catch NR failure with my module. There could be two possiblites:

As you can see in your log "exit with code 1" happens after 40 and something seconds after last exception from my module. Thats weird.

I have two suggestions.

  1. Please enable Debug logs in Config node inside "Read SMS" node. Just checkbox. Then paste me a log with debug enabled and failure.
  2. Please add some code to settings.js, as suggested here: https://community.home-assistant.io/t/nodered-not-starting/591691/3 . It could show the actual exeption causing failure.
PandCall commented 9 months ago

I'll do it asap

nickiv commented 9 months ago

@PandCall I didnt catch any total failure, but made some improvements. Please update to 0.0.7 and let me know if its working or not.

PandCall commented 9 months ago

No, with each installation, NR falls and never rises again.

` Index: 40005, Phone: 336xxxxxxxxx, Content: 'Ok', Date: '2023-12-20 16:11:59', Sca: '', SaveType: 0, Priority: 0, SmsType: 1 }, { Smstat: 0, Index: 40004, Phone: 336xxxxxxxxx, Content: 'Il manque des messages', Date: '2023-12-20 15:50:55', Sca: '', SaveType: 0, Priority: 0, SmsType: 1 }, { Smstat: 0, Index: 40003, Phone: 336xxxxxxxxx, Content: 3, Date: '2023-12-20 15:39:14', Sca: '', SaveType: 0, Priority: 0, SmsType: 1 }, { Smstat: 0, Index: 40002, Phone: 336xxxxxxxxx, Content: 2, Date: '2023-12-20 15:39:12', Sca: '', SaveType: 0, Priority: 0, SmsType: 1 }, { Smstat: 0, Index: 40000, Phone: 336xxxxxxxxx, Content: 1, Date: '2023-12-20 15:39:11', Sca: '', SaveType: 0, Priority: 0, SmsType: 1 } ] 23 Dec 19:37:20 [debug] [Huawei SmsRcv 192.168.8.1] Sending msg to receiver #d482f60815f7e5f9 23 Dec 19:37:20 [debug] [HuaweiMdm 192.168.8.1] queueRequest delete [Arguments] { '0': 40009 } 23 Dec 19:37:20 [debug] [Huawei SmsRcv 192.168.8.1] Sending msg to receiver #d482f60815f7e5f9 23 Dec 19:37:20 [debug] [HuaweiMdm 192.168.8.1] queueRequest delete [Arguments] { '0': 40008 } 23 Dec 19:37:20 [debug] [Huawei SmsRcv 192.168.8.1] Sending msg to receiver #d482f60815f7e5f9 23 Dec 19:37:20 [debug] [HuaweiMdm 192.168.8.1] queueRequest delete [Arguments] { '0': 40006 } 23 Dec 19:37:20 [debug] [Huawei SmsRcv 192.168.8.1] Sending msg to receiver #d482f60815f7e5f9 23 Dec 19:37:20 [debug] [HuaweiMdm 192.168.8.1] queueRequest delete [Arguments] { '0': 40005 } 23 Dec 19:37:20 [debug] [Huawei SmsRcv 192.168.8.1] Sending msg to receiver #d482f60815f7e5f9 23 Dec 19:37:20 [debug] [HuaweiMdm 192.168.8.1] queueRequest delete [Arguments] { '0': 40004 } 23 Dec 19:37:20 - [red] Uncaught Exception: 23 Dec 19:37:20 - [error] TypeError: messages[i].Content.trim is not a function at constructor.poll_success (/config/node_modules/@nickiv/node-red-huawei-sms/huawei-sms-config.js:85:61) at constructor.handle (/config/node_modules/machina/lib/webpack:/src/BehavioralFsm.js:135:1) at constructor.Fsm. [as handle] (/config/node_modules/machina/lib/webpack:/src/Fsm.js:80:1) at EventEmitter.emit (node:events:517:28) at fsm.http_success (/config/node_modules/@nickiv/node-red-huawei-sms/huawei-modem.js:312:39) at fsm.handle (/config/node_modules/machina/lib/webpack:/src/BehavioralFsm.js:135:1) at fsm.Fsm. [as handle] (/config/node_modules/machina/lib/webpack:/src/Fsm.js:80:1) at IncomingMessage.emit (node:events:529:35) at endReadableNT (node:internal/streams/readable:1368:12) at processTicksAndRejections (node:internal/process/task_queues:82:21) [19:37:20] INFO: Service Node-RED exited with code 1 (by signal 0) s6-rc: info: service legacy-services: stopping s6-rc: info: service legacy-services successfully stopped s6-rc: info: service nginx: stopping [19:37:20] INFO: Service NGINX exited with code 0 (by signal 0) s6-rc: info: service nginx successfully stopped s6-rc: info: service init-nginx: stopping s6-rc: info: service nodered: stopping s6-rc: info: service nodered successfully stopped s6-rc: info: service init-nodered: stopping s6-rc: info: service init-nginx successfully stopped s6-rc: info: service init-nodered successfully stopped s6-rc: info: service init-customizations: stopping s6-rc: info: service init-customizations successfully stopped s6-rc: info: service legacy-cont-init: stopping s6-rc: info: service legacy-cont-init successfully stopped s6-rc: info: service fix-attrs: stopping s6-rc: info: service base-addon-log-level: stopping s6-rc: info: service fix-attrs successfully stopped s6-rc: info: service base-addon-log-level successfully stopped s6-rc: info: service base-addon-banner: stopping s6-rc: info: service base-addon-banner successfully stopped s6-rc: info: service s6rc-oneshot-runner: stopping s6-rc: info: service s6rc-oneshot-runner successfully stopped

` I'll have to do the tests on a system with the Key and without HA, only with NR to see how it behaves.

nickiv commented 9 months ago

@PandCall please check out 0.0.8 version. It is a dumb bug (trim is not a function). I fixed it. Please let me know if it works now.

PandCall commented 9 months ago

I've just reinstalled it and it works and connects quickly. NR image Log image HA image Now I'll restart HA and NR to check To be continued......

PandCall commented 9 months ago

Restarting is no problem at the moment, everything seems to be working properly and cohabits with the HA Module, which will read some of the key's status. You must have put your finger on something that was causing this problem. I'm going to continue testing to validate stability. But if you make any changes, don't hesitate to let me know if you want me to test them. Regards

nickiv commented 9 months ago

Actually it was your help. In the log above error is clearly visible "3 Dec 19:37:20 - [error] TypeError: messages[i].Content.trim is not a function". Thank you!

P.S. do not hesitate to file a ticket if you have any errors or may be feature requests!