¿ªÔÆÌåÓý

ctrl + shift + ? for shortcuts
© 2025 Groups.io

Re: HTML5 development for iPad


 
Edited

Bill Gordon
2:13am ?
Did you ever post a demo project this sounds pretty good . I setup a raspberry pi relaying HTML Java I/O and I would love to see what you have done.
If you are referring to my demo on doing HTML5 on a Raspberry Pi,? yes I did.? See my github page at .? In the documentation, there is a reference to a YouTube video if you prefer to watch instead of read.

There is also a follow up video and using a simple UDP socket to talk to other programs or devices.? In that video I demo about how to use Node JS as a front end web server for a Python program.? .? But in reality, it was base on a program I wrote to do an HTML5 web interface for my Crestron MP2E processor using 15+ year old Crestron software back when Crestron's licensing terms were very simple.? All you need to do is write a very simple SIMPL+ JSON processor connected it to a SIMPL UDP socket to interface to the Raspberry Pi.? Below is the SIMPL+ code I used to do that.

/*
? SIMPL+ Module Information
? (Fill in comments below)

/*
? Compiler Directives
*/

#DEFINE_CONSTANT??? TOTALDIGITALS??? ??? 100
#DEFINE_CONSTANT??? TOTALANALOGS??? ??? 10
#DEFINE_CONSTANT??? TOTALSERIALS??? ??? 10

#DEFINE_CONSTANT Quote "\x22"
#DEFINE_CONSTANT Backslash "\x5C"
#DEFINE_CONSTANT LF "\x0A"
#DEFINE_CONSTANT CR "\x0D"
#DEFINE_CONSTANT Tab "\x09"
#DEFINE_CONSTANT FF "\x0C"
#DEFINE_CONSTANT Backspace "\x08"




//#CATEGORY "0"
#DEFAULT_VOLATILE
// #PRINT_TO_TRACE
// #DIGITAL_EXPAND
// #ANALOG_SERIAL_EXPAND
// #OUTPUT_SHIFT
// #HELP_PDF_FILE ""
// #DEFAULT_NONVOLATILE
#ENABLE_STACK_CHECKING
//#ENABLE_TRACE

#HELP_BEGIN

This program follows the GPL3 License:

??? This program is free software: you can redistribute it and/or modify
??? it under the terms of the GNU General Public License as published by
??? the Free Software Foundation, either version 3 of the License, or
??? (at your option) any later version.

??? This program is distributed in the hope that it will be useful,
??? but WITHOUT ANY WARRANTY; without even the implied warranty of
??? MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.? See the
??? GNU General Public License for more details.

??? You should have received a copy of the GNU General Public License
??? along with this program.? If not, see <https://www.gnu.org/licenses/>.

Summary:

?? This module will only decode single JSON key:value pairs.
?? If will not decode more complicated multiple layer key:value pairs.

?? Module automatically adds/deletes escape sequences to/from JSON strings.

INPUTS:

?? ?Debug??? D??? Enables debug info to be printed to the console.

?? ?Refresh??? D??? Resend all non-zero Digital, Analog, and Serial inputs to
?? ???? ??? ??? the webserver via the JSON_TX$ output.

#HELP_END



????????????????????? ?
DIGITAL_INPUT
?? ?Debug,
?? ?Refresh,
?? ?_SKIP_,
?? ?Dig_In[TOTALDIGITALS];

BUFFER_INPUT
?? ?_SKIP_,
?? ?JSON_RX$[2000];

?? ?
ANALOG_INPUT
?? ?_SKIP_,
?? ?Ana_In[TOTALANALOGS];


?? ?
STRING_INPUT
?? ?_SKIP_,
?? ?Ser_In$[TOTALSERIALS][256];



DIGITAL_OUTPUT
?? ?_SKIP_,
?? ?NewClient,
?? ?_SKIP_,
?? ?DigOut[TOTALDIGITALS];

