Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8206267
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T08:36:41+00:00 2026-06-07T08:36:41+00:00

How can I turn on or turn off a switch using Android and a

  • 0

How can I turn on or turn off a switch using Android and a Wi-Fi connection?

I have used SparkFuns IOIO to control relays. But how do I do it wirelessly?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T08:36:43+00:00Added an answer on June 7, 2026 at 8:36 am

    I have a project just like this. Mine is sending position data for a steering system, but the idea is the same. I’ll finish uploading it to Google Code soon. You can check it out at PowerWheelino.

    The basic structure is this:

    1. Touch event on Android sends data (over UDP) to the server.
    2. The UDP server (WRT54G router in this case) receives the data and forwards it over serial to the Arduino.
    3. The Arduino decides what to do with the data from the serial connection.

    Keep in mind that the Arduino automatically resets when receiving data over serial (outside of the IDE Serial interface). See my post here on this topic and ways to get around it. Knowing this previously would have saved me a lot of troubleshooting.

    Disclaimer:

    This code requires some minor modification to accomplish what was requested by the OP. Since you’ve already made a working Android program with IOIO and an Arduino sketch, I assume this is within your abilities.

    Here’s the Android UDP client code:

    Execute UdpClient::sendData() on touch event or button press.

    import java.net.DatagramPacket;
    import java.net.DatagramSocket;
    import java.net.InetAddress;
    
    import android.util.Log;
    
    public class UdpClient {
        String messageStr;
        DatagramSocket s;;
        int server_port;
        InetAddress local;
        int msg_length;
        byte[] message;
    
        public UdpClient (String ipAddress, int port){
            server_port = port;
            try {
                local = InetAddress.getByName(ipAddress);
                s = new DatagramSocket();
            }
            catch (Exception e) {
                e.printStackTrace();
                Log.d("Powerwheelino",e.getStackTrace() + "error");
            }
        }
    
        public boolean sendData(byte drive, byte steering){
            byte drvByte = (byte) (drive & 0xFF);
            byte steerByte = (byte) (steering & 0xFF);
            message = new byte[2];
            message[0] = drvByte;
            message[1] = steerByte;
            msg_length = message.length;
            //message = messageStr.getBytes();
            try {
                DatagramPacket p = new DatagramPacket(message, msg_length,local,server_port);
                s.send(p);
            }
            catch (Exception e) {
                // TODO Auto-generated catch block
                Log.d("Powerwheelino", e.getStackTrace() +"ERROR ");
                e.printStackTrace();
                return false;
            }
            return true;
        }
    }
    

    Here’s the listening UDP server (C++) code

    #include <sys/types.h>
    #include <sys/socket.h>
    #include <netinet/in.h>
    #include <arpa/inet.h>
    #include <stdio.h>
    #include <unistd.h>
    #include <errno.h>
    #include <string.h>
    #include <stdlib.h>
    #include <string>
    #include <SerialStream.h>
    
    using namespace std;
    
    class udp_server {
        int sock;
        int bytes_read;
        socklen_t addr_len;
    
        struct sockaddr_in server_addr , client_addr;
    
        public:
            udp_server(int portNum)
            {
                if ((sock = socket(AF_INET, SOCK_DGRAM, 0)) == -1) {
                    perror("Socket");
                    exit(1);
                }
    
                server_addr.sin_family = AF_INET;
                server_addr.sin_port = htons(portNum);
                server_addr.sin_addr.s_addr = INADDR_ANY;
                bzero(&(server_addr.sin_zero),8);
    
    
                if (bind(sock,(struct sockaddr *)&server_addr,
                    sizeof(struct sockaddr)) == -1)
                {
                    perror("Bind");
                    exit(1);
                }
    
                addr_len = sizeof(struct sockaddr);
    
                printf("\nUDPServer Waiting for client on port %d", portNum);
                    fflush(stdout);
            }
    
            int listen(char recv_data[]) {
                while (1)
                {
                    bytes_read = recvfrom(
                                     sock,
                                     recv_data,
                                     1024,
                                     0,
                                     (struct sockaddr *)&client_addr,
                                     &addr_len
                                 );
    
                    recv_data[bytes_read] = '\0';
                    printf("\n(%s , %d) said : ",inet_ntoa(client_addr.sin_addr),
                                                 ntohs(client_addr.sin_port));
                    printf("%s", recv_data);
                    string drive;
                    string direction;
                    int speed, angle;
    
                    if ((recv_data[0] & 128) > 0) {
                        drive = "Fwd";
                    }
                    else {
                        drive = "Rev";
                    }
                    if ((recv_data[1] & 128) > 0) {
                        direction = "Left";
                    }
                    else {
                        direction = "Right";
                    }
                    speed = recv_data[0] & 127;
                    angle = recv_data[1] & 127;
                    printf("\t %s @ %d and %s @ %d",
                            drive.c_str(),
                            speed,
                            direction.c_str(),
                            angle);
                    fflush(stdout);
                }
                return 0;
            }
    };
    

    Here’s a snippet of the serial communication to the Arduino using LibSerial:

    LibSerial::SerialStream myss;
    SerialComm(int argc, char** argv) {
        myss = new LibSerial::SerialStream("/dev/ttyS0", ios_base::out);
        myss.SetBaudRate(LibSerial::SerialStreamBuf::BAUD_57600);
        myss.SetCharSize(LibSerial::SerialStreamBuf::CHAR_SIZE_8);
        myss.SetFlowControl(LibSerial::SerialStreamBuf::FLOW_CONTROL_NONE);
        myss.SetParity(LibSerial::SerialStreamBuf::PARITY_NONE);
        myss.SetNumOfStopBits(1);
    
        const int Dsize = 2;
        char buffer[1];
        buffer[0] = 125; //0b00000001;
        buffer[1] = '\0';
        bitset(buffer[0]);
        //myss << buffer;
        myss.write(buffer,1);
        //myss.Close();
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

When using NUnit, I can turn off shadow copy so that my test assemblies
So I know I can turn warnings into errors using -Werror=... but I want
For normal input elements you can turn off the spell checking by using a
I'm developing an application that can turn off the sound of Android Phone automatically.
How can I switch between cudaFuncCachePreferShared/cudaFuncCachePreferL1 for Thrust algorithms, an example turn off for
Does anyone know how you can turn off autocompletion on a textfield in Django?
how can one turn off the error messages of a bash script? I want
How can I turn off JavaScript shortening in A4J? I remember there was an
Can anyone tell me, if in PostSharp, I somehow can turn on/off tracing in
How can I turn this behavoir off? It happens when you enter a close

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.