This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void processHttpClient() { | |
// verify if there is new client connected | |
WiFiClient client = server.available() ; | |
if ( !client ) return ; | |
Serial.println( "Client connected" ) ; | |
// prepare for reading request data | |
boolean isBlankLine = true ; | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <aJSON.h> | |
void loop() { | |
if ( ( ctrSeconds % secDebug ) == 0 ) { | |
// infoAnalogs() ; | |
Serial.println( aJson.print( jsonAnalogs() ) ) ; | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
aJsonObject *jsonAnalogs() { | |
aJsonObject *jsonRoot = aJson.createObject() ; | |
aJson.addNumberToObject( jsonRoot , "millis" , (int) millis() ) ; | |
aJsonObject *jsonAnalogs = aJson.createIntArray( arrAnalogs , maxAnalogs ) ; | |
aJson.addItemToObject( jsonRoot , "analogs" , jsonAnalogs ) ; | |
return jsonRoot ; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void readAnalogs() { | |
for ( int idxAnalogs = 0 ; idxAnalogs < maxAnalogs ; idxAnalogs++ ) { | |
arrAnalogs[idxAnalogs] = analogRead( idxAnalogs ) ; | |
} | |
} | |
void infoAnalogs() { | |
Serial.print( "[" ) ; | |
Serial.print( millis() ) ; | |
Serial.print( "] Analogs : " ) ; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void loop() { | |
// validate every one second | |
long newMillis = millis() ; | |
if ( ( newMillis - curMillis ) > 1000 ) { | |
ctrSeconds = ctrSeconds + 1 ; | |
if ( ( ctrSeconds % secAnalogs ) == 0 ) { | |
readAnalogs() ; // <- read all analog pins | |
} | |
if ( ( ctrSeconds % secDebug ) == 0 ) { | |
infoAnalogs() ; // <- debug purpose |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// prepare for looping without delay | |
long curMillis = 0 ; | |
int ctrSeconds = 0 , maxSeconds = 100 ; | |
// prepare for reading analog data | |
int maxAnalogs = 6 ; | |
int arrAnalogs[] = { 0 , 0 , 0 , 0 , 0 , 0 } ; | |
int secAnalogs = 2 ; // in seconds | |
// prepare for debuging |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <SPI.h> | |
#include <Ethernet.h> | |
#include <ICMPPing.h> | |
// prepare for tcp connection | |
byte mac[] = { 0x00, 0x08, 0xDC, 0x00, 0x00, 0x09 } ; | |
// prepare for the ping | |
SOCKET socket = 0 ; | |
int pingTimeout = 4 ; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
aJsonObject *jsonResponse( char *statusCode , char *statusDesc ) { | |
aJsonObject *jsonRoot = aJson.createObject() ; | |
aJson.addNumberToObject( jsonRoot , "millis" , (int) millis() ) ; | |
aJson.addStringToObject( jsonRoot , "status-code" , statusCode ) ; | |
aJson.addStringToObject( jsonRoot , "status-desc" , statusDesc ) ; | |
return jsonRoot ; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// prepare for the default command request | |
void defaultCommand( WebServer &webserver , WebServer::ConnectionType connType , char *tailUrl , bool tailComplete ) { | |
Serial.print( "New Command: " ) ; | |
// first, accepting all kind of request | |
webserver.httpSuccess() ; | |
// validate based on http method, | |
// only GET or POST is allow to continue | |
Serial.print( "connType = " ) ; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "SPI.h" | |
#include "Ethernet.h" | |
#include "WebServer.h" | |
#include "aJSON.h" | |
// prepare for the ethernet profile | |
static uint8_t mac[] = { 0x00 , 0x08, 0xDC, 0x00, 0x00, 0x09 } ; | |
static uint8_t ip[] = { 169, 254, 62, 169 } ; | |
// prepare for webserver with webduino |