feature-requests icon indicating copy to clipboard operation
feature-requests copied to clipboard

Add 3g / 4g txt support uisng SIM7600 or similar

Open andypnz opened this issue 1 year ago • 36 comments

Describe the problem you have/What new integration you would like

Hi. I see there is a ESPHome integration for the SIM800L to send SMS txt messages..... Unfortunately the SIM800L uses the 2G network, which is being removed..... Is there any support for the SIM7600 or similar board to use the 3G / 4G network to send / receive txt messages using ESPHome running on a Wemos D1 mini or ESP32, etc ?

Please describe your use case for this integration and alternatives you've tried:

As above

Additional context

andypnz avatar Jul 30 '22 22:07 andypnz

As far as I can see in most parts of the world 2G stays as it's based on plain GSM and used by older IoT, not planned to be removed any time soon. 3G is being removed as it's a separate network (frequencies needed for 5G SA), and 4G is still in active operation as even 5G relies on it as NSA network.

Where are you located?

nagyrobi avatar Jul 31 '22 03:07 nagyrobi

I am in New Zealand. Some cellular providers here have already shut down their 2G networks here..... Others plan to do the same by 2025 despite potentially millions of devices still using 2G..... So looking for a 3G / 4G solution.....

And I would like to send the sms direct from a ESPHome device, not something more central (like Home Assistant).

Ideally I would use something like this SIM7600SA-H 4G HAT for Raspberry Pi 4G 3G 2G Communication connected to a Wemos D1 mini or ESP32.... I wonder if I could use serial protocol directly to send AT commands? Really, it is just to send sms messages on alarm.....

Thank you for your thoughts....

andypnz avatar Jul 31 '22 04:07 andypnz

Afaik SMS is a standalone GSM transport, works without 2G, it's among with the voice channels. You don't even need 2G to send SMS. You only need (some kind of)G for internet/data.

Don't invest on 3G as it will be shut down soon. You need a 4G/5G device on long term for mobile data.

But given the super low cost of SIM800L it still might be worth using it in your area until 2025 as it's supported at the moment by ESPHome. You will be able to do SMS without 2G even after 2025.

nagyrobi avatar Jul 31 '22 04:07 nagyrobi

Agree..... and I think the SIM7600 fits the bill..... hoping for a solution to use 4G/5G now :-)

andypnz avatar Jul 31 '22 04:07 andypnz

Unfortunately the 800L is not working for me here - and confirmed 2g is already not supported on my chosen network. So I do need a 3G/4G/5G solution - I have ordered a SIM7600 - looking on GitHub I wonder if the 800L code code be modified to work with the 7600?

Happy to do some testing if anyone is interested (and has time) in doing that? My 7600 should be here in a week or so…..

andypnz avatar Aug 07 '22 09:08 andypnz

@andypnz Did you had some success with the SIM7600 ?

bobzer avatar Jul 11 '23 14:07 bobzer

+1

I’m in Thailand and 2G is long gone here.

robdejonge avatar Oct 11 '23 05:10 robdejonge

Has anybody tried actually using a SIM7000/7600/7670 etc using the SIM800 component? They all have UART and use the same AT command set so it might just work? I've just ordered a LillyGo A7670E module and ESP32 "motherboard" and will have a play when it arrives. It might just need some minor fiddling to get it to work.

NB: The 7670 is worth considering if you only need 4G/LTE and there's a version for your region. The 7600 supports "old" 3G comms and is physically larger and much more expensive. Note that the SIM7000 is LTE Cat-M/NB only, which might need a special IoT SIM plan rather than a regular consumer SIM, and might not even be supported on some networks.

garethm79 avatar Nov 03 '23 16:11 garethm79

Yes, it works as these basic AT commands are the same. Tested with sim7600E.

randybb avatar Nov 03 '23 18:11 randybb

@andypnz please send me your mail. I have adapted the code that it should be working in case no GSM is available. @randybb I can confirm the SIM800L code is working when GSM is available. If not, it will not be working since the code things the registration was not successful. I have modified slightly and looking for some testers

chino-lu avatar Nov 09 '23 12:11 chino-lu

@chino-lu Hello, If it still possible, I would like to try your code for using SIM7600 by GSM/LTE with my HA server

qnixAVA avatar Dec 28 '23 10:12 qnixAVA

@chino-lu I would like to test it as well of your offer is still standing. Thank you.

danielionutmuresan avatar Jan 21 '24 15:01 danielionutmuresan

@qnixAVA sorry, hadn't seen your message here. I have uploaded the code to https://github.com/chino-lu/sim7600

chino-lu avatar Jan 22 '24 21:01 chino-lu

@qnixAVA - sorry for my lack of knowledge, but how would I go about using that code ?

pacmac avatar Feb 29 '24 06:02 pacmac

Hello @pacmac, I don't know yet, I was thinking about another problem concerning my project. Now it's solved, I can start thinking about how to use the code of chino-lu on esphome.

qnixAVA avatar Feb 29 '24 07:02 qnixAVA

you only need it to place it in your config folder config

  • esphome
    • include
    • -SIM7600

in your esphome yaml you define esphome: includes: - SIM7600/sim7600.h

chino-lu avatar Feb 29 '24 08:02 chino-lu

Thanks so much, I have included it and it compiles with no errors, but how do I use it:

sim7600:
  on_sms_received:
    - logger.log:
        format: "Received '%s' from %s"
        args: [ 'message.c_str()', 'sender.c_str()' ]

Throws error component not found

pacmac avatar Feb 29 '24 08:02 pacmac

