[photon] anyone who send OSC message successfully without cloud connection?

Hi. I want to send OSC message in local network from photon to PC in the same network area, without cloud connection.
I already search and tried in this forum. but not worked.

first I set SYSTEM_MODE(SEMI_AUTOMATIC)
and then setting destination ip address and port.

WiFi.connect() -> WiFi.ping(WiFi.gatewayIP()); -> WiFi.ready() checked. -> udp.begin(). not worked.
Wifi.useStaticIP() -> WiFi.connect() -> WiFi.ping(WiFi.gatewayIP()); -> WiFi.ready() checked. -> udp.begin(). not worked.

I confirmed that photon is connected with router. green LED is breathing. localIP is printed. and also, in router setting page, I can confirmed that. but, OSC messaged is not worked.

FIY, I used simple-OSC library. and all flashed with CLI.

here is my tested code.

SYSTEM_MODE(SEMI_AUTOMATIC); 
#include "simple-OSC.h"

UDP udp;
IPAddress outIP(192, 168, 100, 102);
unsigned int outPort = 8008;

unsigned int millisCounter;
unsigned int lastLEDToggleTimer;
bool bLEDMode = false;

void setup() {
	pinMode(D7, OUTPUT);
  // Put initialization like pinMode and begin functions here.
	Serial.begin(115200);

	// static IP setting
    IPAddress myAddress(192, 168, 100, 101);           
    IPAddress netmask(255, 255, 255, 0);
    IPAddress gateway(192, 168, 100, 1);
    IPAddress dns(192, 168, 100, 1);
    WiFi.setStaticIP(myAddress, netmask, gateway, dns);

    WiFi.useStaticIP();


    WiFi.connect();
    while(!WiFi.ready()){
    	Particle.process();
    	delay(100);
	}

	WiFi.ping(WiFi.gatewayIP());

	if(WiFi.ready()){	// flashing 10 times
		for(int i=0; i<10; i++){
    		digitalWrite(D7, HIGH);
    		delay(100);
    		digitalWrite(D7, LOW);	
    		delay(100);
    	}
	}
    
	udp.begin(8001);

    millisCounter = millis();
    lastLEDToggleTimer = millis();
    Serial.print("local IP: \t");
    Serial.println(WiFi.localIP());

}


// loop() runs over and over again, as quickly as it can execute.
void loop() {
  // The core of your code will likely live here.
	// millisCounter = millis();

	if (millis() - lastLEDToggleTimer > 200){
		bLEDMode = !bLEDMode;
		lastLEDToggleTimer = millis();
		millisCounter ++;
		Serial.println();
		Serial.print("counter : \t");
		Serial.println(millisCounter);

		WiFi.ping(WiFi.gatewayIP());

		OSCMessage message("/demo/millis");
		message.addInt(300);
		message.send(udp, outIP, outPort);
		Serial.print(".");
	}

	digitalWrite(D7, bLEDMode);
}

Have you tried raw UDP traffic on your network before going down the OSC route?
If not, take some variables out of the complex equation.

thanks for reply @ScruffR.

I found that some of addresses are not working.
actually it related with number of character of address string. if string length is four times( i.e. 4, 8, 12…), packet is broken.
looks something relate with simple-OSC library.

@ScruffR I am actually curious about this same thing. My ultimate goal is to have devices that communicate over WLAN with static IP addressing via OSC. Currently I am able to run my firmware no problem and communicate via OSC and UDP while in automatic mode and connected to the cloud.

I am able to generate a static IP that works and connects to the cloud by following this thread: I need to set a static IP on a Photon

Upon connection I can easily ping my particle and there are no indications of network failure on the board. When trying to implement a simple UDP message like this:

  Udp.beginPacket(IPAddress(192,168,0,22), 7100);
  Udp.write(TxMsg, 12);
  Udp.endPacket();
  Serial.println("message_sent");
  delay(1000);

I am seeing nothing on the other end and getting serial confirmation of message sent.

Full code (bits and pieces from the forum mostly):

SYSTEM_MODE(SEMI_AUTOMATIC);

define STATUS_LED D7
UDP Udp;

