this one has anologWrite which is more what you was asking for.
only changes to need to make are in setup pinMode etc and
function htmlPage
String body = ""; //add buttons selector
#include <DigiFi.h>
DigiFi server;
void setup() {
Serial.begin(9600);
server.begin(9600);
pinMode(7,OUTPUT);
pinMode(6,OUTPUT);
pinMode(5,OUTPUT);
pinMode(4,OUTPUT);
digitalWrite(7,HIGH);
digitalWrite(6,LOW);
digitalWrite(5,LOW);
digitalWrite(4,LOW);
//DigiX trick - since we are on serial over USB wait for character to be entered in serial terminal
while(!Serial.available()){
Serial.println("Enter any key to begin");
delay(1000);
}
Serial.println("Starting");
Serial.println("wifi inited");
while (server.ready() != 1)
{
Serial.println("Error connecting to network");
delay(15000);
}
Serial.println("Connected to wifi!");
Serial.print("Server running at: ");
String address = server.server(8080);//sets up server and returns IP
Serial.println(address);
}
void loop() {
if ( server.serverRequest()){
if( findOutHowManyCharInAString( server.serverRequestPath() , '=') !=0){
getUrlVariablesFromWifiString( server.serverRequestPath() );
server.serverResponse(htmlReturn()); //need relay so brouser dont hang
}
else
server.serverResponse(htmlPage()); //defaults to 200
}
}
void runVariableCommand(String string){
if(string.charAt(0)=='d'){ // letter d = Digital
int endOfVariableName = string.indexOf('=');
int booleanValue = stringToInt(string.substring(endOfVariableName+1,string.length()));
String variableName = string.substring(0,endOfVariableName);
digitalWrite( stringToInt( variableName.substring(1,variableName.length()) ), booleanValue );
Serial.print("digital Pin ");
Serial.print(stringToInt( variableName.substring(1,variableName.length()) ));
Serial.print(" to ");
Serial.println(booleanValue);
}
if(string.charAt(0)=='a'){ // letter a = Analog
int endOfVariableName = string.indexOf('=');
int booleanValue = stringToInt(string.substring(endOfVariableName+1,string.length()));
String variableName = string.substring(0,endOfVariableName);
analogWrite( stringToInt( variableName.substring(1,variableName.length()) ), booleanValue );
Serial.print("Analog Pin ");
Serial.print(stringToInt( variableName.substring(1,variableName.length()) ));
Serial.print(" to ");
Serial.println(booleanValue);
}
}
boolean getUrlVariablesFromWifiString( String data ){
Serial.print("Request = ");
Serial.println(data);
if(data.length()>=0){
getEachVariable(data.substring(data.indexOf('?')+1, data.length()));
return true;
}else
return false;
}
// split get Into smaller Chunks ie. ?d12=1&d13=0 into d12=1 and d13=0
String splitVariablesUP( String *str , String strTemp, int strLength ){
String singleVariableAsString;
int startIndex=0;
//finds the first index of &
int endIndex=strTemp.indexOf('&');
// get the variable parts into a string
singleVariableAsString = strTemp.substring( startIndex , endIndex );
//now delete variable from reference string
*str = strTemp.substring( endIndex+1 , strLength );// endIndex +1 is so we loose the & char as we do not need it
return singleVariableAsString;
}
// break down GET sting into each variable + value
void getEachVariable(String strTemp){
// returns variable count
int variableCount = findOutHowManyCharInAString( strTemp , '=');
Serial.print("Variable Count = ");
Serial.println(variableCount);
// loops through each variable
for(int i=0;i<variableCount;i++){
// assigns each variable and value to a string array
runVariableCommand(splitVariablesUP( &strTemp , strTemp , strTemp.length() ));
}
}
//return int value from string
int stringToInt(String thisString) {
int i, value, length;
length = thisString.length();
char blah[(length+1)];
for(i=0; i<length; i++) {
blah[i] = thisString.charAt(i);
}
blah[i]=0;
value = atoi(blah);
return value;
}
//return how many variables are in the GET
int findOutHowManyCharInAString(String str, char findChar){
int positionChar = 0;
int count=0;
while(positionChar != -1){
positionChar = str.indexOf( findChar , positionChar+1 );
if(positionChar!=-1)
count++;
}
return count;
}
// html code
String htmlPage(){
String startHtml = "<!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Transitional//EN' 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd'><html xmlns='http://www.w3.org/1999/xhtml'><head><meta http-equiv='Content-Type' content='text/html;charset=utf-8' /><title>Arduino DigiX Wifi</title>";
String jquery = "\n<script src='http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js'></script>"
"\n<script>\n"
"\n$(function(){"
"\nalert('jquery Loaded');"
"\n$('.relay').click( function(){"
"\najaxCallScript( $(this).attr('pin') + '=' + $(this).attr('val'));"
"\n});"
" \n$('.selector').change(function(){\najaxCallScript( \n$(this).attr('pin') + '=' + $(this).val());"
"\n});"
"\n});"
"\n</script>";
String ajax = "\n<script>\nfunction ajaxCallScript( get ){"
"\nfile = '?' + get;"
"\nif (window.XMLHttpRequest)"
"\n{// code for IE7+, Firefox, Chrome, Opera, Safari"
"\nxmlhttp=new XMLHttpRequest();"
"\n}"
"\nelse"
"\n{// code for IE6, IE5"
"\nxmlhttp=new ActiveXObject('Microsoft.XMLHTTP');"
"\n}"
"\nxmlhttp.onreadystatechange=function(){"
"\nif (xmlhttp.readyState==4 && xmlhttp.status==200){"
"\ndocument.getElementById(elementName).innerHTML = 'done';}"
"\nelse"
"\ndocument.getElementById(elementName).innerHTML = 'Sent';"
"\n}"
"\nxmlhttp.open('GET',file,true);"
"\nxmlhttp.send();"
"\n}\n</script>";
String javascript = "";
String body = "<lable>Digital Pin 4<button class='relay' pin='d4' val='0'>LOW</button><button class='relay' pin='d4' val='1'>HIGH</button></label>"
"<br><lable>Analog Pin 1<select class='selector' pin='a1'><option>0</option><option>50</option><option>100</option><option>150</option><option>200</option><option>255</option></select>";
String endHtml = "\n</body>\n</html>";
return startHtml+jquery+ajax+javascript+body+endHtml;
}
String htmlReturn(){
return "hello";
}