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

ESP32 derive not working #94

Closed
Heusini opened this issue May 26, 2021 · 3 comments
Closed

ESP32 derive not working #94

Heusini opened this issue May 26, 2021 · 3 comments

Comments

@Heusini
Copy link

Heusini commented May 26, 2021

The ESP32 returns the sent request as an echo thus i cannot simply derive the AtatResp but have to manually parse the response.

Here is an example.
This is the request i send:

#[at_cmd("+CWJAP", WifiConnectResponse)]
pub struct WifiConnect {
  #[at_arg(position = 0)]
  pub ssid: String<64>,
  #[at_arg(position = 1)]
  pub pw: String<128>,
}

This is the raw response as returned from the esp32:

AT+CWJAP="ssid","password"
WIFI CONNECTED
WIFI GOT IP

OK

It would be nice if the above response could be parsed with the following AtatResp derive.

#[derive(Clone, Debug, AtatResp)]
pub struct WifiConnectResponse {
  #[at_arg(position = 0)]
  pub connected: String<32>,
  #[at_arg(position = 1)]
  pub got_ip: String<32>,
}
@Heusini Heusini changed the title ESP32 AT-Echo derive not working ESP32 derive not working May 26, 2021
@MathiasKoch
Copy link
Member

The problem is not actually that the device returns the echo, this is actually a requirement currently due to #82 .

The problem in this case, is that the ATAT parser expects parameters of the response to be separated by a ,, where in this case they are separated by \r\n

I will have a look when i get time, to see if it would be possible to extend the derive capabilities with a separator option.

Thanks for reporting!

@Heusini
Copy link
Author

Heusini commented May 26, 2021

Shouldn't this parse?
This is the full raw response:

AT+CIPDNS?
+CIPDNS:1,"42.2.129.13","8.8.8.8"

OK

This is the buffer after the digest:

+CIPDNS?
+CIPDNS:1,"42.2.129.13","8.8.8.8"

This is the struct i use to parse:

#[derive(Clone, Debug, PartialEq, AtatResp)]
pub struct DNSResponse {
    pub dns: String<64>,
    pub dns_1: String<64>,
    pub dns_2: String<64>,
}

I get a parse error but shouldn't the DNSResponse look like this:

dns = +CIPDNS?\r\n+CIPDNS:1
dns_1 = 42.2.129.13
dns_2 = 8.8.8.8

@MathiasKoch
Copy link
Member

MathiasKoch commented May 27, 2021

Hmm, not quite.

The parsed values will only be the parameters after the :, meaning that what you would probably want for this case would be:

#[derive(Clone, Debug, PartialEq, AtatResp)]
pub struct DNSResponse {
    pub some_flag: u8,
    pub dns_1: String<64>,
    pub dns_2: String<64>,
}

Where some_flag is the first parameter (value 1), that i have no idea what is without context :)

That should work.. If you want to improve it a little further, you could use no_std_net::IpAddr for the IP's (or no_std_net::Ipv4Addr if only v4 is supported)

Just make sure to enable the serde feature of no_std_net

One further, the first parameter could of course be changed into an enum, being a lot more descriptive than a u8 flag.

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

No branches or pull requests

2 participants