/* * This program feeds simulated data to the LabVIEW-based * Interface Engine over a UDP feed. */ // Include the networking stuff #include #include #include int status = WL_IDLE_STATUS; #include "arduino_secrets.h" ///////please enter your sensitive data in the Secret tab/arduino_secrets.h char ssid[] = SECRET_SSID; // your network SSID (name) char pass[] = SECRET_PASS; // your network password (use for WPA, or use as key for WEP) int keyIndex = 0; // your network key Index number (needed only for WEP) IPAddress remote_ip(10, 0, 0, 102); // The PC running LabVIEW unsigned int remote_port = 61558; // The UDP port that LabVIEW is watching unsigned int localPort = 8888; // The UDP port that the Arduino is monitoring char packetBuffer[145]; // character array to hold outgoing message WiFiUDP Udp; // A UDP instance to let us send and receive packets over UDP void setup() { Serial.begin(9600); // check for the presence of the shield: if (WiFi.status() == WL_NO_SHIELD) { Serial.println("WiFi shield not present"); // don't continue: while (true); } // attempt to connect to WiFi network: while ( status != WL_CONNECTED) { Serial.print("Attempting to connect to SSID: "); Serial.println(ssid); // Connect to WPA/WPA2 network. Change this line if using open or WEP network: status = WiFi.begin(ssid, pass); // wait 10 seconds for connection: delay(2000); } Serial.println("Connected to wifi"); printWiFiStatus(); Serial.println("\nStarting UDP Instance..."); Udp.begin(localPort); } void loop() { // Generate Channel 0 Simulated Data // to be replaced with actual acquisition logic float bq0 = ((float)random(100, 999))/1000; float bq1 = ((float)random(100, 999))/1000; float bq2 = ((float)random(100, 999))/1000; float bq3 = ((float)random(100, 999))/1000; /* float blaX = ((float)random(0, 12400))/1000; float blaY = ((float)random(0, 12400))/1000; float blaZ = ((float)random(0, 12400))/1000; float baaX = ((float)random(0, 12400))/1000; float baaY = ((float)random(0, 12400))/1000; float baaZ = ((float)random(0, 12400))/1000; */ // Generate Channel 1 Simulated Data // to be replaced with actual acquisition logic float hq0 = ((float)random(200, 999))/1000; float hq1 = ((float)random(200, 999))/1000; float hq2 = ((float)random(200, 999))/1000; float hq3 = ((float)random(200, 999))/1000; /* float hlaX = ((float)random(0, 12400))/1000; float hlaY = ((float)random(0, 12400))/1000; float hlaZ = ((float)random(0, 12400))/1000; float haaX = ((float)random(0, 12400))/1000; float haaY = ((float)random(0, 12400))/1000; float haaZ = ((float)random(0, 12400))/1000; */ // Generate output packet /* String cn0 = String(bq0,3) + "," + String(bq1,3) + "," + String(bq2,3) + "," + String(bq3,3) + "," + String(blaX,3) + "," + String(blaY,3) + "," + String(blaZ,3) + "," + String(baaX,3) + "," + String(baaY,3) + "," + String(baaZ,3); */ String cn0 = String(bq0,4) + "," + String(bq1,4) + "," + String(bq2,4) + "," + String(bq3,4); /* String cn1 = String(hq0,3) + "," + String(hq1,3) + "," + String(hq2,3) + "," + String(hq3,3) + "," + String(hlaX,3) + "," + String(hlaY,3) + "," + String(hlaZ,3) + "," + String(haaX,3) + "," + String(haaY,3) + "," + String(haaZ,3); */ String cn1 = String(hq0,4) + "," + String(hq1,4) + "," + String(hq2,4) + "," + String(hq3,4); String output = cn0 + "," + cn1; // Print output to serial monitor // Serial.println(output); // Copy string into outgoing packet -- // Stop when you get to the null terminator int i = 0; memset(packetBuffer, 0, 144); while ((int)output[i] != 0){ packetBuffer[i] = output[i]; i = i + 1; } // send the output via UDP Udp.beginPacket(remote_ip, remote_port); Udp.write(packetBuffer); Udp.endPacket(); delay(250); } void printWiFiStatus() { // print the SSID of the network you're attached to: Serial.print("SSID: "); Serial.println(WiFi.SSID()); // print your WiFi shield's IP address: IPAddress ip = WiFi.localIP(); Serial.print("IP Address: "); Serial.println(ip); // print the received signal strength: long rssi = WiFi.RSSI(); Serial.print("signal strength (RSSI):"); Serial.print(rssi); Serial.println(" dBm"); }