Author Topic: Pure Wifi mode  (Read 2806 times)

Mike_Eitel

  • Newbie
  • *
  • Posts: 3
Pure Wifi mode
« on: December 17, 2016, 09:41:50 am »
Hi
I read in docs and forums but could not get a clear view how to archive what I want:
Having oakboards ( until now > 8 ) connected via wifi to my control system.

I run Raspberry with Codesys and need remote IO modules.
The industrial world where I'm comming from, uses commonly IEC61131 programming tools with included webserver. And Codesys is one of the biggest, additionaly you can get a raspberry license for only 35 bugs!

One very good connection of io modules is via ethernet based Modbus TCP protocol. Would fit perfect to my advanced home automation. That is why I bought those oaks; but haven't been able to find the best way of implementation.

For safety reasons  I do not want any internet based programming like particle, I need to stay inside my own wifi network.

Is there an easy way to get oak in pure wifi modus? With fixed ip's and with that protocol? ( I intend to write it myself, did it for pure serial AVR years agoo) By the way, modbus it's still the mostly distributed protocol and every control system, scada or even lots of apps are talking modbus.

Thx for a small description how to use arduino witch libs, and eventually based on with example I could do it.

Mike

PeterF

  • Hero Member
  • *****
  • Posts: 881
Re: Pure Wifi mode
« Reply #1 on: December 17, 2016, 04:19:36 pm »
To disable the particle internet connection, you'll want to run your Oaks in SEMI_AUTOMATIC mode i.e. SYSTEM_MODE(SEMI_AUTOMATIC); at minimum... this will get them onto your wifi, but won't start the particle connection itself. This also allows you to still use the SoftAP OakConfig app (although the particle login on the app would then be rather pointless).

If you want full control of the wifi, you then want your Oaks in MANUAL mode i.e. SYSTEM_MODE(MANUAL); which will let you choose when to start the wifi connection. The following code should give you an idea as to how it all fits together. It will connect to a hard-coded wifi network, and attempt to use the specified IP. Whilst the wifi is connecting the P1 led should rapidly blink. Then once the main loop is running the classic blink sketch runs... I disabled persistence so that it doesn't interfere with the SoftAP OakConfig app as the P1 config mode is still available for use, and there is no need for it anyway as the wifi SSID / passwd is hard coded in the sketch. This then allows your to use Particle still for the OTA programming if you want access to it at any time.

When you load this code via OTA programming, you will get a message saying "Error : Reboot timeout - flash likely failed.", which is to be expected, as the Oak never connects to particle after starting the sketch, thus can't report that it is online.

Code: [Select]
SYSTEM_MODE(MANUAL);

#include <ESP8266WiFi.h>

//WiFi config stuff
char SSID[] = "yourNetwork";    // your network SSID
char passwd[] = "secretPassword"; // your network password

//Static IP stuff
IPAddress ip(192, 168, 0, 70); //your static IP
IPAddress gateway(192, 168, 0, 1); //your gateway IP
IPAddress subnet(255, 255, 255, 0);  //your subnet mask

void setup()
{
  pinMode(LED_BUILTIN, OUTPUT);
 
  //don't save these details
  WiFi.persistent(false);

  //configure the WiFi to use the custom settings
  WiFi.config(ip, gateway, subnet);

  //start the WiFi connection process
  WiFi.begin_internal(SSID, passwd, 0, NULL);

  //wait for WiFi to connect
  while (WiFi.status() != WL_CONNECTED)
  {
    digitalWrite(LED_BUILTIN, HIGH);
    delay(100);
    digitalWrite(LED_BUILTIN, LOW);
    delay(100);
  }
}

void loop()
{
  digitalWrite(LED_BUILTIN, HIGH);   // turn the LED on (HIGH is the voltage level)
  delay(1000);                       // wait for a second
  digitalWrite(LED_BUILTIN, LOW);    // turn the LED off by making the voltage LOW
  delay(1000);                       // wait for a second 
}

« Last Edit: December 17, 2016, 04:23:16 pm by PeterF »

exeng

  • Sr. Member
  • ****
  • Posts: 454
Re: Pure Wifi mode
« Reply #2 on: December 17, 2016, 06:35:46 pm »
Pete, it appears you have created the basis for a Wiki for Pure Wifi mode with an example.
« Last Edit: December 17, 2016, 07:00:24 pm by exeng »

PeterF

  • Hero Member
  • *****
  • Posts: 881
Re: Pure Wifi mode
« Reply #3 on: December 17, 2016, 07:29:49 pm »
lol... well, what do you know... so I did indeed! :-P ... so now I suppose I should add this sketch, another one that sticks with DHCP, and probably a third 'normal' Oak API one showing how to do some simple connect when a button is pressed type stuff... as isn't that the gold standard of Oakdem... being able to make your own IoT Wifi button? :-D Thanks for the reminder Steve ;)


Mike_Eitel

  • Newbie
  • *
  • Posts: 3
Re: Pure Wifi mode
« Reply #4 on: December 18, 2016, 07:12:33 am »
THX Peter

That gives me a good starting point.

Will report back as soon as i will have coded something...
Will take a while as i'm "dancing on to many weddings= projects" as my lady tell's me..

Mike