STRING_OUTPUT
?? ?_SKIP_,
?? ?JSON_TX$;
?? ?
?? ?
ANALOG_OUTPUT
?? ?_SKIP_,
?? ?AnaOut[TOTALANALOGS];
?? ?
STRING_OUTPUT
?? ?_SKIP_,
?? ?SerOut$[TOTALSERIALS];


INTEGER
?? ?LastDigPress,
?? ?Semaphore;

STRING ??? SerialStorage$[TOTALSERIALS][256];


CHANGE JSON_RX$
???? {???
?? ?INTEGER Value, Index;
?? ?STRING JSON_PAIR$[512];
?? ?STRING JSON_KEY$[512];
?? ?STRING JSON_VALUE$[512];
?? ?STRING JSON_TRASH[512];

?????????? ?
??? if(Semaphore = 0)
?? ???? {
?? ???? Semaphore = 1;
?? ???? if (Debug) print("processing\n");
?? ???? while(find("}", JSON_RX$) > 0)
?? ???? ??? {
?? ???? ??? JSON_PAIR$ = remove("}", JSON_RX$);
?? ???? ??? Index = find("{", JSON_PAIR$);
?? ???? ??? if(Index > 0)
?? ???? ??? ??? {
?? ???? ??? ??? JSON_PAIR$ = mid(JSON_PAIR$,Index,len(JSON_PAIR$));
?? ???? ??? ??? if (Debug) print("JSON_PAIR$=%s\n",JSON_PAIR$);
?? ???? ??? ??? JSON_VALUE$ = JSON_PAIR$;

?? ???? ??? ??? // Find JSON Key
?? ???? ??? ??? JSON_KEY$ = remove(":", JSON_VALUE$);??? ??? ??? ???
?? ???? ??? ??? JSON_TRASH = remove(Quote, JSON_KEY$);
?? ???? ??? ??? JSON_KEY$ = remove(Quote, JSON_KEY$);
?? ???? ??? ??? Index = len(JSON_KEY$);
?? ???? ??? ??? if (Index>2) {JSON_KEY$ = left(JSON_KEY$, Index-1);}
?? ???? ??? ??? ??? ??? else {JSON_KEY$ = "";}
?? ???? ??? ??? if (Debug) print("JSON_KEY$=%s\n",JSON_KEY$);

?? ???? ??? ??? // Find JSON VALUE
?? ???? ??? ??? JSON_VALUE$ = left(JSON_VALUE$,len(JSON_VALUE$)-1); // remove trailing }
?? ???? ??? ??? if (Debug) print("JSON_VALUE$=%s\n",JSON_VALUE$);

??????????????? // Digital signal
?? ???? ??? ??? if (left(JSON_KEY$, 1) = "D") // this is a Digital signal
?? ???? ??? ??? ??? {
?? ???? ??? ??? ??? index = atoi(JSON_KEY$);
?? ???? ??? ??? ??? if ((Index) && (Index <= TOTALDIGITALS))
?? ???? ??? ??? ??? ??? {
?? ???? ??? ??? ??? ??? Value = atoi(JSON_VALUE$);
?? ???? ??? ??? ??? ??? switch (Value)
?? ???? ??? ??? ??? ??? ??? {
?? ???? ??? ??? ??? ??? ??? case (0) :
?? ???? ??? ??? ??? ??? ??? ??? {
?? ???? ??? ??? ??? ??? ??? ??? // Test if button is action. If not, release the last button
?? ???? ??? ??? ??? ??? ??? ??? // This is in class some slides off the button while holding it
?? ???? ??? ??? ??? ??? ??? ??? if (DigOut[Index]) DigOut[Index] = 0;
?? ???? ??? ??? ??? ??? ??? ??? else if(LastDigPress) DigOut[LastDigPress] = 0;
???? ??? ??? ??? ??? ??? ??? ??? LastDigPress = 0;
?? ???? ??? ??? ??? ??? ??? ??? }
?? ???? ??? ??? ??? ??? ??? case (1) :
?? ???? ??? ??? ??? ??? ??? ??? {
?? ???? ??? ??? ??? ??? ??? ??? DigOut[Index] = 1;
?? ???? ??? ??? ??? ??? ??? ??? LastDigPress = Index;
?? ???? ??? ??? ??? ??? ??? ??? }
?? ???? ??? ??? ??? ??? ??? case (2) :
?? ???? ??? ??? ??? ??? ??? ??? {
?? ???? ??? ??? ??? ??? ??? ??? DigOut[Index] = 1;
?? ???? ??? ??? ??? ??? ??? ??? processlogic();
?? ???? ??? ??? ??? ??? ??? ??? DigOut[Index] = 0;
?? ???? ??? ??? ??? ??? ??? ??? }
?? ???? ??? ??? ??? ??? ??? }
?? ???? ??? ??? ??? ??? }
?? ???? ??? ??? ??? }

?? ???? ??? ??? // Analog Signal
?? ???? ??? ??? else if (left(JSON_KEY$, 1) = "A") // this is a Analog signal
?? ???? ??? ??? ??? {
?? ???? ??? ??? ??? index = atoi(JSON_KEY$);
?? ???? ??? ??? ??? if ( (Index) && (Index <= TOTALANALOGS) )
?? ???? ??? ??? ??? ??? {
?? ???? ??? ??? ??? ??? Value = atoi(JSON_VALUE$);
?? ???? ??? ??? ??? ??? AnaOut[Index] = atoi(JSON_VALUE$);
?? ???? ??? ??? ??? ??? }
?? ???? ??? ??? ??? }

?? ???? ??? ??? //Serial signal
?? ???? ??? ??? else if (left(JSON_KEY$, 1) = "S") // this is a Serial signal
?? ???? ??? ??? ??? {
?? ???? ??? ??? ??? index = atoi(JSON_KEY$);
?? ???? ??? ??? ??? if ( (Index) && (Index <= TOTALSERIALS) )
?? ???? ??? ??? ??? ??? {
?? ???? ??? ??? ??? ??? JSON_TRASH = remove(Quote, JSON_Value$);
?????????? ?
?? ???? ??? ??? ??? ??? // Convert Backspace escape sequences
?? ???? ??? ??? ??? ??? Value = find("\\b" , JSON_Value$);
?? ???? ??? ??? ??? ??? while (Value)???
?? ???? ??? ??? ??? ??? ??? {
?? ???? ??? ??? ??? ??? ??? JSON_Value$ = left(JSON_Value$,Value-1) + Backspace + right(JSON_Value$, len(JSON_Value$)- (Value+1) );
?? ???? ??? ??? ??? ??? ??? Value = find("\\b", JSON_Value$, Value+2);
?? ???? ??? ??? ??? ??? ??? }

?? ???? ??? ??? ??? ??? // Convert FormFeed escape sequences
?? ???? ??? ??? ??? ??? Value = find("\\f" , JSON_Value$);
?? ???? ??? ??? ??? ??? while (Value)???
?? ???? ??? ??? ??? ??? ??? {
?? ???? ??? ??? ??? ??? ??? JSON_Value$ = left(JSON_Value$,Value-1) + FF + right(JSON_Value$, len(JSON_Value$)- (Value+1) );
?? ???? ??? ??? ??? ??? ??? Value = find("\\f", JSON_Value$, Value+2);
?? ???? ??? ??? ??? ??? ??? }
??????????????????????? ?
?? ???? ??? ??? ??? ??? // Convert LineFeed escape sequences
?? ???? ??? ??? ??? ??? Value = find("\\n" , JSON_Value$);
?? ???? ??? ??? ??? ??? while (Value)???
?? ???? ??? ??? ??? ??? ??? {
?? ???? ??? ??? ??? ??? ??? JSON_Value$ = left(JSON_Value$,Value-1) + LF + right(JSON_Value$, len(JSON_Value$)- (Value+1) );
?? ???? ??? ??? ??? ??? ??? Value = find("\\n", JSON_Value$, Value+2);
?? ???? ??? ??? ??? ??? ??? }

?? ???? ??? ??? ??? ??? // Convert Carriage Return escape sequences
?? ???? ??? ??? ??? ??? Value = find("\\r" , JSON_Value$);
?? ???? ??? ??? ??? ??? while (Value)???
?? ???? ??? ??? ??? ??? ??? {
?? ???? ??? ??? ??? ??? ??? JSON_Value$ = left(JSON_Value$,Value-1) + CR + right(JSON_Value$, len(JSON_Value$)-(Value+1) );
?? ???? ??? ??? ??? ??? ??? Value = find("\\r", JSON_Value$, Value+2);
?? ???? ??? ??? ??? ??? ??? }

?????????????????????? ?
?? ???? ??? ??? ??? ??? // Convert Tab escape sequences
?? ???? ??? ??? ??? ??? Value = find("\\t" , JSON_Value$);
?? ???? ??? ??? ??? ??? while (Value)???
?? ???? ??? ??? ??? ??? ??? {
?? ???? ??? ??? ??? ??? ??? JSON_Value$ = left(JSON_Value$,Value-1) + Tab + right(JSON_Value$, len(JSON_Value$)- (Value+1) );
?? ???? ??? ??? ??? ??? ??? Value = find("\\t", JSON_Value$, Value+2);
?? ???? ??? ??? ??? ??? ??? }


?? ???? ??? ??? ??? ??? // Convert Quote escape sequences to quote
?? ???? ??? ??? ??? ??? Value = find("\x5C22" , JSON_Value$);
?? ???? ??? ??? ??? ??? while (Value)???
?? ???? ??? ??? ??? ??? ??? {
?? ???? ??? ??? ??? ??? ??? JSON_Value$ = left(JSON_Value$,Value-1) + right(JSON_Value$, len(JSON_Value$)- Value);
?? ???? ??? ??? ??? ??? ??? Value = find("\x5C22", JSON_Value$, Value+2);
?? ???? ??? ??? ??? ??? ??? }

? ??? ??? ??? ??? ??? ??? // Convert Backslash escape sequences to Backslash
?? ???? ??? ??? ??? ??? Value = find("\x5C5C" , JSON_Value$);
?? ???? ??? ??? ??? ??? while (Value)???
?? ???? ??? ??? ??? ??? ??? {
?? ???? ??? ??? ??? ??? ??? JSON_Value$ = left(JSON_Value$,Value-1) + right(JSON_Value$, len(JSON_Value$)- Value);
?? ???? ??? ??? ??? ??? ??? Value = find("\x5C5C", JSON_Value$, Value+2);
?? ???? ??? ??? ??? ??? ??? }


?? ???? ??? ??? ??? ??? // find end of line
?? ???? ??? ??? ??? ??? Value = 0;
?? ???? ??? ??? ??? ??? while (find(Quote, JSON_Value$, Value))
?? ???? ??? ??? ??? ??? ??? {
?? ???? ??? ??? ??? ??? ??? Value = find(Quote, JSON_Value$, Value);
?? ???? ??? ??? ??? ??? ??? }
?? ???? ??? ??? ??? ??? // Removed trailing quote
?? ???? ??? ??? ??? ??? if (Value) JSON_Value$ = left(JSON_Value$, Value-1);
?? ???? ??? ??? ??? ??? if (len(JSON_Value$) > 2)
?? ???? ??? ??? ??? ??? ??? {
?? ???? ??? ??? ??? ??? ??? JSON_Value$ = left(JSON_Value$, len(JSON_Value$)-1);
?? ???? ??? ??? ??? ??? ??? SerOut$[Index] = JSON_VALUE$;
?? ???? ??? ??? ??? ??? ??? }
?? ???? ??? ??? ??? ???

?? ???? ??? ??? ??? ??? }
?? ???? ??? ??? ??? }



?? ???? ??? ??? else if (left(JSON_KEY$, 1) = "") // this is a null signal
?? ???? ??? ??? ??? {
?? ???? ??? ??? ??? // Release occurred over a non button area of screen.? Release previously pressed button
?? ???? ??? ??? ??? // in case this is the result of finger sliding off of button.
?? ???? ??? ??? ??? if ((LastDigPress) && (atoi(JSON_VALUE$) = 0) )
?? ???? ??? ??? ??? ??? {
?? ???? ??? ??? ??? ??? DigOut[LastDigPress] = 0;
?? ???? ??? ??? ??? ??? LastDigPress = 0;
?? ???? ??? ??? ??? ??? }

?? ???? ??? ??? ??? }

?? ???? ??? ??? else if (find("NewClient",JSON_KEY$)) // A newClient
?? ???? ??? ??? ??? {
?? ???? ??? ??? ??? NewClient = 1;
?? ???? ??? ??? ??? processlogic();
?? ???? ??? ??? ??? NewClient = 0;
?? ???? ??? ??? ??? }

?? ???? ??? ??? else if ((LastDigPress) && (JSON_VALUE$ = "0") )
?? ???? ??? ??? ??? {
?? ???? ??? ??? ??? // Release occurred over a non button area of screen.? Release previously pressed button
?? ???? ??? ??? ??? // in case this is the result of finger sliding off of button.
?? ???? ??? ??? ??? DigOut[LastDigPress] = 0;
?? ???? ??? ??? ??? LastDigPress = 0;
?? ???? ??? ??? ??? }
?????????????? }
?? ???? ??? processlogic();
?? ???? ??? } // End of while(find("}", JSON_RX$) > 0)
?? ???? Semaphore = 0;
?? ???? print("end process\n");
?? ????
?? ???? }? // End of if(Semaphore = 0)
?? ?} // End of CHANGE JSON_RX$

