Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

aREST using UIPEthernet stack failed #300

Open
yusuf81 opened this issue Jun 17, 2021 · 1 comment
Open

aREST using UIPEthernet stack failed #300

yusuf81 opened this issue Jun 17, 2021 · 1 comment

Comments

@yusuf81
Copy link

yusuf81 commented Jun 17, 2021

Hello @marcoschwartz ,

When I use aREST with standard ethernet.h at uno, everything working smoothly (only minor problem with memory constraint at uno). Today I want to miniaturize all my board using nano, so I moved to enc ENC28J60 ethernet module and use UIPEthernet library, when I compile it it spit error message. Is there anything to tweak when use UIP?, because it's said on UIP website it's drop-in replacement for ethernet library.

Here the error message:

E:\karim\Documents\Arduino\arest-wd\arest-wd.ino: In function 'void loop()':
arest-wd:108:21: error: no matching function for call to 'aREST::handle(UIPClient&)'
   rest.handle(client);
                     ^
In file included from E:\karim\Documents\Arduino\arest-wd\arest-wd.ino:5:0:
E:\karim\Documents\Arduino\libraries\aREST/aREST.h:787:6: note: candidate: void aREST::handle(HardwareSerial&)
 void handle(HardwareSerial& serial){
      ^~~~~~
E:\karim\Documents\Arduino\libraries\aREST/aREST.h:787:6: note:   no known conversion for argument 1 from 'UIPClient' to 'HardwareSerial&'
E:\karim\Documents\Arduino\libraries\aREST/aREST.h:811:6: note: candidate: void aREST::handle(char*)
 void handle(char * string) {
      ^~~~~~
E:\karim\Documents\Arduino\libraries\aREST/aREST.h:811:6: note:   no known conversion for argument 1 from 'UIPClient' to 'char*'
exit status 1
no matching function for call to 'aREST::handle(UIPClient&)'

Here the source code (the error is in "rest.handle(client);" line):

#include <SPI.h>
//#include <Ethernet.h>
//#include <EthernetENC.h>
#include <UIPEthernet.h>
#include <aREST.h>
#include <avr/wdt.h>
byte mac[] = {
  0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED
};
IPAddress iperror(0, 0, 0, 0);
EthernetServer server1(80);
EthernetClient client;
aREST rest = aREST();
int relay1;
int relay2;
int relay3;
//int relay4;
int relaycontrol(String command);
int pinrelay1 = 7;
int pinrelay2 = 6;
int pinrelay3 = 5;
//int pinrelay4 = 4;
unsigned long alarmreset = 300000;
unsigned long catatwaktu;
unsigned long timenow;
int matike = 10;
//int totalmati = 0;
int tegangan1 = 0;
int tegangan2 = 0;
int counterdisc = 0;

IPAddress server(10, 23, 50, 41);
unsigned long lastConnectionTime = 0;
const unsigned long postingInterval = 60L * 1000L;

int analogInput1 = A0;
int analogInput2 = A1;
float vout1 = 0.0;
float vout2 = 0.0;
float vin1 = 0.0;
float vin2 = 0.0;
float R1 = 30000.0; //
float R2 = 7500.0; //
int value1 = 0;
int value2 = 0;

void setup(void)
{
  Serial.begin(9600);
  while (!Serial) {
  }
  rest.function("reboot", reboot);
  relay1 = LOW;
  relay2 = HIGH;
  relay3 = HIGH;
  //relay4 = LOW;
  pinMode(analogInput1, INPUT);
  pinMode(analogInput2, INPUT);
  pinMode(pinrelay1, OUTPUT);
  pinMode(pinrelay2, OUTPUT);
  pinMode(pinrelay3, OUTPUT);
  //pinMode(pinrelay4, OUTPUT);
  digitalWrite(pinrelay1, relay1);
  digitalWrite(pinrelay2, relay2);
  digitalWrite(pinrelay3, relay3);
  //digitalWrite(pinrelay4, relay4);
  rest.set_id("relaykaki4");
  rest.set_name("petanetwork-relay");
  rest.variable("relay1", &relay1);
  rest.variable("relay2", &relay2);
  rest.variable("relay3", &relay3);
  //rest.variable("relay4", &relay4);
  rest.variable("tegangan1", &tegangan1);
  rest.variable("tegangan2", &tegangan2);
  Ethernet.init(10);  // Most Arduino shields
  delay(2000);
  Serial.println("Starting 2 ...");
  Ethernet.begin(mac);
  delay(2000);
  Serial.print("relay1 IP Address: ");
  Serial.println(Ethernet.localIP());
  Serial.print("Gateway IP Address: ");
  Serial.println(Ethernet.gatewayIP());
  if (Ethernet.localIP() == iperror) {
    Serial.println("IP Error");
    wdt_enable(WDTO_1S);
    while (true);
  }
  Serial.println("Web Server Starting ...");
  server1.begin();
  wdt_enable(WDTO_8S);
}

void loop() {
  relay1 = (int)digitalRead(pinrelay1);
  relay2 = (int)digitalRead(pinrelay2);
  relay3 = (int)digitalRead(pinrelay3);
  //relay4 = (int)digitalRead(pinrelay4);
  timenow = millis();
  if (relay1 == 1 && catatwaktu == 0) {
    catatwaktu = millis();
  }
  if (millis() - catatwaktu > alarmreset) {
    digitalWrite(pinrelay1, LOW);
    catatwaktu = 0;
  }
  EthernetClient client = server1.available();
  rest.handle(client);
  wdt_reset();
  if (client.available()) {
    char c = client.read();
    Serial.write(c);
  }
  if (millis() - lastConnectionTime > postingInterval) {
    httpRequest();
  }
  value1 = analogRead(analogInput1);
  vout1 = (value1 * 5.0) / 1024.0; // see text
  vin1 = vout1 / (R2 / (R1 + R2));
  tegangan1 = vin1*100;
  value2 = analogRead(analogInput2);
  vout2 = (value2 * 5.0) / 1024.0; // see text
  vin2 = vout2 / (R2 / (R1 + R2));
  tegangan2 = vin2*100;
}

void(* resetFunc) (void) = 0; //declare reset function @ address 0
int reboot (String command) {
  resetFunc();
  return 1;
}

void httpRequest() {
  client.stop();
  if (client.connect(server, 80)) {
    client.println("GET / HTTP/1.1");
    client.println("Host: 10.23.0.23");
    client.println("Connection: close");
    client.println();
    digitalWrite(pinrelay3, HIGH);
    counterdisc = 0;
    Serial.println("KONEKSI NYALA");

    Serial.print("INPUT V1= ");
    Serial.println(tegangan1);
    Serial.print("INPUT V2= ");
    Serial.println(tegangan2);
    //tanda millis()
  } else {
    counterdisc++;
    Serial.print("Mati ke:");
    Serial.println(counterdisc);
    if (counterdisc >= matike) {
      Serial.println("RESET MODEM");
      digitalWrite(pinrelay3, LOW);
      wdt_reset();
      delay(5000);
      wdt_reset();
      Serial.println("RESET MODEM SELESAI");
      digitalWrite(pinrelay3, HIGH);
      counterdisc = 0;
      //totalmati++;
    }
  }
  lastConnectionTime = millis();
}
@tobiasvogel
Copy link

I faced the same issue; using this minute change to aREST.h will fix the problem:

576c576
< #elif defined(ethernet_h_)
---
> #elif defined(ethernet_h_) || defined(UIPETHERNET_H)
1554c1554
<   #if defined(ADAFRUIT_CC3000_H) || defined(ESP8266) || defined(ethernet_h_) || defined(WiFi_h)
---
>   #if defined(ADAFRUIT_CC3000_H) || defined(ESP8266) || defined(ethernet_h_) || defined(UIPETHERNET_H) || defined(WiFi_h)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants