A place users can post their projects. If you have a small project and would like your own dedicated place to post and have others chat about it then this is your spot.

User avatar
By GalactusX31
#95975 Now I'm back!!
I lost all my work because of my stupidity, I reinstalled my computer from 0, and I forgot that all my projects were in a partition on the disk destined for windows :evil: ...

I have had to start everything from scratch :shock: and I have progressed, I have had new ideas, new problems and new solutions.

I have played around with the possibility of, instead of having all the languages "hand-coded" into a very large list, have a simple and light list of "keywords" and "translate them to the need" of the end user.

I'm polishing the code to make it cleaner and more efficient, removing all the unnecessary junk, you know, annotations, trial and error code. To date I have been able to complete my 2 big challenges:

1. Translate a text "A" into another "B" with a simple function.
2. Generate the audio of the translated text "B" and save it in a MicroSD memory.

Currently, the translation of any text is only limited by the number of languages available in google translator and, not only that, I also enjoy the literal "translation" that Google does of times, dates and expressions, without the use of API or additional modules.

If someone is encouraged to help me, I need a "simple" and "light" way to get the time and date without the need to put it in the code, just like windows does, taking the time from a server. I'll post my progress.
User avatar
By GalactusX31
#95977
GalactusX31 wrote:If someone is encouraged to help me, I need a "simple" and "light" way to get the time and date without the need to put it in the code, just like windows does, taking the time from a server. I'll post my progress.


Goal accomplished!!

It took me a whole day to figure out the best way to set the time automatically, capturing time zone and UTC through the public IP of the Wifi network... I'm starting to understand how the "ArduinoJson.h" library works , and I'm going to almost completely redesign the way I structure my configuration files.

More work and progress this weekend, I'll post parts of my code, I hope they help me polish it and make it more efficient.
User avatar
By GalactusX31
#96044 A small update:

In order to use as few mules as possible, without the need to use a GPS device to obtain the user's position, I am going to use the WIFI connection point to obtain the data referring to its position, and thus obtain all the necessary information, as well as other data of interest.
Code: Select all#include <WiFi.h>
#include <HTTPClient.h>

HTTPClient http;

const char* ssid = "YOUR_WIFI_NAME";
const char* password = "YOUR_WIFI_PASSWORD";

void UserInfo(){
  http.begin("https://ipapi.co/json");
 
  int httpCode = http.GET();

  if(httpCode == 200) {
    String payload = http.getString();
    Serial.println(payload);
  } else { 
    Serial.printf("[HTTP] GET... failed, error: %s\n", http.errorToString( httpCode ).c_str() );
  }
    http.end();
}

void setup() {
  Serial.begin(115200);
  WiFi.begin(ssid, password);
  Serial.println("Connecting to WiFi...");

  while (WiFi.status() != WL_CONNECTED) {
    delay(1000);
    Serial.print(".");
  }

  Serial.println("Connected to WiFi");
  UserInfo();
}

void loop() {
}

Image

With this code a call is made to "https://ipapi.co/json", and in response it gives us data in the form of a *.json file, here we collect many interesting data such as public IP, city, country name, capital, currency, languages spoken... and most importantly, timezone and utc_offset, which will help us to configure the clock.

If anyone has a better idea of how to collect this data, I would appreciate any help I can get, as well as suggestions and corrections.
User avatar
By GalactusX31
#96073 A small preview of my work from these weeks:

After many trials and errors, I have found the "efficient" way to save the data for the different languages, I have decided to use the "ArduinoJson" library for this purpose, and in this way generate the necessary "base" files for everything, thus saving space on the microcontroller.

This is just a function to save the days of the week, having 3 fields, "lang" is the language to which it is translated, "text" is the name of the day of the week and "audio" is the address of the audio file on the microsd card.

Code: Select allvoid WeekFileCreation() {
  DynamicJsonDocument doc(1024);
  JsonObject week = doc.createNestedObject("WEEK");
  JsonObject monday = week.createNestedObject("monday");
  monday["lang"] = "es";
  monday["text"] = "Lunes";
  monday["audio"] = "audio/lunes.mp3";
  JsonObject tuesday = week.createNestedObject("tuesday");
  tuesday["lang"] = "es";
  tuesday["text"] = "Martes";
  tuesday["audio"] = "audio/martes.mp3";
  JsonObject wednesday = week.createNestedObject("wednesday");
  wednesday["lang"] = "es";
  wednesday["text"] = "Miércoles";
  wednesday["audio"] = "audio/miercoles.mp3";
  JsonObject thursday = week.createNestedObject("thursday");
  thursday["lang"] = "es";
  thursday["text"] = "Jueves";
  thursday["audio"] = "audio/jueves.mp3";
  JsonObject friday = week.createNestedObject("friday");
  friday["lang"] = "es";
  friday["text"] = "Viernes";
  friday["audio"] = "audio/viernes.mp3";
  JsonObject saturday = week.createNestedObject("saturday");
  saturday["lang"] = "es";
  saturday["text"] = "Sábado";
  saturday["audio"] = "audio/sabado.mp3";
  JsonObject sunday = week.createNestedObject("sunday");
  sunday["lang"] = "es";
  sunday["text"] = "Domingo";
  sunday["audio"] = "audio/domingo.mp3";

  file = SD.open("/WeekConfig.json", FILE_WRITE);
  if (file) {
    Serial.println("Creating \"WeekConfig\" file...");
    serializeJson(doc, file);
    file.close();
  } else {
    Serial.println("Error creating \"WeekConfig\" file");
  }
}

Then, I create a process to access any specific data from the configuration files.

Code: Select allString getJsonValue(const char* filejson, const char* object, const char* field1, const char* field2, const char* field3) {
#define BUFFER_SIZE 1024
  StaticJsonDocument<BUFFER_SIZE> doc;
  file = SD.open(filejson, FILE_READ);
  DeserializationError error = deserializeJson(doc, file);
  file.close();

  if (field3 == "") {
    String value = doc[object][field1][field2].as<String>();
    return value;
  } else {
    String value = doc[object][field1][field2][field3].as<String>();
    return value;
  }

  if (error) {
    Serial.print("Error reading file: ");
    Serial.println(error.c_str());
    return "";
  }
}

This part of the code is launched when the device is first started; if it detects that the configuration file does not exist, it calls the function to create it.

Code: Select all...
  if (!SD.exists("/WeekConfig.json")) {
    Serial.println("\"WeekConfig\" file not found, creating it");
    WeekFileCreation();
  } else {
    Serial.println("\"WeekConfig\" file found, OK");
  }
...

And finally, the most "efficient" way that I have found is this, passing the name/pointer of the configuration file and the different fields/address of the data to request.

Code: Select all...
  String dayweek = getJsonValue("/WeekConfig.json", "WEEK", "wednesday", "text", "");
  Serial.println("Data of week['wednesday']['text']: " + dayweek);
...


This is just part of my project, I'm piecing together the pieces of code I've been working on... treating each task as an independent one, this way I can design, learn from my mistakes and improve my understanding of the programming in arduino.

If someone knows how to improve my code and/or has ideas to improve my project, everything will be very welcome.