#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.print("PUBLISH foo bar: ");
Serial.println(redis.publish("foo", "bar"));
redisConn.stop();
Serial.print("Connection closed!");
}
void loop()
{
}