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 8287705
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T12:07:19+00:00 2026-06-08T12:07:19+00:00

I am writing an Android application to communicate with my Arduino over the web.

  • 0

I am writing an Android application to communicate with my Arduino over the web. The Arduino is running a web server through an Ethernet shield. I am attaching my code, but I will explain it here so you will understand what I am trying to do.

The Android sends an HTTP request in the format http://192.168.1.148/?Lights=1. The Arduino gets the request, executes the command (in this case turning on some lights) and then responds to the Android device by simply sending the string “Lights=On”. The Android will then change the color of the button to notify the user that the command was executed successfully.

The Arduino is getting the instruction and executing it and sending the response but my button color is not changing. I know that the Android device is getting the string because I added a debug line to change the text on the button to the received response. The relevant code for the Android device is:

((Button) v).setText(sb.toString()); //This works and the button text changes to "Lights=On".

//Test response and update button
if(sb.toString()=="Lights=On"){
    v.getBackground().setColorFilter(0xFFFFFF00, PorterDuff.Mode.MULTIPLY);
    Drawable d = lightOff.getBackground();
    lightOff.invalidateDrawable(d);
    d.clearColorFilter();
}

The Arduino code is:

 if(s=="Lights"){
     switch(client.read()){
         case '0':
             digitalWrite(LightPin,0);
             client.print("Lights=Off");
             //debug
             Serial.println("Lights=Off");
             break;

         case '1':
             digitalWrite(LightPin,1);
             client.print("Lights=On");
             Serial.println("Lights=On");
             break;
     }
 }

Please let me know if you need more of the code to answer this question.

  • 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-08T12:07:20+00:00Added an answer on June 8, 2026 at 12:07 pm

    To simply change the background color of the button:

                String state = sb.toString().trim();
                ((Button) v).setText(state);
                if(state.contains("On")){
                    v.setBackgroundColor(Color.DKGRAY);
                }
                else
                {
                    v.setBackgroundColor(Color.MAGENTA);                    
                }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am writing an android application, which communicates with server when the user logs
I am currently writing my first Android application and I keep running into references
I am writing an application that communicates using sockets. I have a server running
I am writing an Android application that interfaces with a RESTful service. This web
We are writing an application for Android OS which communicates with a server to
I am writing an android application which uses a REST-based API on the server.
I'm writing an Android application which is targeted to API level 15 but I
I am writing an Android application which can enable and disable the Network Data
I am writing an Android application which uses several 3D models. Such a model
I'm writing an Android application that I want to be able to send requests

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.