ni.com is currently undergoing scheduled maintenance.

Some services may be unavailable at this time. Please contact us for help or try again later.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

sending data throughTCP/IP to an Labview server.

Hello,

I'm trying to send a string from an arduino gsm board  to an labview server. From arduino board i think everythink is ok, i specified ip adress and port number, the problem is that it can't connect to the labview server and i don't have any more ideas where can be the proble.

I tryed with hercules to listen o port and it works fine, i received the data from arduino.

 

I leave here the code i used and the VI for server.

 

 

 

 

 

 

 

// libraries
#include <MKRGSM.h>
#include <Arduino_MKRENV.h>

// Please enter your sensitive data in the Secret tab or arduino_secrets.h
// PIN Number
const char PINNUMBER[]     = "1234";
// APN data
const char GPRS_APN[]      = "live.vodafone.com";
const char GPRS_LOGIN[]    = "live";
const char GPRS_PASSWORD[] = "";

// initialize the library instance
GSMClient client;
GPRS gprs;
GSM gsmAccess;

uint8_t pachet[] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
// URL, path and port (for example: example.org)
char server[] = "141.85.162.154";
char path[] = "/";
int port = 5901; // port 80 is the default for HTTP

void setup() {
  // initialize serial communications and wait for port to open:
  Serial.begin(9600);
  while (!Serial) {
    ; // wait for serial port to connect. Needed for native USB port only
  }
  if (!ENV.begin()) {
    Serial.println("Failed to initialize MKR ENV shield!");
    while (1);
  Serial.println("Starting Arduino web client.");
  // connection state
  bool connected = false;

  // After starting the modem with GSM.begin()
  // attach the shield to the GPRS network with the APN, login and password
  while (!connected) {
    if ((gsmAccess.begin(PINNUMBER) == GSM_READY) &&
        (gprs.attachGPRS(GPRS_APN, GPRS_LOGIN, GPRS_PASSWORD) == GPRS_READY)) {
      connected = true;
    } else {
      Serial.println("Not connected");
      delay(1000);
    }
  }

  Serial.println("connecting...");

  // if you get a connection, report back via serial:
  if (client.connect(server, port)) {
    Serial.println("connected");
    // Make a HTTP request:
//    client.print("GET ");
//    client.print(path);
//    client.println(" HTTP/1.1");
//    client.print("Host: ");
//    client.println(server);
//    client.println("Connection: close");
//    client.println();
 client.beginWrite();
 client.write(pachet, sizeof(pachet));
 client.endWrite();
  } else {
    // if you didn't get a connection to the server:
    Serial.println("connection failed");
   }
 } 
}
void loop() {

  // read all the sensor values
  float temperature = ENV.readTemperature();
  uint16_t word_temp = temperature * 100;
  uint8_t high_word_temp = word_temp >> 8;
  uint8_t low_word_temp = word_temp;
  pachet[1] = high_word_temp;
  pachet[2] = low_word_temp;


  float humidity    = ENV.readHumidity();
  uint16_t word_hum = humidity * 100;
  uint8_t high_word_hum = word_hum >> 8;
  uint8_t low_word_hum = word_hum;
  pachet[3] = high_word_hum;
  pachet[4] = low_word_hum;


  float pressure    = ENV.readPressure();
  int16_t word_pressure = pressure * 100;
  uint8_t high_word_pressure = word_pressure >> 8;
  uint8_t low_word_pressure = word_pressure;
  pachet[5] = high_word_pressure;
  pachet[6] = low_word_pressure;

  float illuminance = ENV.readIlluminance();
  uint16_t word_illuminance = illuminance * 100;
  uint8_t high_word_illuminance = word_illuminance >> 8;
  uint8_t low_word_illuminance = word_illuminance;
  pachet[7] = high_word_illuminance;
  pachet[8] = low_word_illuminance;

  float uva         = ENV.readUVA();
  uint16_t word_uva = uva * 100;
  uint8_t high_word_uva = word_uva >> 8;
  uint8_t low_word_uva = word_uva;
  pachet[9] = high_word_uva;
  pachet[10] = low_word_uva;

  float uvb         = ENV.readUVB();
  uint16_t word_uvb = uvb * 100;
  uint8_t high_word_uvb = word_uvb >> 8;
  uint8_t low_word_uvb = word_uvb;
  pachet[13] = high_word_uvb;
  pachet[14] = low_word_uvb;


  float uvIndex     = ENV.readUVIndex();   

  // print each of the sensor values
  Serial.print("Temperature = ");
  Serial.print(temperature);
  Serial.println(" °C");

  Serial.print("Humidity    = ");
  Serial.print(humidity);
  Serial.println(" %");

  Serial.print("Pressure    = ");
  Serial.print(pressure);
  Serial.println(" kPa");

  Serial.print("Illuminance = ");
  Serial.print(illuminance);
  Serial.println(" lx");

  Serial.print("UVA         = ");
  Serial.println(uva);

  Serial.print("UVB         = ");
  Serial.println(uvb);

  Serial.print("UV Index    = ");
  Serial.println(uvIndex);

  
  Serial.print(" ");
   Serial.println(" ");
  for(int i=0; i<28; i++)
  {
//    if(pachet[i]==0)
//      {
//        pachet[i]=1;
//      }
      
    Serial.print(pachet[i]);
    Serial.print(" ");
  }

  Serial.println();
  Serial.print("dimenziunea pachetului este");
  Serial.println(sizeof(pachet)); 
 
  // print an empty line
  Serial.println();

  // wait 1 second to print again
  delay(1000);
  
  // if there are incoming bytes available

// from the server, read them and print them:
  if (client.available()) {
    char c = client.read();
    Serial.print(c);
  }


  // if the server's disconnected, stop the client:
  if (!client.available() && !client.connected()) {
    Serial.println();
    Serial.println("disconnecting.");
    client.stop();

    // do nothing forevermore:
    for (;;)
      ;
  }
}

 

 

 

 

 

 

0 Kudos
Message 1 of 2
(1,124 Views)

Hi Dummson,

 


@Dummson wrote:

the problem is that it can't connect to the labview server and i don't have any more ideas where can be the proble.

I tryed with hercules to listen o port and it works fine, i received the data from arduino.

 

I leave here the code i used and the VI for server.


Unfortunately you forgot to attach that VI…

 

Can you create one more VI that does the same as the Arduino should do: send some data to your "LabVIEW server" (whatever that is!?)?

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 2 of 2
(1,096 Views)