PUSH Refresh
?? ?{
?? ?INTEGER
?? ???? Value,
?? ???? Index;
?? ?STRING TempStr$[255];

?? ?for (Index = 1 to TOTALDIGITALS)
?? ???? {
?? ???? if (Dig_In[Index])
?? ???? if ( (IsSignalDefined(Dig_In[Index])) && (Dig_In[Index]) )
?? ???? ??? {
?? ???? ??? makestring(TempStr$,"%sD%u%s:1",Quote,Index,Quote);
?? ???? ??? TempStr$ = "{" + TempStr$ + "}"; // workaround for Series3 compiler problem with braces.
?? ???? ??? JSON_TX$ = TempStr$;
?? ???? ??? processlogic();
?? ???? ??? }
?? ???? }
?? ?for (Index = 1 to TOTALANALOGS)
?? ???? {
?? ???? if ( (IsSignalDefined(Ana_In[Index])) && (Ana_In[Index]) )
?? ???? ??? {
?? ???? ??? Value = Ana_In[Index];
?? ???? ??? makestring(TempStr$,"%sA%u%s:%u",Quote,Index,Quote,Value);
?? ???? ??? TempStr$ = "{" + TempStr$ + "}"; // workaround for Series3 compiler problem with braces.
?? ???? ??? JSON_TX$ = TempStr$;
?? ???? ??? processlogic();
?? ???? ??? }
?? ???? }

?? ?for (Index = 1 to TOTALSERIALS)
?? ???? {
?? ???? if ( (IsSignalDefined(Ser_In$[Index])) && (len(Ser_In$[Index]) )? )
?? ???? ??? {
?? ???? ??? JSON_TX$ = SerialStorage$[Index];
?? ???? ??? processlogic();
?? ???? ??? }
?? ???? }
?? ?}