//Global variables
boolean useStaticIP = true;
unsigned char TxMsg[12] = { 1, 254, 1, 254, 1, 254, 43, 212, 71, 184, 3, 252 };

void setup(void) {
  // debug LED setup
  pinMode(STATUS_LED, OUTPUT);
  digitalWrite(STATUS_LED, HIGH);

  Time.zone(-8);
  delay(5000);
  Serial.begin(57600);
  delay(2000);
  Serial.println("Hello there!");

  Udp.begin(8888);

  // read wifi .INI and connect to network
  networkConnect();
}

void loop() {

  Udp.beginPacket(IPAddress(192,168,0,22), 7100);
  Udp.write(TxMsg, 12);
  Udp.endPacket();
  Serial.println("message_sent");
  delay(1000);
}

void networkConnect()
{
  char networkSSID[33] = "xxxx";
  char networkPass[65] = "xxxx";

  // WLAN_SEC_UNSEC = 0
  // WLAN_SEC_WEP = 1
  // WLAN_SEC_WPA = 2
  // WLAN_SEC_WPA2 = 3
  int authValue = 3;

  // WLAN_CIPHER_NOT_SET = 0
  // WLAN_CIPHER_AES = 1
  // WLAN_CIPHER_TKIP = 2
  // WLAN_CIPHER_AES_TKIP = 3
  int cipherValue = 1;

  uint8_t serverIP[] = {192, 168, 0, 150};
  IPAddress myAddress = serverIP;
  uint8_t serverNM[] = {255, 255, 255, 0};
  IPAddress netmask = serverNM;
  uint8_t serverGW[] = {192, 168, 0, 1};
  IPAddress gateway = serverGW;
  uint8_t serverDNS[] = {209, 18, 47, 62};
  IPAddress dns = serverDNS;

  // Static IP or DHCP?
  if (useStaticIP)
  {
    Serial.print("Using Static IP Address: ");
    Serial.print(serverIP[0]);
    Serial.print(".");
    Serial.print(serverIP[1]);
    Serial.print(".");
    Serial.print(serverIP[2]);
    Serial.print(".");
    Serial.println(serverIP[3]);
    WiFi.setStaticIP(myAddress, netmask, gateway, dns);
    WiFi.useStaticIP();
  }

  Serial.println("---");
  Serial.print("deviceID: ");
  String myID = System.deviceID();
  Serial.println(myID);
  Serial.printlnf("System version: %s", System.version().c_str());
  uint32_t freemem = System.freeMemory();
  Serial.print("free memory: ");
  Serial.println(freemem);
}

One thing to note, once you use WiFi.useStaticIP() this will be true till you actively revert back by explicitly calling WiFi.useDynamicIP() - even beyond power off.

With your current code it’s a one-way ticket.

BTW, you may want to put all the extra vars only used for static IP into the respective if-block too.
And when you only got one “trivial” packet, I’d go for Udp.sendPacket() instead of

  Udp.beginPacket(IPAddress(192,168,0,22), 7100);
  Udp.write(TxMsg, 12);
  Udp.endPacket();

Switched over to the Udp.sendPacket() as well a moved those vars into the proper if block, but still no UDP stream coming through? I tested the receiver by sending packets to it from a known working test app and it came through. Any ideas as to what else could be causing the issue?

Sorry for picking up an old thread, but any suggestions as to what to do in order to move forward? Really trying to get this working for an upcoming installation.

I haven’t had any chance to check your code, but maybe @rickkas7 has some test rig he could use for testing this :wink:

You can’t call udp.begin(8888) until after WiFi.ready() returns true.

It looks like you’re using SEMI_AUTOMATIC but I don’t see a WiFi.connect() or Particle.connect() so the Photon will never go online.

You need to make one of those calls, then wait for WiFi.ready() before you can call udp.begin.

1 Like

Completely missed this part due to this statement

Hey @rickkas7 and @ScruffR thanks so much for responses and advice!

I added the WiFi.connect() and was checking WiFi.ready() before opening the Udp port, but still having no luck.

