Add arduino-mk Makefile and fix build

This commit is contained in:
Daniel Gröber 2017-03-06 13:28:30 +01:00
parent 3a0663bd70
commit 623d50b873
2 changed files with 154 additions and 151 deletions

View file

@ -54,102 +54,6 @@ const int rlight = 6;
const int topen = 2; const int topen = 2;
const int tclose = 3; const int tclose = 3;
// Status LED pins
void setup()
{
pinMode(glight, OUTPUT);
pinMode(rlight, OUTPUT);
// Buttons with pullup resistor
pinMode(topen, INPUT);
pinMode(tclose, INPUT);
digitalWrite(topen,HIGH);
digitalWrite(tclose,HIGH);
// Start Serial for debugging on the Serial Monitor
if(debug){
Serial.begin(9600);
}
// Start Ethernet on Arduino
setEth(-1);
setRoom(2);
Timer1.initialize(20000); // 50 mal die Sekunde
Timer1.attachInterrupt(setLeds);
startEthernet();
delay(1000);
// Get current Status
RequestState();
}
void loop()
{
readButtons();
launchUpdate();
}
void readButtons(){
int ret=0;
if((digitalRead(topen)==LOW)&&(hsopen!=1)){
//startEthernet();
setRoom(2);
TriggerServerUpdate(true);
}
if((digitalRead(tclose)==LOW)&&(hsopen!=0)){
//startEthernet();
setRoom(2);
TriggerServerUpdate(false);
}
}
void launchUpdate(){
if(update==1){
RequestPing();
RequestState();
update = 0;
}
}
void startEthernet()
{
client.stop();
if(debug){
Serial.println("Connecting Arduino to network...");
Serial.println();
}
setEth(-1);
delay(1000);
// Connect to network amd obtain an IP address using DHCP
if (Ethernet.begin(mac) == 0)
{
if(debug){
Serial.println("DHCP Failed, reset Arduino to try again");
Serial.println();
}
setEth(0);
}
else
{
if(debug){
Serial.println("Arduino connected to network using DHCP");
Serial.println();
}
setEth(1);
}
if(debug){
Serial.println("DONE");
Serial.println();
}
delay(1000);
}
void setLeds(){ void setLeds(){
if (pingtimer>=0) if (pingtimer>=0)
{ {
@ -256,49 +160,38 @@ void setRoom(int statuss){
setLeds(); setLeds();
} }
void startEthernet()
void RequestState() { {
TriggerServerReq("/status-s.php",0); client.stop();
if(debug){
Serial.println("Connecting Arduino to network...");
Serial.println();
} }
setEth(-1);
delay(1000);
// Connect to network amd obtain an IP address using DHCP
void RequestPing() { if (Ethernet.begin(mac) == 0)
TriggerServerReq("/ping-get.php?apikey="+pingAPIKey,1); {
if(debug){
Serial.println("DHCP Failed, reset Arduino to try again");
Serial.println();
} }
setEth(0);
void TriggerServerReq(String s, int mode) {
// attempt to connect, and wait a millisecond:
if(debug){Serial.println("connecting to server... Status req");}
if (client.connect(serverName, 80)) {
if(debug){Serial.println("making HTTP request...");}
// make HTTP GET request to server:
client.println("GET "+ s +" HTTP/1.1");
client.println("HOST: it-syndikat.org");
client.println("Connection: close");
client.println();
readServerStatus(mode);
}else{
if(debug){Serial.println("Not connected...");}
} }
// note the time of this connect attempt: else
{
if(debug){
Serial.println("Arduino connected to network using DHCP");
Serial.println();
} }
setEth(1);
void TriggerServerUpdate(boolean stat) {
// attempt to connect, and wait a millisecond:
if(debug){Serial.println("connecting to server... Update Req");}
if (client.connect(serverName, 80)) {
if(debug){Serial.println("making HTTP request...");}
// make HTTP GET request to server:
String s =(stat?"true":"false");
client.println("GET /update.php?open=" + s + "&apikey="+serverAPIKey+" HTTP/1.1");
client.println("HOST: it-syndikat.org");
client.println("Connection: close");
client.println();
readServerStatus(0);
}else{
if(debug){Serial.println("Not connected...");}
} }
// note the time of this connect attempt: if(debug){
Serial.println("DONE");
Serial.println();
}
delay(1000);
} }
//reads out the status returned by the server and sets the LED's appropriately. //reads out the status returned by the server and sets the LED's appropriately.
@ -365,6 +258,109 @@ int readServerStatus(int mode) {
client.stop(); client.stop();
} }
void TriggerServerReq(String s, int mode) {
// attempt to connect, and wait a millisecond:
if(debug){Serial.println("connecting to server... Status req");}
if (client.connect(serverName, 80)) {
if(debug){Serial.println("making HTTP request...");}
// make HTTP GET request to server:
client.println("GET "+ s +" HTTP/1.1");
client.println("HOST: it-syndikat.org");
client.println("Connection: close");
client.println();
readServerStatus(mode);
}else{
if(debug){Serial.println("Not connected...");}
}
// note the time of this connect attempt:
}
void RequestState() {
TriggerServerReq("/status-s.php",0);
}
// Status LED pins
void setup()
{
pinMode(glight, OUTPUT);
pinMode(rlight, OUTPUT);
// Buttons with pullup resistor
pinMode(topen, INPUT);
pinMode(tclose, INPUT);
digitalWrite(topen,HIGH);
digitalWrite(tclose,HIGH);
// Start Serial for debugging on the Serial Monitor
if(debug){
Serial.begin(9600);
}
// Start Ethernet on Arduino
setEth(-1);
setRoom(2);
Timer1.initialize(20000); // 50 mal die Sekunde
Timer1.attachInterrupt(setLeds);
startEthernet();
delay(1000);
// Get current Status
RequestState();
}
void TriggerServerUpdate(boolean stat) {
// attempt to connect, and wait a millisecond:
if(debug){Serial.println("connecting to server... Update Req");}
if (client.connect(serverName, 80)) {
if(debug){Serial.println("making HTTP request...");}
// make HTTP GET request to server:
String s =(stat?"true":"false");
client.println("GET /update.php?open=" + s + "&apikey="+serverAPIKey+" HTTP/1.1");
client.println("HOST: it-syndikat.org");
client.println("Connection: close");
client.println();
readServerStatus(0);
}else{
if(debug){Serial.println("Not connected...");}
}
// note the time of this connect attempt:
}
void readButtons(){
int ret=0;
if((digitalRead(topen)==LOW)&&(hsopen!=1)){
//startEthernet();
setRoom(2);
TriggerServerUpdate(true);
}
if((digitalRead(tclose)==LOW)&&(hsopen!=0)){
//startEthernet();
setRoom(2);
TriggerServerUpdate(false);
}
}
void RequestPing() {
TriggerServerReq("/ping-get.php?apikey="+pingAPIKey,1);
}
void launchUpdate(){
if(update==1){
RequestPing();
RequestState();
update = 0;
}
}
void loop()
{
readButtons();
launchUpdate();
}
//This just reads the server return and logs it to the serial //This just reads the server return and logs it to the serial
// @deprecated // @deprecated
@ -380,4 +376,3 @@ void readServerReturn() {
if(debug){Serial.println("disconnecting.");} if(debug){Serial.println("disconnecting.");}
client.stop(); client.stop();
} }

View file

@ -0,0 +1,8 @@
ARDUINO_DIR = /usr/share/arduino
ARDMK_DIR = /usr/share/arduino
AVR_TOOLS_DIR = /usr
BOARD_TAG = uno
ARDUINO_LIBS = Ethernet SPI
include $(ARDMK_DIR)/Arduino.mk