Hi guys,
I got a code from my software vendor.
It needs to get http request when the button is pressed.
Unfortunately, arduino gives a lot of errors to this code.
I do not understand what goes wrong, can you help me?
#include <SPI.h>
#include <Ethernet2.h>
// this must be unique
byte mac[] = {
0xFE, 0xE7, 0xDE, 0xB0, 0xDC, 0x9B
};
int systemState = 0;
// change to your network settings
IPAddress ip(192, 168, 1, 110);
IPAddress gateway(192, 168, 1, 1);
IPAddress subnet(255, 255, 255, 0);
// change to your server
IPAddress server(192, 168, 178, 104);
char serverName[] = “192, 168, 178, 104”;
// change to your server’s port
int serverPort = 14999;
EthernetClient client;
int totalCount = 0;
char pageAdd[64];
//buttonPin
const int buttonPin = 2; // the number of the pushbutton pin
void setup() {
Serial.begin(9600);
// disable SD SPI
pinMode(4, OUTPUT);
digitalWrite(4, HIGH);
//button pin mode
pinMode(buttonPin, INPUT);
// Start ethernet
Serial.println(“Starting ethernet…”);
Ethernet.begin(mac, ip, gateway, gateway, subnet);
Serial.println(Ethernet.localIP());
delay(2000);
Serial.println(“Ready”);
}
void loop() {
if (systemState == 0) {
pushButton();
}
}
byte getPage(IPAddress ipBuf, int thisPort, char *page)
{
int inChar;
char outBuf[128];
Serial.print(F(“connecting…”));
if (client.connect(ipBuf, thisPort) == 1)
{
Serial.println(F(“connected”));
sprintf(outBuf, ”GET % s HTTP / 1.1″, page);
client.println(outBuf);
sprintf(outBuf, ”Host: % s”, serverName);
client.println(outBuf);
client.println(F(“Connection: close\r\n”));
}
else
{
Serial.println(F(“failed”));
return 0;
}
// connectLoop controls the hardware fail timeout
int connectLoop = 0;
while (client.connected())
{
while (client.available())
{
inChar = client.read();
Serial.write(inChar);
// set connectLoop to zero if a packet arrive
connectLoop = 0;
}
connectLoop++;
// if more than 10000 milliseconds since the last packet
if (connectLoop > 10000)
{
// then close the connection from this end.
Serial.println();
Serial.println(F(“Timeout”));
client.stop();
}
// this is a delay for the connectLoop timing
delay(1);
}
Serial.println();
Serial.println(F(“disconnecting.”));
// close client end
client.stop();
return 1;
}
//Send get request to Houdini if button was pressed
void pushButton() {
if (digitalRead(buttonPin) == HIGH) {
// send request to Houdini
sprintf(pageAdd, ” / Custom_Term”); (!getPage(server, serverPort, pageAdd));
Serial.println(“Button pressed”);
systemState == 1;
}
}