Xinyuan-LilyGO / LilyGO-T-SIM7000G

LilyGO T-SIM7000G
https://pt.aliexpress.com/item/4000542688096.html
283 stars 123 forks source link

SIM7000G positioning and cellular #246

Open BestITUserEUW opened 9 months ago

BestITUserEUW commented 9 months ago

Hey, I wanted to know if it's possible to use positioning and cellular at the same time with SIM7000G ? You only mention SIM7070 not supporting that, but I couldn't find examples on position and cellular at the same time. I'm not too familiar with modems but from what I read here: https://github.com/espressif/esp-protocols/blob/master/docs/esp_modem/en/README.rst

You have different modes your modem can be in DATA for cellular and COMMAND for sending and receiving at commands. There is also CMUX which can enable both, in the readme it's said that sim7000 series does not support cmux at all. I can't use TinyGsm because there is no support for x509 Certficate authentication which I need for my Mqtt broker, so I am using esp_modem from esp-idf with idf framework right now. I was able to connect to the broker, publish and receive data with ssl connection and also switch between data and command mode and thus publishing Gps data, but I wasn't able to send at commands while having cellular connection open.

Is it possible that I can get gps data and publish over cellular at the same time ?

Jorin-Post commented 6 months ago

So far I know you can save the AT+CGNSINF string in a char and do what ever data manipulation that you want and send it trough MQTT. I did it with the adafruit MQTT broker. This is the function I used: ` void transCoordinates() { while (lat <= 0 || lon <= 0) { modem.sendAT("+SGPIO=0,4,1,1"); if (modem.waitResponse(10000L) != 1) { Serial.println(" SGPIO=0,4,1,1 false "); } modem.enableGPS(); Serial.println("Requesting current GPS/GNSS/GLONASS location"); if (modem.getGPS(&lat, &lon)) { Serial.println("Latitude: " + String(lat, 8) + "\tLongitude: " + String(lon, 8)); } delay(1000); } char *p = sendbuffer; // add speed value dtostrf(speed_mph, 2, 6, p); p += strlen(p); p[0] = ','; p++;

// concat latitude dtostrf(lat, 2, 6, p); p += strlen(p); p[0] = ','; p++;

// concat longitude dtostrf(lon, 3, 6, p); p += strlen(p); p[0] = ','; p++;

// concat altitude dtostrf(altitude, 2, 6, p); p += strlen(p);

// null terminate p[0] = 0;

//Serial.print("Sending: "); Serial.println(sendbuffer); // (Speed,Latitude,Longitude,Altitude) mqtt.publish(GPSTopic, sendbuffer); } `

I'm struggling with getting a mqtt connection over SSL handshake and SAS code as password. Are you willing to send the code you have running on the SIM7000?

BestITUserEUW commented 6 months ago

@Jorin-Post My Problem is that i want to get Gps data from device and publish over lte at the same time and as far as i know, for that you have to switch between data and command mode in modem.

For your problem, I can't really send you the code it's not open source. I haven't found a way to get ssl handshake done with Arduino Framework and LTE, but for esp-idf framework i found a solution using PPP (Point to Point Protocol) Client. With that you can establish ssl connection with LTE. Here is an example for pppos client in esp-idf.

https://github.com/espressif/espprotocols/blob/master/components/esp_modem/examples/pppos_client/main/pppos_client_main.c

You will also need esp_modem library and esp_mqtt library from esp-idf. In esp_mqtt client setup you can add your ssl certs:

esp_mqtt_client_config_t mqttConf{}; mqttConf.broker.verification.certificate = "root_cert"; mqttConf.credentials.authentication.certificate = "client_cert"; mqttConf.credentials.authentication.key ="client_key";

If you don't need modem and you are publishing over Wifi just use WiFiClientSecure like so:

WiFiClientSecure wcs{}; wcs.setCACert("ca_cert_data"); wcs.setCertificate("certificate_data"); wcs.setPrivateKey("private_key_data");

Then pass wcs to your mqtt library on initialization. For example 256dpi/MQTT:

MQTTClient mqttClient{}; mqttClient.begin("myEndpoint", 8883, wcs);

Jorin-Post commented 6 months ago

Esp IDF is a bit more advanced than what I used to. But thx I'm going to try it. For your problem I have unfortunately no fix.