Have tried to figure it out, but compile fails with Component not found: sim7600.:

esphome:
  includes:
    - sim7600/sim7600.h

custom_component:
  - lambda: |-
      auto sim7600 = new sim7600();
      App.register_component(sim7600);
      return {sim7600};

sim7600:
  on_sms_received:
    - logger.log:
        format: "Received '%s' from %s"
        args: [ 'message.c_str()', 'sender.c_str()' ]

pacmac avatar Feb 29 '24 08:02 pacmac

just checked again, here is my code

esphome:
  name: kc868-aio
  friendly_name: KC868-AIO

external_components:
  - source:
      type: local
      path: include
esp32:
  board: esp32dev
  framework:
    type: arduino

# Enable logging
logger:
  baud_rate: 0


ota:
  password: "xxxx" 

wifi:
  ssid: "xxxx"
  password: "xxxxxx"

  # Enable fallback hotspot (captive portal) in case wifi connection fails
  ap:
    ssid: "Kc868-Aio Fallback Hotspot"
    password: "xxxxx"

captive_portal:

# Enable Home Assistant API
api:
  encryption:
    key: "xxxx"
  services:
    - service: send_sms
      variables:
        recipient: string
        message: string
      then:
        - sim7600.send_sms:
            recipient: !lambda 'return recipient;'
            message: !lambda 'return message;'
    - service: dial
      variables:
        recipient: string
      then:
        - sim7600.dial:
            recipient: !lambda 'return recipient;'
    - service: connect
      then:
        - sim7600.connect
    - service: disconnect
      then:
        - sim7600.disconnect
    - service: send_ussd
      variables:
        ussdCode: string
      then:
        - sim7600.send_ussd:
            ussd: !lambda 'return ussdCode;'

text_sensor:
  - platform: template
    id: sms_sender
    name: "Sms Sender"
  - platform: template
    id: sms_message
    name: "Sms Message"
  - platform: template
    id: caller_id_text_sensor
    name: "Caller ID"
  - platform: template
    id: ussd_message
    name: "Ussd Code"


uart:
  tx_pin: GPIO13
  rx_pin: GPIO15
  baud_rate: 115200
  debug:
    direction: BOTH
    dummy_receiver: false
    after:
      delimiter: "\n"
    sequence:
      - lambda: UARTDebug::log_string(direction, bytes);

chino-lu avatar Feb 29 '24 09:02 chino-lu

thanks so much that worked :-)

pacmac avatar Feb 29 '24 12:02 pacmac

Well it seems that I can receive SMS but I cannot send and are not sure where to start debugging:

[10:00:05][D][uart_debug:158]: >>> "\x1AAT+CSCS=\"GSM\"\r\n"
[10:00:05][D][uart_debug:158]: <<< "\r\nOK\r\n"
[10:00:05][D][uart_debug:158]: >>> "AT+CMGS=\"+XXXXXXXXXX\"\r\n"
[10:00:05][I][sim7600:343]: Sending to +XXXXXXXXXX message: 'Pong'
[10:00:05][D][uart_debug:158]: <<< "\r\n>"
[10:00:05][D][uart_debug:158]: >>> "Pong\x1A"
[10:00:05][D][uart_debug:158]: <<< " \r\n"
[10:00:13][D][uart_debug:158]: <<< "\r\n+CMS ERROR: Unknown error\r\n"

Any suggestions ?

pacmac avatar Mar 01 '24 10:03 pacmac

Hello there, I wanted to know if with that code I will be able to send data from sensor to my home assistant ? I was looking for doing this by 4G/5G, but idk if it's possible to do this by sms ?

qnixAVA avatar Mar 01 '24 11:03 qnixAVA

@qnixAVA it will not - esphome can use only wifi or ethernet, data transfer via HSDPA/LTE is not implemented. Anyway, these SIM7600 modules have native http/https and mqtt build-in, so this could be one of the possible options. We just need to find a volunteer who will implement it :)

@chino-lu btw, maybe the network registration type could be configurable - AT+CREG for 3g/4g, AT+CGREG for GPRS and AT+CEREG for LTE only then we could have one universal component for all SIMxxxx modules.

randybb avatar Mar 01 '24 12:03 randybb

@randybb okay.. thanks. Maybe it will be possible by using https webhook ? In this case I will need to establish connection of my SIM7600 first, then add webhook to my home assistant with esphome API ?

qnixAVA avatar Mar 01 '24 12:03 qnixAVA

@qnixAVA yes, this is why I have mentioned https :) This could be the easiest way - just check "AT Commands for HTTPS" in the manual - should not be hard send couple of AT commands. I have my "tracker" (LilyGo-T-PCIE with SIM7600E) ready on my desk for more than 2 years and had no time to finish it.

randybb avatar Mar 01 '24 12:03 randybb

@randybb Yes thank's buddy. I was thinking about since the start of my project but I don't have enough programming knowledge to adapt the arduino code to yaml of esphome :/ .

qnixAVA avatar Mar 01 '24 13:03 qnixAVA

CSCS

could you try 00 instead of +?

chino-lu avatar Mar 01 '24 18:03 chino-lu

I have this problem when compiling the code in esphome: image Pls kindly help to check Ah, and the code bellow: 4g-mobile-gateway.zip

trungnvdng avatar Mar 05 '24 09:03 trungnvdng

please share you folder structure in ESPHome

chino-lu avatar Mar 05 '24 09:03 chino-lu

The structure is: ESPHome/ sim7600/ sim7600.h

image

trungnvdng avatar Mar 05 '24 09:03 trungnvdng