CHANGE Dig_In??? ??? {
?? ?INTEGER Index;
?? ?STRING TempStr$[255];
?? ?
?? ?Index = getlastmodifiedarrayindex();
?? ?if (Dig_In[Index])
?? ???? {
?? ???? makestring(TempStr$,"%sD%u%s:1",Quote,Index,Quote);
?? ???? }
?? ?else
?? ???? {
?? ???? makestring(TempStr$,"%sD%u%s:0",Quote,Index,Quote);
?? ???? }
?? ?TempStr$ = "{" + TempStr$ + "}"; // workaround for Series3 compiler problem with braces.
?? ?if (Debug) print("Sending JSON:%s\n",TempStr$);
?? ?JSON_TX$ = TempStr$;
?? ?processlogic();
?? ?}
?? ?
CHANGE Ana_In
?? ?{
?? ?INTEGER
?? ???? Value,
?? ???? Index;
?? ?STRING TempStr$[255];???

?? ?Index = getlastmodifiedarrayindex();
?? ?Value = Ana_In[Index];
?? ?makestring(TempStr$,"%sA%u%s:%u",Quote,Index,Quote,Value);
?? ?TempStr$ = "{" + TempStr$ + "}"; // workaround for Series3 compiler problem with braces.
?? ?if (Debug) print("Sending JSON:%s\n",TempStr$);
?? ?JSON_TX$ = TempStr$;

?? ?}

