embassy icon indicating copy to clipboard operation
embassy copied to clipboard

Help wanted: embassy-net-ppp

Open KorribanMaster opened this issue 1 year ago • 2 comments

Hello, I'm trying to set up a project with a simcom sim868 GSM/GNSS module using PPP. I managed to setup the module using PPP on linux successfully using the following guide as well as talking to the simcom module via serial from an stm32f449 and connecting it to a network and sending data using AT commands but using the ppp network from embassy seems much nicer integrated.

However I can not figure out how to setup embassy ppp from the example to connect using the real modem. I guess what i am missing is the modem and carrier specifics that are setup via the ppp config and the chatscript when using linux and pppd.

Has anyone already setup a real gsm modem using ppp and maybe could provide an example or some cues on the process?

KorribanMaster avatar Jun 19 '24 08:06 KorribanMaster

embassy-net-ppp only does the "PPP" part, not the "AT command" part. You can use it with a modem but you have to do the AT commands yourself.

Run the AT commands needed to setup the modem (write it as a string to the uart, then wait the modem to reply with OK). The last command ATD*99# is special: write it as a string, then wait for the modem to reply with CONNECT. After this, the UART is switched to "data mode", speaking PPP. After this is done, you can start forwarding bytes between the serial port and embassy-net-ppp.

Dirbaio avatar Jun 19 '24 10:06 Dirbaio

Hello, I'm trying to set up a project with a simcom sim868 GSM/GNSS module using PPP. I managed to setup the module using PPP on linux successfully using the following guide as well as talking to the simcom module via serial from an stm32f449 and connecting it to a network and sending data using AT commands but using the ppp network from embassy seems much nicer integrated.

However I can not figure out how to setup embassy ppp from the example to connect using the real modem. I guess what i am missing is the modem and carrier specifics that are setup via the ppp config and the chatscript when using linux and pppd.

Has anyone already setup a real gsm modem using ppp and maybe could provide an example or some cues on the process?

I'm actually working on this and managed to make it work (dirty code, a lot of messing). I can provide you the steps what you should look for (right now I have huge mess in code, doing a lot of this and that and mixed up together). I did exactly what Dirbaio said and worked pretty well.

  1. you need to setup two buffers (rx and tx), like [u8; N_RX/TX];
  2. connect to modem via UART, dirty example taken from my code:
    // somewhere top before main
    bind_interrupts!(struct UartIrqs {
        USART1 => embassy_stm32::usart::BufferedInterruptHandler<peripherals::USART1>;
    });

    // in main
     let mut uart = embassy_stm32::usart::BufferedUart::new(
         p.USART1,
         UartIrqs,
         p.PA10,
         p.PA9,
         tx_buffer,
         rx_buffer,
         Default::default(),
     )
     .unwrap();
  1. send commands to modem to setup and switch to data mode (in my case I send AT+CGDCONT=1,"ip","apn"\r followed by ATD*99#\r. example sending / receiving part:
    // reading & parsing output is up to you, to make sure modem is up, got successful replies on commands, etc.
    uart.write_all("AT\r".as_bytes()).await.unwrap();
    uart.flush().await.unwrap();
    Timer::after_secs(1).await; // wait for a bit for modem to respond
    uart.read(&mut buf).await.unwrap();
  1. now comes the embassy_net_ppp part:
let state = embassy_net_ppp::State::<N_RX, N_TX>::new();
let (device, runner) = embassy_net_ppp::new(state);

let cfg = embassy_net_ppp::Config {
  username: "foo".as_bytes(),
  password: "bar".as_bytes(),
}

runner.run(uart, cfg, |stat| {
  info!("stat: {}", stat);
});

then basically follow the docs, you already have the connection. create network stack, etc.

overflowz avatar Aug 22 '24 20:08 overflowz

ah i was only missing the ATD*99#\r part i already figured i probably need to connect the modem first. Thanks a lot to both of you. Maybe i can make a PR to the README of embassy_net_ppp to explain this a little better

KorribanMaster avatar Sep 09 '24 06:09 KorribanMaster