processing.net.* transformation to android

edited March 28 in Android Mode

Hello everybody,

I have made a program with java that includes processing.net.* libary. When I wanted to transform this program to arduino it says that the libary is not available in andorid so the program doesn't work. I wonder if there are any libary compatible like processing.net.* or something that allow me to do this prorgam:

`

import processing.net.*;

Client myClient; //Definir variables String incomingMessage; int dato; int valin=0; int xin=0; int x=1; void setup() { size(1000,400); background(255);
// Connect to the local machine at port 5204. // This example will not run if you haven't // previously started a server on this port. myClient = new Client(this, "192.168.1.1", 81); myClient.write("start now"); } void newstart(){ size(1000,400); background(255); }

void draw() { // Recibir el mensaje incomingMessage = myClient.readStringUntil('\n'); //Eliminar los espazcios blancos if (incomingMessage!=null){ incomingMessage = incomingMessage.trim(); //Cambio de variable int dato = Integer.parseInt(incomingMessage); println(dato); // Guardar la variable

  //Graficar los datos
  dato=399 - dato/10;
  line(xin, valin, x, dato);  //Forma una linea del punto anterior al nuevo punto
  valin=dato;                 //Definición de la nueva y inicial
  //Si los datos son más grandes que la ventana, restart      
  if (x>=1000){
    newstart();
    xin=0;
    x=1;

  }else{
  xin=x;                     // Definición de la nueva x inicial
  x++;       
  dato=dato+1;
    }

} }

`

The programe is a client which sends a messatge to an arduino launchpad (server) and the launchpad starts sending a voltage value every second.

Thank you for your help!!!

