Hey Guys,
Very new to arduino.
Im trying to have multiple push buttons set up with my Ethernet shield so when i press a push button it does a get request from a different websites
Im using it with software called Houdini MC that runs off of HTTP requests.
I have it working with a single button pushing a single HTTP request but would love multiple buttons hitting different places.
my current code is- (which i got from the houdini website)
#include <SPI.h>
#include <Ethernet.h>
// this must be unique
byte mac[] = {
0xDE, 0xAD, 0xB8, 0xEF, 0xFE, 0xED };
int systemState = 0;
// change to your network settings
IPAddress ip(192,168,1,113);
// change to your server
IPAddress server(192,168,1,42);
char serverName[] = "192,168,1,42";
// change to your server’s port
int serverPort = 14999;
EthernetClient client;
int totalCount = 0;
char pageAdd[64];
//buttonPin
const int buttonPin = 2;
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);
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 arrives
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,"/stop"); (!getPage(server, serverPort, pageAdd));
Serial.println("Button pressed");
systemState == 1;
}
}
Hey Guys,
Very new to arduino.
Im trying to have multiple push buttons set up with my Ethernet shield so when i press a push button it does a get request from a different websites
Im using it with software called Houdini MC that runs off of HTTP requests.
I have it working with a single button pushing a single HTTP request but would love multiple buttons hitting different places.
my current code is- (which i got from the houdini website)
#include <SPI.h>
#include <Ethernet.h>
// this must be unique
byte mac[] = {
0xDE, 0xAD, 0xB8, 0xEF, 0xFE, 0xED };
int systemState = 0;
// change to your network settings
IPAddress ip(192,168,1,113);
// change to your server
IPAddress server(192,168,1,42);
char serverName[] = "192,168,1,42";
// change to your server's port
int serverPort = 14999;
EthernetClient client;
int totalCount = 0;
char pageAdd[64];
//buttonPin
const int buttonPin = 2;
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);
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 arrives
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,"/stop"); (!getPage(server, serverPort, pageAdd));
Serial.println("Button pressed");
systemState == 1;
}
}