Maintaining communication between Arduino and Java program

微笑、不失礼 提交于 2019-11-29 08:24:32

I solved it, i made it so that the Arduino sends data to the Java program every 15 seconds. All it took was some lines on the Arduino program:

Variables:

long lastSendt;

Loop function:

void loop(){

    if(client){

        if(millis() >= (lastSendt + 15000)){
            sendCharacter('*')
        }

        if(client.available()){

            char c = client.read();

            if(c != '\n'){
                message += c;
            }
            else{
                Serial.println("Received message: "+message);
                checkMessage();
                sendMessage(message);
                message = "";
            }
        }
    }
}

sendCharacter function:

void sendCharacter(char toSend){

    if(client){
        client.println(toSend){
        lastSendt = millis();
    }else{
        Serial.println("Could not send character!");
    }
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!