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

[modem] pppos tcp/ip for uart modem (esp-idf only) #6721

Draft
wants to merge 26 commits into
base: dev
Choose a base branch
from

Conversation

oarcher
Copy link

@oarcher oarcher commented May 11, 2024

What does this implement/fix?

This implement pppos tcp/ip for esp32. it conflict with wifi or ethernet component.

Types of changes

  • Bugfix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Other

Related issue or feature (if applicable):
esphome/feature-requests#2303
esphome/feature-requests#477
esphome/feature-requests#1379

Pull request in esphome-docs with documentation (if applicable): esphome/esphome-docs#

Test Environment

  • ESP32
  • ESP32 IDF
  • ESP8266
  • RP2040
  • BK72xx
  • RTL87xx

Example entry for config.yaml:

# While not merged, this PR is also available as an externa component
external_components:
    - source: github://pr#6721
      components: [ network, modem ]

# Currently, to power cycle the modem, we will use an external package 
# at https://github.com/oarcher/piotech/blob/main/packages/lilygo_tsim.yaml
# this will create a binary sensor 'modem_ready' that the component will use
# to check the modem state.
# it works for LilyGo T-SIM7600, but might be adaptated for other devices
# This is needed, because ( at least on Lilygo T-SIM, a warm reboot doesn't reset the modem, 
# and it's not responding to AT commands )

substitutions:
  pwr_pin: GPIO04
  pwr_pin_inverted: "True"
  status_pin: GPIO34
  flight_pin: GPIO25

packages:
  modem_power:
    url: https://github.com/oarcher/piotech
    files: [ packages/lilygo_tsim.yaml ]
    refresh: 10min



modem:
  id: atmodem
  ready: modem_ready  # The binary sensor that reports the modem state
  rx_pin: 26
  tx_pin: 27
  model: SIM7600  # or BG96 SIM7000 SIM800
  apn: orange
  username: orange
  password: orange
  pin_code: "0000"
  # we can send initial AT commands at setup
  # here to configure GNSS and poweron GPS
  init_at:
    - AT+CGNSSMODE=15,1 # GNSS all navigation systems
    - AT+CGPS=1 # GPS on
 
mqtt:
# mqtt with a public brocker available is mandatory, because it's currently the only way to reach the device
# on a private and foreign network.

# the DCE is available to others components here an example that feed
# a text sensor with a google map url
text_sensor:
  - platform: template
    name: "gmap"
    update_interval: 60s
    lambda: |-
      std::string gnss_info;
      esp_modem::command_result err;
      err = id(atmodem)->dce->at("AT+CGNSSINFO", gnss_info, 3000);
      if (err != esp_modem::command_result::OK) {
        return { "AT+CGNSSINFO ERROR" };
      }

      std::string data = gnss_info.substr(12);


      std::vector<std::string> parts;
      size_t pos = 0;
      std::string delimiter = ",";
      while ((pos = data.find(delimiter)) != std::string::npos) {
        parts.push_back(data.substr(0, pos));
        data.erase(0, pos + delimiter.length());
      }
      parts.push_back(data); 

      if (parts.size() < 14) {
        return { "Invalid GNSS data: " + gnss_info };
      }
    
      std::string latitude = parts[4];
      std::string lat_direction = parts[5];
      std::string longitude = parts[6];
      std::string lon_direction = parts[7];
    
      if (latitude.empty() || lat_direction.empty() || longitude.empty() || lon_direction.empty()) {
        return { "Invalid GNSS data: " + gnss_info };
      }
    
      double lat_deg = std::stod(latitude.substr(0, 2));
      double lat_min = std::stod(latitude.substr(2));
      double lat = lat_deg + (lat_min / 60.0);
      if (lat_direction == "S") lat = -lat;
    
      double lon_deg = std::stod(longitude.substr(0, 3));
      double lon_min = std::stod(longitude.substr(3));
      double lon = lon_deg + (lon_min / 60.0);
      if (lon_direction == "W") lon = -lon;
    
      std::string google_maps_link = "https://www.google.com/maps/search/?api=1&query=" + std::to_string(lat) + "," + std::to_string(lon);
      return { google_maps_link };
 

Checklist:

  • The code change is tested and works locally.
  • Tests have been added to verify that the new code works (under tests/ folder).

If user exposed functionality or configuration variables are added/changed:

@probot-esphome
Copy link

Hey there @esphome/core, mind taking a look at this pull request as it has been labeled with an integration (network) you are listed as a code owner for? Thanks!
(message by CodeOwnersMention)

@probot-esphome
Copy link

Hey there @esphome/core, mind taking a look at this pull request as it has been labeled with an integration (ota) you are listed as a code owner for? Thanks!
(message by CodeOwnersMention)

@codecov-commenter
Copy link

codecov-commenter commented May 11, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 54.13%. Comparing base (4d8b5ed) to head (ee873ee).
Report is 668 commits behind head on dev.

Additional details and impacted files
@@            Coverage Diff             @@
##              dev    #6721      +/-   ##
==========================================
+ Coverage   53.70%   54.13%   +0.42%     
==========================================
  Files          50       50              
  Lines        9408     9619     +211     
  Branches     1654     1698      +44     
==========================================
+ Hits         5053     5207     +154     
- Misses       4056     4086      +30     
- Partials      299      326      +27     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@oarcher
Copy link
Author

oarcher commented May 11, 2024

oups, initial bad branch push, ota is not involved in this PR.

This is a currently a draft PR, it needs more works.

It is currently tested and developed on Lilygo T-SIM7600E.

It use esp-modem, so it's esp-idf only. Supported modem are SIM800, BG96, SIM7600.

I've been able to use mqtt and http_request.ota.
It doesn't works with wireguard while trombik/esp_wireguard#39 is open.

There is some modem initialisation that need to be fixed. For now, it's better to start the device from a cold state (with no power).

The PPPos data communication is done in CMUX mode, so it should be possible to send other AT command (gnss, gps, etc...) using the command channel (TODO).

And I'm sot sure that gsm is a good name for the component. perhaps cellular as a platform component, and

pppos:
  platform: cellular
  ...
  
 gps:
   platform: cellular

@oarcher oarcher changed the title [gsm] ppos tcp/ip for modem (esp-idf only) [gsm] pppos tcp/ip for uart modem (esp-idf only) May 12, 2024
@oarcher oarcher changed the title [gsm] pppos tcp/ip for uart modem (esp-idf only) [modem] pppos tcp/ip for uart modem (esp-idf only) May 14, 2024
@ChadMatsalla
Copy link

I can test this with an A7670G if that helps.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants