Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <RestClient.h>
- #define INTERVAL 5000
- #define SENSOR A0
- RestClient client = RestClient("maker.ifttt.com");
- String response;
- int uvIndex = -1;
- unsigned long previous = 0;
- void setup() {
- Serial.begin(115200);
- pinMode(SENSOR, INPUT);
- client.begin("MyWiFi", "qwerty123");
- client.setContentType("application/json");
- }
- void loop() {
- if (millis() - previous >= INTERVAL) {
- previous = millis();
- String message;
- int sensorValue;
- int analogValue = analogRead(SENSOR);
- if (analogValue < 20) {
- sensorValue = 0;
- } else {
- sensorValue = (0.05 * analogValue) - 1;
- }
- if (uvIndex != sensorValue) {
- uvIndex = sensorValue;
- if (uvIndex < 3) {
- message = "It's the best time to go out on the beach! If you burn easily, put some sunscreen!";
- } else if (uvIndex > 2 && uvIndex < 6) {
- message = "It's okay to go out on the beach but be sure to put some sunscreen!";
- } else if (uvIndex > 5 && uvIndex < 8) {
- message = "Don't risk it! Go out if it's 4PM onwards!";
- } else if (uvIndex > 7) {
- message = "You don't want to go to the beach right now. Just don't";
- }
- postDataToIfttt(message);
- }
- }
- }
- void postDataToIfttt(String data) {
- response = "";
- String postData = "{ \"value1\" : \"" + data + "\"," + " \"value2\" : \"\", \"value3\" : \"\" }";
- Serial.println(postData);
- int statusCode = client.post("/trigger/event/with/key/your_maker_key", postData.c_str(), &response);
- Serial.print("Status code from server: ");
- Serial.println(statusCode);
- Serial.print("Response body from server: ");
- Serial.println(response);
- }
Advertisement
Add Comment
Please, Sign In to add comment