Skip to content

Instantly share code, notes, and snippets.

View biskandar's full-sized avatar
💭
Spring Boot + Kubernetes = DevOps

Benny biskandar

💭
Spring Boot + Kubernetes = DevOps
View GitHub Profile
@biskandar
biskandar / 2012101606.c
Created October 16, 2012 09:03
Reading Arduino's Analog Pins with JSON Protocol by using WiFi Shield 2012101606
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 ;
@biskandar
biskandar / 2012101605.c
Created October 16, 2012 09:02
Reading Arduino's Analog Pins with JSON Protocol by using WiFi Shield 2012101605
#include <aJSON.h>
void loop() {
if ( ( ctrSeconds % secDebug ) == 0 ) {
// infoAnalogs() ;
Serial.println( aJson.print( jsonAnalogs() ) ) ;
}
}
@biskandar
biskandar / 2012101604.c
Created October 16, 2012 09:00
Reading Arduino's Analog Pins with JSON Protocol by using WiFi Shield 2012101604
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 ;
}
@biskandar
biskandar / 2012101603.c
Created October 16, 2012 09:00
Reading Arduino's Analog Pins with JSON Protocol by using WiFi Shield 2012101603
void readAnalogs() {
for ( int idxAnalogs = 0 ; idxAnalogs < maxAnalogs ; idxAnalogs++ ) {
arrAnalogs[idxAnalogs] = analogRead( idxAnalogs ) ;
}
}
void infoAnalogs() {
Serial.print( "[" ) ;
Serial.print( millis() ) ;
Serial.print( "] Analogs : " ) ;
@biskandar
biskandar / 2012101602.c
Created October 16, 2012 08:58
Reading Arduino's Analog Pins with JSON Protocol by using WiFi Shield 2012101602
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
@biskandar
biskandar / 2012101601.c
Created October 16, 2012 08:57
Reading Arduino's Analog Pins with JSON Protocol by using WiFi Shield 2012101601
// 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
@biskandar
biskandar / 2012101001.c
Created October 10, 2012 13:29
Make your arduino and his best ethernet friend talk to the world 2012101001
#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 ;
@biskandar
biskandar / 2012100804.c
Created October 8, 2012 12:25
Simplified webserver module using Webduino library 2012100804
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 ;
}
@biskandar
biskandar / 2012100803.c
Created October 8, 2012 12:17
Simplified webserver module using Webduino library 2012100803
// 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 = " ) ;
@biskandar
biskandar / 2012100802.c
Created October 8, 2012 11:48
Simplified webserver module using Webduino library 2012100802
#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