Пример #1
0
void sendUpdate(){
	StaticJsonBuffer<300> sendJsonBuffer;
    JsonObject &json = sendJsonBuffer.createObject();
    json["type"] = "state";
    json["count"] = totalActiveSockets;
	json["time"] = SystemClock.now().toUnixTime();;
	json["mute"] = mute;
	json["source"] = source;
	json["mixing"] = mixing;
	json["enhance"] = enhance;
	json["volumeFR"] = 74-volumeFR;
	json["volumeFL"] = 74-volumeFL;	
	json["volumeRR"] = 74-volumeRR;
	json["volumeRL"] = 74-volumeRL;
	json["volumeCEN"] = 74-volumeCEN;
	json["volumeSW"] = 74-volumeSW;
	json["frequency"] = frequency;
	json["volumeALLCH"] = 74-volumeALLCH;
	json["power"] = power;


	String jsonString;
	json.printTo(jsonString);

	WebSocketsList &clients = server.getActiveWebSockets();
	for (int i = 0; i < clients.count(); i++){
		clients[i].sendString(jsonString);
	}

}
Пример #2
0
void wsDisconnected(WebSocket& socket) {
	totalActiveSockets--;

	// Notify everybody about lost connection
	WebSocketsList &clients = server.getActiveWebSockets();
	for (int i = 0; i < clients.count(); i++)
		clients[i].sendString("We lost our friend :( Total: " + String(totalActiveSockets));
}
Пример #3
0
void wsConnected(WebSocket& socket)
{
	totalActiveSockets++;

	// Notify everybody about new connection
	WebSocketsList &clients = server.getActiveWebSockets();
	for (int i = 0; i < clients.count(); i++)
		clients[i].sendString("New friend arrived! Total: " + String(totalActiveSockets));
}
Пример #4
0
void readPeriodically()
{
	Wire.beginTransmission(0x48);   //talking to chip
	Wire.write(byte(0x00));   //status register address
	Wire.endTransmission();
	Wire.requestFrom(0x48, 1);   //request status register data
	int readycap;
	//Serial.println(" Trying read...");   //try read
	readycap = Wire.read();
	if ((readycap & 0x1) == 0)
	{                // ready?
		//Serial.print(system_get_time());
		//Serial.println(" Data Ready");
		//delay(10);
		Wire.beginTransmission(0x48);    //arduino asks for data from ad7747
		Wire.write(0x01);   		     //set address point to capacitive DAC register 1
		Wire.endTransmission();          //pointer is set so now we can read the

		//Serial.print(system_get_time());
		//Serial.println(" Data Incoming");
		//delay(10);
		Wire.requestFrom(0x48, 3,false);   //reads data from cap DAC registers 1-3
		while (Wire.available())
		{
			//Serial.print(system_get_time());
			//Serial.println("  Wire available.");
			unsigned char hi, mid, lo;      //1 byte numbers
			long capacitance;      //will be a 3byte number
			hi = Wire.read();
			//delay(3);
			mid = Wire.read();
			//delay(3);
			lo = Wire.read();
			capacitance = (hi << 16) + (mid << 8) + lo - 0x800000;
			pf = (float) capacitance * -1 / (float) 0x800000 * 8.192f;
			//Serial.print(system_get_time());
			//Serial.print(" ");
			//Serial.println(pf, DEC); //prints the capacitance data in decimal through serial port
		}
		//Serial.println();
	}

	system_soft_wdt_feed();
	char buf[22];
	dtostrf(pf, 10, 8, buf);
	WebSocketsList &clients = server.getActiveWebSockets();
	for (int i = 0; i < clients.count(); i++)
	{
		clients[i].sendString(buf);
	}	
	
	procTimer.initializeMs(150, readPeriodically).startOnce();

}
Пример #5
0
void reportEncoderPosition() {
	char buf[60];
	char buf1[12];

	floatEncoder = encoder0Pos * (2.4 / 160.0);
	dtostrf(floatEncoder, 4, 2, buf1);
	sprintf(buf, "Encoder: %s", deblank(buf1));
	String message1 = String(buf);

	if (!message1.equals(lastPositionMessage)) {
		WebSocketsList &clients = server.getActiveWebSockets();
		for (int i = 0; i < clients.count(); i++) {
			clients[i].sendString(message1);
		}
	}

	//printf(" * zmtp_msg: ");
	//zmtp_msg_t *msg = zmtp_msg_from_const_data(0, "hello", 6);
	//zmtp_msg_destroy(&msg);

	//zmtp_msg_test (false);
	//zmtp_channel_test (false);

	/*


	 pb::Container container, got;


	 pb::Pin *pin;
	 pb::Value *value;

	 // type-tag the container:
	 container.set_type(pb::ContainerType::MT_HALUPDATE);
	 container.set_serial(56789);
	 container.set_rsvp(pb::ReplyType::NONE);


	 // add repeated submessage(s)
	 pin = container.add_pin();
	 pin->set_type(pb::ValueType::HAL_S32);
	 pin->set_name("foo.1.bar");
	 pin->set_hals32(4711);

	 value = container.add_value();
	 value->set_type(pb::ValueType::DOUBLE);
	 value->set_v_double(3.14159);

	 //std::string json = pb2json(container);
	 */

}
Пример #6
0
void wsMessageReceived(WebSocket& socket, const String& message)
{
	WebSocketsList &clients = server.getActiveWebSockets();

    StaticJsonBuffer<200> jsonBuffer;
    JsonObject& root = jsonBuffer.parseObject(message);
    String actionName  = root["name"].asString();
 
    if(actionName=="enhance"){
    	setEnhance(!enhance);
    }else if(actionName=="power"){
    	setPower(!power);
    }else if(actionName=="mute"){
    	setMmute(!mute);
    }else if(actionName=="mixing"){
    	setMixing(!mixing);
    }else if(actionName=="frequency"){
		setFrequency(root["val"]);
    }else if(actionName=="source"){
		setSource(root["val"]);
    }else if (actionName == "volumeFR") {
        setVolume(CHAN_FR, root["val"]);
    } else if (actionName == "volumeFL") {
        setVolume(CHAN_FL, root["val"]);
    } else if (actionName == "volumeRR") {
        setVolume(CHAN_RR, root["val"]);
    } else if (actionName == "volumeRL") {
        setVolume(CHAN_RL, root["val"]);
    } else if (actionName == "volumeCEN") {
        setVolume(CHAN_CEN, root["val"]);
    } else if (actionName == "volumeSW") {
        setVolume(CHAN_SW, root["val"]);
    } else if (actionName == "volumeALLCH") {
        setVolume(CHAN_ALL, root["val"]);
    } else if (actionName == "volumeSW") {
        setVolume(CHAN_SW, root["val"]);
    } else if (actionName == "lcdText") {
        setLcd(root["line"], root["val"]);
    }





	sendUpdate();
	Serial.printf("WebSocket message received:\r\n%s\r\n", actionName);
}
Пример #7
0
void wsConnected(WebSocket& socket) {
	totalActiveSockets++;
	lastPositionMessage = "";
	// Notify everybody about new connection

	uint8 slotNo = rboot_get_current_rom();
	String slotNoStr = String(slotNo);

	uint32 heapSize = system_get_free_heap_size();
	String heapSizeStr = String(heapSize);

	WebSocketsList &clients = server.getActiveWebSockets();
	for (int i = 0; i < clients.count(); i++) {
		clients[i].sendString(
				"Connected to station: " + wifi_sid.get(currWifiIndex) + ", ROM:" + slotNoStr + ", heapSize: "
						+ heapSizeStr + ", appVer:1.22, SDK version: " + system_get_sdk_version());
	}

}
Пример #8
0
void reportAnalogue() {
	char buf[60];
	char buf1[10];
	char data[4];

	/*
	 1 ... BROWN        ... 12V ... 24V +
	 2 ... WHITE        ... RXD
	 3 ... BLUE         ... GND
	 4...  BLACK        ... not used
	 5...  YELOW/GREEN  ... TXD
	 */

	floatAnalog = atof(analogResult.c_str()) / 10.0;
	dtostrf(floatAnalog, 7, 4, buf1);
	sprintf(buf, "Analogue: %s", deblank(buf1));
	String message = String(buf);

	if (!message.equals(lastPositionMessage)) {
		WebSocketsList &clients = server.getActiveWebSockets();
		for (int i = 0; i < clients.count(); i++) {
			clients[i].sendString(message);
		}
		lastPositionMessage = message;

		/*
		union u
		{
		    float f;
		    char s[sizeof(float)];
		};

		union u foo;
		foo.f = floatAnalog;
*/
		//udp.sendStringTo(IPAddress("192.168.1.19"), (uint16_t)1234, foo.s);
		udp.sendStringTo(IPAddress(udpServerIP), udpServerPort, analogResult);

		//Serial.printf("Analogue: %f", analogResult.c_str());
	}
}
Пример #9
0
void sendToClients(String message) {
	WebSocketsList &clients = server.getActiveWebSockets();
	for (int i = 0; i < clients.count(); i++) {
		clients[i].sendString(message);
	}
}
Пример #10
0
void readFromLTC2400() {
	float volt;
	float v_ref = 4.096; // Reference Voltage, 5.0 Volt for LT1021 or 3.0 for LP2950-3, 4.096Vs for REF3040
	long int ltw = 0;         // ADC Data ling int
	BYTE sig;                 // sign bit flag
	BYTE b0;                  //
	char buf1[10];
	char buf[60];

	digitalWrite(PIN_SS, 0);
	delayMicroseconds(1);
	if (digitalRead(PIN_DO) == 0) {   // ADC Converter ready ?

		ltw = 0;
		sig = 0;

		b0 = Ltc2400Spi->transfer(1);      // read 4 bytes adc raw data with SPI
		if ((b0 & 0x20) == 0)
			sig = 1;  // is input negative ?
		b0 &= 0x1F;                   // discard bit 25..31
		ltw |= b0;
		ltw <<= 8;
		b0 = Ltc2400Spi->transfer(1);
		ltw |= b0;
		ltw <<= 8;
		b0 = Ltc2400Spi->transfer(1);
		ltw |= b0;
		ltw <<= 8;
		b0 = Ltc2400Spi->transfer(1);
		ltw |= b0;

		delayMicroseconds(1);

		digitalWrite(PIN_SS, HIGH);      // LTC2400 CS HIGH
		delay(200);

		if (sig)
			ltw |= 0xf0000000;    // if input negative insert sign bit
		ltw = ltw / 16;   // scale result down , last 4 bits have no information
		volt = ltw * v_ref / 16777216; // max scale

		//Serial.printf("%d",cnt++);
		//Serial.printf(";  ");
		dtostrf(volt, 6, 6, buf1);
		//Serial.printf("%s",buf1);           // print voltage as floating number
		//Serial.println("  ");

		sprintf(buf, "Analogue: %s", buf1);
		String message = String(buf);

		if (!message.equals(lastPositionMessage)) {
			WebSocketsList &clients = server.getActiveWebSockets();
			for (int i = 0; i < clients.count(); i++) {
				clients[i].sendString(message);
			}
			lastPositionMessage = message;
		}

	}
	digitalWrite(PIN_SS, HIGH); // LTC2400 CS hi
	delay(5);
	reportTimer.startOnce();
}