At this point I was able to definitively confirm that my particles have the proper static local IP, and was able to ping them from my laptop, but still no UDP coming through.

After a bit of messing around I removed the inline ip: Udp.sendPacket(TxMsg, 12, (192,168,0,4), 8888); and changed it to a local variable with the IPAddress data type: IPAddress remoteIP(192, 168, 0, 4); and the UDP and OSC worked!

Figured I’d post the rest of the code here if anyone else may find it useful.

#include "Particle.h"
#include "simple-OSC/simple-OSC.h"

SYSTEM_MODE(SEMI_AUTOMATIC);

#define STATUS_LED D7
UDP Udp;

//Global variables
boolean useStaticIP = true;
unsigned char TxMsg[12] = { 1, 254, 1, 254, 1, 254, 43, 212, 71, 184, 3, 252 };
IPAddress remoteIP(192, 168, 0, 4);
int port = 4545;

// device variables
String sys_id = System.deviceID();

void setup(void) {
  // debug LED setup
  pinMode(STATUS_LED, OUTPUT);
  digitalWrite(STATUS_LED, HIGH);

  Time.zone(-8);
  delay(5000);
  Serial.begin(57600);
  delay(2000);
  Serial.println("Hello there!");

  // Connect to Network
  networkConnect();
  delay(1000);

  if(!WiFi.ready())
  {
    networkConnect();
  }
  else Udp.begin(8888);
  Serial.println("UDP Connected @ port 8888");
}

void loop() {

  //Udp.sendPacket(TxMsg, 12, remoteIP, port);
  delay(100);
  //Udp.sendPacket(TxMsg, 12, remoteIP, 8888);
  delay(100);
  Udp.sendPacket(TxMsg, 12, remoteIP, 59288);
  SEND_OSC();


  //blink LED for each message sent
  digitalWrite(STATUS_LED, LOW);
  delay(100);
  digitalWrite(STATUS_LED, HIGH);
  delay(1000);
}

void networkConnect()
{
  char networkSSID[33] = "xxx";
  char networkPass[65] = "xxx";

  uint8_t serverIP[] = {192, 168, 0, 40};
  IPAddress myAddress = serverIP;
  uint8_t serverNM[] = {255, 255, 255, 0};
  IPAddress netmask = serverNM;
  uint8_t serverGW[] = {192, 168, 0, 1};
  IPAddress gateway = serverGW;
  uint8_t serverDNS[] = {209, 18, 47, 62};
  IPAddress dns = serverDNS;

  // Static IP or DHCP?
  if (useStaticIP)
  {
    Serial.print("Using Static IP Address: ");
    Serial.print(serverIP[0]);
    Serial.print(".");
    Serial.print(serverIP[1]);
    Serial.print(".");
    Serial.print(serverIP[2]);
    Serial.print(".");
    Serial.println(serverIP[3]);
    WiFi.setStaticIP(myAddress, netmask, gateway, dns);
    WiFi.useStaticIP();
  }
  else Serial.println("Using DHCP");

  // Connect to WiFi Network
  WiFi.connect(WIFI_CONNECT_SKIP_LISTEN);
  delay(1000);

  while(!WiFi.ready())
  {
    Particle.process();
    Serial.println("Waiting on Network");
  }

  if(WiFi.ready())
  {
    Serial.println("Connected to:");
    Serial.println(WiFi.localIP());
    Serial.println(WiFi.subnetMask());
    Serial.println(WiFi.gatewayIP());
    Serial.println(WiFi.SSID());
  }

  Serial.println("---");
  Serial.print("deviceID: ");
  String myID = System.deviceID();
  Serial.println(myID);
  Serial.printlnf("System version: %s", System.version().c_str());
  uint32_t freemem = System.freeMemory();
  Serial.print("free memory: ");
  Serial.println(freemem);
}

void SEND_OSC()
{
  //SEND
  OSCMessage outMessage("/"+ sys_id);
  // pulse arg
  outMessage.addInt( 0 );
  // arg for pole id
  outMessage.addInt( 7 );
  outMessage.send( Udp, remoteIP, port );
  Serial.println("message sent");
}