added mechanism to strip unnecessary backslashes from Home App JSON
Apple "escapes" forward slashes in JSON output, replacing '/' with '\/', which destroys base64 strings.
This commit is contained in:
parent
3d4b02e492
commit
75cbf9715f
|
|
@ -2007,7 +2007,7 @@ StatusCode SpanCharacteristic::loadUpdate(char *val, char *ev, boolean wr){
|
|||
case STRING:
|
||||
case DATA:
|
||||
case TLV_ENC:
|
||||
uvSet(newValue,(const char *)val);
|
||||
uvSet(newValue,(const char *)stripBackslash(val));
|
||||
break;
|
||||
|
||||
default:
|
||||
|
|
|
|||
|
|
@ -73,6 +73,20 @@ char *Utils::readSerial(char *c, int max){
|
|||
|
||||
//////////////////////////////////////
|
||||
|
||||
char *Utils::stripBackslash(char *c){
|
||||
|
||||
size_t n=strlen(c);
|
||||
char *p=c;
|
||||
for(int i=0;i<=n;i++){
|
||||
*p=c[i];
|
||||
if(*p!='\\')
|
||||
p++;
|
||||
}
|
||||
return(c);
|
||||
}
|
||||
|
||||
//////////////////////////////////////
|
||||
|
||||
String Utils::mask(char *c, int n){
|
||||
String s="";
|
||||
int len=strlen(c);
|
||||
|
|
|
|||
|
|
@ -35,7 +35,7 @@ namespace Utils {
|
|||
|
||||
char *readSerial(char *c, int max); // read serial port into 'c' until <newline>, but storing only first 'max' characters (the rest are discarded)
|
||||
String mask(char *c, int n); // simply utility that creates a String from 'c' with all except the first and last 'n' characters replaced by '*'
|
||||
|
||||
char *stripBackslash(char *c); // strips backslashes out of c (Apple unecessesarily "escapes" forward slashes in JSON)
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////
|
||||
|
|
|
|||
|
|
@ -49,7 +49,7 @@ struct HomeSpanTV : Service::Television {
|
|||
|
||||
for(int i=0;i<sizeof(order)/sizeof(uint32_t);i++){
|
||||
if(i>0)
|
||||
orderTLV.add(0);
|
||||
orderTLV.add(6);
|
||||
orderTLV.add(1,sizeof(uint32_t),(uint8_t*)(order+i));
|
||||
}
|
||||
|
||||
|
|
@ -117,6 +117,7 @@ struct HomeSpanTV : Service::Television {
|
|||
HomeSpanTV *hsTV=(HomeSpanTV *)arg;
|
||||
hsTV->tvname->setString("New Name");
|
||||
Serial.printf("Reset TV Name to '%s'\n",hsTV->tvname->getString());
|
||||
Serial.printf("Showing displayOrder '%s'\n",hsTV->displayOrder->getString());
|
||||
}
|
||||
|
||||
static void changeOrder(const char *buf, void *arg){
|
||||
|
|
@ -128,12 +129,12 @@ struct HomeSpanTV : Service::Television {
|
|||
orderTLV.print();
|
||||
orderTLV.wipe();
|
||||
|
||||
uint32_t order[]={12,10,6,2,1,9,11,3,18,5};
|
||||
uint8_t order[]={12,10,6,2,1,9,11,3,18,5};
|
||||
|
||||
for(int i=0;i<sizeof(order)/sizeof(uint32_t);i++){
|
||||
for(int i=0;i<sizeof(order)/sizeof(uint8_t);i++){
|
||||
if(i>0)
|
||||
orderTLV.add(0);
|
||||
orderTLV.add(1,sizeof(uint32_t),(uint8_t*)(order+i));
|
||||
orderTLV.add(1,sizeof(uint8_t),(uint8_t*)(order+i));
|
||||
}
|
||||
|
||||
Serial.printf("AFTER:\n");
|
||||
|
|
|
|||
Loading…
Reference in New Issue