Пример #1
0
void mmData(int value, int decPtPos, int unit) {
	const char mls[]=" fpnumKMGT";
	const char *units[]={"ohm","V","A","F","C","X","H","Hz", "%"};
	int x;
	char buf[12];
	char json[128];
	int p=11;
	int val=value;
	if (val<0) val=-val;
	buf[p--]=0;
	for (x=0; x<10; x++) {
		if (x>decPtPos && val==0) break;
		if (decPtPos==x && x!=0) buf[p--]='.';
		buf[p--]='0'+val%10;
		val/=10;
	}
	if (value<0) buf[p--]='-';
	//Abuse json buffer for normal stuff
	sprintf(json, "%s %c%s%s\n", &buf[p+1], mls[unit>>8], units[unit&127], (unit&MM_U_FL_AC)?" AC":"");
	telnetBcast(json);

	//Populate json buffer
	x=sprintf(json, "{ \"value\": \"%s\", \"ml\": \"%c\", \"unit\": \"%s\", \"acdc\": \"%s\" }",
		&buf[p+1], mls[unit>>8], units[unit&127], (unit&MM_U_FL_AC)?"AC":"DC");
	
	cgiWebsockBroadcast("/mmws.cgi", json, x, WEBSOCK_FLAG_NONE);
}
Пример #2
0
//Broadcast the uptime in seconds every second over connected websockets
static void ICACHE_FLASH_ATTR websockTimerCb(void *arg) {
	static int ctr=0;
	char buff[128];
	ctr++;
	os_sprintf(buff, "Up for %d minutes %d seconds!\n", ctr/60, ctr%60);
	cgiWebsockBroadcast("/websocket/ws.cgi", buff, os_strlen(buff), WEBSOCK_FLAG_NONE);
}
Пример #3
0
//Broadcast the uptime in seconds every second over connected websockets
static void ICACHE_FLASH_ATTR websockTimerCb(void *arg) {
	if (sendBufPos!=0) cgiWebsockBroadcast("/websocket/ws.cgi", sendBuf, sendBufPos, WEBSOCK_FLAG_NONE);
	sendBufPos=0;
}