?? ?
CHANGE Ser_In$
?? ?{
?? ?INTEGER
?? ???? Value,
?? ???? Index;
?? ?STRING TempStr$[255];???

?? ?
?? ?Index = getlastmodifiedarrayindex();
?? ?TempStr$ = Ser_In$[Index];

?? ?// Replaced backslash with \\
?? ?Value = find(Backslash ,TempStr$);
?? ?while (Value)
?? ???? {
?? ???? TempStr$ = left(TempStr$,Value-1) + Backslash + right(TempStr$, len(TempStr$) - (Value-1) );
?? ???? Value = find(Quote,TempStr$, Value+2);
?? ???? }
?
?? ?// Replaced Quote with \"
?? ?Value = find(Quote,TempStr$);
?? ?while (Value)
?? ???? {
?? ???? TempStr$ = left(TempStr$,Value-1) + Backslash + right(TempStr$, len(TempStr$) - (Value-1) );
?? ???? Value = find(Quote,TempStr$, Value+2);
?? ???? }

??? // Replaced LineFeed with \n"
?? ?Value = find(LF,TempStr$);
?? ?while (Value)
?? ???? {
?? ???? TempStr$ = left(TempStr$,Value-1) + "\\n" + right(TempStr$, len(TempStr$) - (Value) );
?? ???? Value = find(LF,TempStr$, Value+2);
?? ???? }
? ?
?? ?// Replaced Carrage Return with \r"
?? ?Value = find(CR,TempStr$);
?? ?while (Value)
?? ???? {
?? ???? TempStr$ = left(TempStr$,Value-1) + "\\r" + right(TempStr$, len(TempStr$) - (Value) );
?? ???? Value = find(CR,TempStr$, Value+2);
?? ???? }
?? ?
?? ?// Replaced Tab with \t"
?? ?Value = find(Tab,TempStr$);
?? ?while (Value)
?? ???? {
?? ???? TempStr$ = left(TempStr$,Value-1) + "\\t" + right(TempStr$, len(TempStr$) - (Value) );
?? ???? Value = find(Tab,TempStr$, Value+2);
?? ???? }
?? ?
?? ?// Replaced FormFeed with \f"
?? ?Value = find(FF,TempStr$);
?? ?while (Value)
?? ???? {
?? ???? TempStr$ = left(TempStr$,Value-1) + "\\f" + right(TempStr$, len(TempStr$) - (Value) );
?? ???? Value = find(FF,TempStr$, Value+2);
?? ???? }

?? ?makestring(TempStr$,"%sS%u%s:%s%s%s",Quote,Index,Quote,Quote,TempStr$,Quote);
?? ?TempStr$ = "{" + TempStr$ + "}"; // workaround for Series3 compiler problem with braces.
?? ?if (Debug) print("Sending JSON:%s\n",TempStr$);
?? ?JSON_TX$ = TempStr$;
?? ?SerialStorage$[Index] = TempStr$;

?? ?}
?? ?
FUNCTION Main()
?? ?{
?? ?INTEGER Index;

?? ?Semaphore = 0;

?? ?for (Index = 1 to TOTALSERIALS)
?? ???? {
?? ???? SerialStorage$[Index] =??? "";
?? ???? }

?? ?if ( WaitForInitializationComplete() < 0 )
??????? {
??????? print("Webserver_JSON_Processor: Error waiting for initialization complete\n");
??????? return;
??????? }

?? ????
?? ?}










Join [email protected] to automatically receive all group messages.