EasyIot server with arduino relay HELP!!!

7 years 3 months ago #3869 by c150186.learn
Hi
I'm currently using Raspberry Pi 3B as EasyIOT server, relays connected to arduino uno with ESP8266.
I followed the guide from iot-playground.com/blog/2-uncategorised/...66-wifi-relay-switch but it doesn't work.

I setup my relay pin connected to pin 11 and RX&TX to 2&3. Below is the ino code i modified.
/*
 V1.0 - first version
 V1.1 - adopt to new library 
 
 Created by Igor Jarc <igor.jarc1@gmail.com>
 See http://iot-playground.com for details
 
 This program is free software; you can redistribute it and/or
 modify it under the terms of the GNU General Public License
 version 2 as published by the Free Software Foundation.
 */
#include <Esp8266EasyIoT.h>
#include <SoftwareSerial.h> 

Esp8266EasyIoT esp; 

SoftwareSerial serialEsp(2,3);



#define RELAY_1  11  // Arduino Digital I/O pin number for first relay (second on pin+1 etc)
#define RELAY_ON 1  // GPIO value to write to turn on attached relay
#define RELAY_OFF 0 // GPIO value to write to turn off attached relay


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

  Serial.println("EasyIoTEsp init");

  esp.begin(incomingMessage, 4  , &serialEsp, &Serial);
  //esp.begin(incomingMessage, 3, &serialEsp);

  pinMode(RELAY_1, OUTPUT);

  esp.present(1, S_DIGITAL_OUTPUT);
}

void loop()
{
  esp.process();
}

void incomingMessage(const Esp8266EasyIoTMsg &message) {
  // We only expect one type of message from controller. But we better check anyway.

  Serial.println("New message");
  if (message.type==V_DIGITAL_VALUE) {
    // Change relay state
    digitalWrite(message.sensor-1+RELAY_1, message.getBool()?RELAY_ON:RELAY_OFF);

    Serial.print("Incoming change for sensor:");
    Serial.print(message.sensor);
    Serial.print(", New status: ");
    Serial.println(message.getBool());
  } 
}

I was able to access the server address and added the ESP8266 driver in. However, when I tried switching on the relay ... the webpage relay interface remain as OFF no matter how many times I press ON.

Please help me. Thanks a million.

Please Log in or Create an account to join the conversation.

Time to create page: 0.144 seconds

Forum latest

  • No posts to display.