#include <Redis.h>

#include <WiFi.h>

#define WIFI_SSID "Wokwi-GUEST"
#define WIFI_PASSWORD ""

#define REDIS_ADDR "redis-11502.c282.east-us-mz.azure.cloud.redislabs.com"
#define REDIS_PORT 11502
#define REDIS_PASSWORD "disciplinasunicamp"

void setup()
{
    Serial.begin(115200);
    Serial.println();

    WiFi.mode(WIFI_STA);
    WiFi.begin(WIFI_SSID, WIFI_PASSWORD);
    Serial.print("Connecting to the WiFi");
    while (WiFi.status() != WL_CONNECTED)
    {
        delay(250);
        Serial.print(".");
    }
    Serial.println();
    Serial.print("IP Address: ");
    Serial.println(WiFi.localIP());

    WiFiClient redisConn;
    if (!redisConn.connect(REDIS_ADDR, REDIS_PORT))
    {
        Serial.println("Failed to connect to the Redis server!");
        return;
    }

    Redis redis(redisConn);
    auto connRet = redis.authenticate(REDIS_PASSWORD);
    if (connRet == RedisSuccess)
    {
        Serial.println("Connected to the Redis server!");
    }
    else
    {
        Serial.printf("Failed to authenticate to the Redis server! Errno: %d\n", (int)connRet);
        return;
    }

    Serial.println(redis.lindex("30072024_1600",0) + " : " + redis.lindex("30072024_1600",1));
    Serial.println(redis.lindex("30072024_1600",2) + " : " + redis.lindex("30072024_1600",3));
    Serial.println(redis.lindex("30072024_1600",4) + " : " + redis.lindex("30072024_1600",5));
    Serial.println(redis.lindex("30072024_1600",6) + " : " + redis.lindex("30072024_1600",7));
    Serial.println(redis.lindex("30072024_1600",8) + " : " + redis.lindex("30072024_1600",9));

    redisConn.stop();
    Serial.print("Connection closed!");
}

void loop()
{
}