Answers

  • @henrykman3===

    try with OSCP5 lib.

  • Please edit your post, select your code and hit ctrl+o to format your code. Make sure there is an empty line above and below your code

    Also do not create duplicate posts. If they are the same topic, keep it under the same post.

    It is completely normal for a library to work in one platform or application and not in others. You have to find the library that receives your message in your arduino and a library that send messages in your Android. However, this is not enough. You have to understand how the data is sent to be able to receive them and process them correctly. For example, if you send data via oscP5, you can read oscP5 packages if you use the same library. But if you use another TCP/IP library, you will need to write your own code to unpacked the data. Notice oscP5 could work for your application but you need to modify your server side, in your case your Arduino code based on what you described it in your post. Notice oscP5 is only one option. You could also use any of the other library documented on the web for Android devices.

    As a suggestion, oscP5 is good but then you need to understand how the data is packed. Maybe post a sample code on your arduino side. This will help understand better about the resources that you are using and how you are using/processing your data.

    Kf

  • This was my java code in processing that works perfectly. I send a string value with my cc3200 launchpad (Texas) and this data is recived by my computer and drawed in a graphic.

    import processing.net.*;
    
    Client myClient; 
    //Definir variables
    String incomingMessage;
    int dato;
    int valin=0;
    int xin=0;
    int x=1;
    void setup() {
      size(1000,400);
      background(255);  
       // Connect to the local machine at port 5204.
      // This example will not run if you haven't
      // previously started a server on this port.
      myClient = new Client(this, "192.168.1.1", 81); 
       myClient.write("start now");
    } 
    void newstart(){
      size(1000,400);
     background(255); 
    }
    
    void draw() { 
       // Recibir el mensaje
        incomingMessage = myClient.readStringUntil('\n'); 
        //Eliminar los espazcios blancos
        if (incomingMessage!=null){
        incomingMessage = incomingMessage.trim();
        //Cambio de variable
      int dato = Integer.parseInt(incomingMessage);
          println(dato);  // Guardar la variable
    
          //Graficar los datos
          dato=399 - dato/10;
          line(xin, valin, x, dato);  //Forma una linea del punto anterior al nuevo punto
          valin=dato;                 //Definición de la nueva y inicial
          //Si los datos son más grandes que la ventana, restart      
          if (x>=1000){
            newstart();
            xin=0;
            x=1;
    
          }else{
          xin=x;                     // Definición de la nueva x inicial
          x++;       
          dato=dato+1;
            }
    }
    }
    

    On the other side we have the launchpad code:

    // Core library for code-sense - IDE-based
    #include "Energia.h"
    
    
    // Include application, user and local libraries
    
    #ifndef __CC3200R1M1RGC__
    #include <SPI.h>                // Do not include SPI for CC3200 LaunchPad
    #endif
    #include <WiFi.h>
    
    
    // Define structures and classes
    
    
    // Define variables and constants
    char wifi_name[] = "energia";
    char wifi_password[] = "launchpad";
    
    WiFiServer myServer(12000);
    uint8_t oldCountClients = 0;
    uint8_t countClients = 0;
    
    
    // Add setup code
    void setup()
    {
        Serial.begin(115200);
        delay(500);
    
        Serial.println("*** LaunchPad CC3200 WiFi Web-Server in AP Mode");
    
        // Start WiFi and create a network with wifi_name as the network name
        // with wifi_password as the password.
        Serial.print("Starting AP... ");
        WiFi.beginNetwork(wifi_name, wifi_password);
        while (WiFi.localIP() == INADDR_NONE)
        {
            // print dots while we wait for the AP config to complete
            Serial.print('.');
            delay(300);
        }
        Serial.println("DONE");
    
        Serial.print("LAN name = ");
        Serial.println(wifi_name);
        Serial.print("WPA password = ");
        Serial.println(wifi_password);
    
    
        pinMode(RED_LED, OUTPUT);      // set the LED pin mode
        digitalWrite(RED_LED, LOW);
        pinMode(GREEN_LED, OUTPUT);      // set the LED pin mode
        digitalWrite(GREEN_LED, LOW);
        pinMode(YELLOW_LED, OUTPUT);      // set the LED pin mode
        digitalWrite(YELLOW_LED, LOW);
    
        IPAddress ip = WiFi.localIP();
        Serial.print("Webserver IP address = ");
        Serial.println(ip);
    
        Serial.print("Web-server port = ");
        myServer.begin();                           // start the web server on port 81
        Serial.println("81");
        Serial.println();
    }
    
    // Add loop code
    void loop()
    {
    
        countClients = WiFi.getTotalDevices();
    
        // Did a client connect/disconnect since the last time we checked?
        if (countClients != oldCountClients)
        {
            if (countClients > oldCountClients)
            {  // Client connect
                //            digitalWrite(RED_LED, !digitalRead(RED_LED));
                Serial.println("Client connected to AP");
                for (uint8_t k = 0; k < countClients; k++)
                {
                    Serial.print("Client #");
                    Serial.print(k);
                    Serial.print(" at IP address = ");
                    Serial.print(WiFi.deviceIpAddress(k));
                    Serial.print(", MAC = ");
                    Serial.println(WiFi.deviceMacAddress(k));
                    Serial.println("CC3200 in AP mode only accepts one client.");
                }
            }
            else
            {  // Client disconnect
                //            digitalWrite(RED_LED, !digitalRead(RED_LED));
                Serial.println("Client disconnected from AP.");
                Serial.println();
            }
            oldCountClients = countClients;
        }
    
        WiFiClient myClient = myServer.available();
    
        if (myClient)
        {                             // if you get a client,
            Serial.println(". Client connected to server");           // print a message out the serial port
            char buffer[150] = {0};                 // make a buffer to hold incoming data
            int8_t i = 0;
            while (myClient.connected())
            {            // loop while the client's connected
                if (myClient.available())
                {             // if there's bytes to read from the client,
                    char c = myClient.read();             // read a byte, then
                    Serial.write(c);                    // print it out the serial monitor
                      int sensorReading = analogRead(24);
                      int i=0;
                       while (i<4){
                      sensorReading = analogRead(24);
                      myClient.println(sensorReading);
                      Serial.println(sensorReading);
                      delay(20);
                       }
    

    I've been trying oscP5 libary, but i don't which kind of permises I have to give to my app to create what I want.

    Thank you for your help!!!

Sign In or Register to comment.