Thanks for taking the time to reply!
Is it best to keep these threads separate or should I jump across for any future replies?
Iām not having any success with either TCP or ICMP ping work arounds - both give the same results as I originally posted.
My code is getting very hacky, but Iām quite sure itās working as intended, based on the network output Iām seeing when I change #define options. If you spot any errors that have crept in, that would be good to know!
I am compiling locally using the master branch of the spark firmware repo, then uploading using dfu-util. Could any of that be causing issues as a few others confirm the workaround works for them?
If thereās any code that is known to work, Iād love a link so I can test if it is my environment or something elseā¦
My code is getting very messy now, sorry for that - but I hope it conveys that Iām trying all the options!
W.
#include "neopixel__spark_internet_button/neopixel__spark_internet_button.h"
// IMPORTANT: Set pixel COUNT, PIN and TYPE
#define PIXEL_PIN A7
#define PIXEL_COUNT 11
#define PIXEL_TYPE WS2812B
#define INITIALISE 0
#define CONNECTING 1
#define CONNECTED 2
#define DISCONNECTED 3
//config:
#define MAN_WIFI
#define EVERYONE
//#define MANUAL_CONNECT_TO_CLOUD
//#define DISCONNECT_FROM_CLOUD
#define TCP_WORKAROUND
#define WORKAROUND
#ifdef MAN_WIFI
SYSTEM_MODE(MANUAL);
#else
SYSTEM_MODE(AUTOMATIC);
#endif
void signal(int state);
#ifdef WORKAROUND
bool once = true;
#ifdef TCP_WORKAROUND
TCPClient client;
#endif
#endif
Adafruit_NeoPixel strip = Adafruit_NeoPixel(PIXEL_COUNT, PIXEL_PIN, PIXEL_TYPE);
unsigned int
state = INITIALISE;
UDP udp;
int limit,localPort = 5050,packetCount=0;
unsigned char tgtIP[] =
#ifdef EVERYONE
{255,255,255,255}
#else
{192,168,1,255}
#endif
;
void sendPacket()
{
udp.begin(localPort);
udp.beginPacket(tgtIP, 8080);
udp.write((const unsigned char *)"Hello World!",12);
udp.endPacket();
udp.stop();
}
void setup()
{
pinMode(D0,INPUT);
pinMode(D1, INPUT_PULLUP);
strip.begin();
strip.show(); // Initialize all pixels to 'off'
limit=1;
signal(10);
}
int togState=0;
void loop()
{
#ifdef MAN_WIFI
if(WiFi.connecting())
return;
if(!WiFi.ready())
{
//not ready or connecting - turn it on and start to connect...
WiFi.on();
WiFi.connect();
signal(1);
return;
}
#ifdef MANUAL_CONNECT_TO_CLOUD
switch(state)
{
case INITIALISE:
signal(2);
Spark.connect();
state = CONNECTING;
return;
case CONNECTING:
if(Spark.connected())
signal(3);
state=CONNECTED;
else
return;
}
#else
state = CONNECTED;
#endif
#endif
#ifdef DISCONNECT_FROM_CLOUD
if(state == CONNECTED && Spark.connected())
{
signal(4);
Spark.disconnect();
state = DISCONNECTED;
}
#endif
#ifdef WORKAROUND
if(once)
{
once = false;
signal(5);
#ifdef TCP_WORKAROUND
client.connect("www.google.com",80);
delay(1000);
client.stop();
#else
//WiFi.ping({192,168,27,210});
WiFi.ping(WiFi.gatewayIP());
#endif
signal(6);
delay(1000);
signal(7);
}
#endif
if(digitalRead(D1) == 0)
{
limit=1;
packetCount=1;
}
if(packetCount > 0)
{
packetCount--;
sendPacket();
}
if(limit > 0)
{
signal(8 + togState);
togState = (togState ? 0 : 1);
limit =0;
delay(500);
}
}
void blank()
{
for(int i=0; i<strip.numPixels(); i++)
strip.setPixelColor(i, 0);
}
unsigned int on = Adafruit_NeoPixel::Color(63,0,0);
void signal(int state)
{
blank();
strip.setPixelColor(state,on);
strip.show();
}