0

MODBUS TCP via WiFi Shield
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

MODBUS TCP via WiFi Shield

by ductsoup on Fri Oct 17, 2014 5:20 pm

I'd like to get an Arduino Uno with the Adafruit WiFi shield (slave) connected to our SCADA solution (master). I found a library called Mudbus that seems suitable but it's coded for the Arduino ethernet shield.

So far I've updated the WiFi firmware to the latest release, successfully run wifibuildtest, pulled the Mudbus library into one of the example sketches and made what I think are the appropriate include and instance changes. The sketch compiles without errors or warnings, I get the connection to the AP but the sketch seems to hang at the first call to client.available() in the Modbus object.

I've only been messing with Arduino for a week so I figured I stop and ask before diving into a full debug. First, has anyone else gone down this road? And second, is there any resource or pointers for porting to the WiFi shield?

Thanks, C

ductsoup
 
Posts: 160
Joined: Sun Oct 12, 2014 7:26 am

Re: MODBUS TCP via WiFi Shield

by franklin97355 on Fri Oct 17, 2014 7:35 pm

Perhaps if you posted your code and a link to the library we could look for options.

franklin97355
 
Posts: 16661
Joined: Mon Apr 21, 2008 2:33 pm
Location: Lacomb, OR.

Re: MODBUS TCP via WiFi Shield

by ductsoup on Sat Oct 18, 2014 6:29 am

The Mudbus library is here: https://code.google.com/p/mudbus/downloads/list.

To get it to compile I made these changes.

In Mudbus.h
Code: Select all | TOGGLE FULL SIZE
//#include <Ethernet.h>
#include "Adafruit_CC3000_Library-master\Adafruit_CC3000.h"

In Mudbus.cpp
Code: Select all | TOGGLE FULL SIZE
//EthernetServer MbServer(MB_PORT);
Adafruit_CC3000_Server MbServer(MB_PORT);

and
Code: Select all | TOGGLE FULL SIZE
  //EthernetClient client = MbServer.available();
  Adafruit_CC3000_ClientRef client = MbServer.available();

The usage is much like the WiFi shield HTTPServer.

ductsoup
 
Posts: 160
Joined: Sun Oct 12, 2014 7:26 am

Re: MODBUS TCP via WiFi Shield

by ductsoup on Sat Oct 18, 2014 8:16 am

Hark!

Problem solved. There was no call to .begin() in the library so we apparently weren't listening for connections.

Code: Select all | TOGGLE FULL SIZE
void Mudbus::Begin()
{
  MbServer.begin();
}

ductsoup
 
Posts: 160
Joined: Sun Oct 12, 2014 7:26 am

Re: MODBUS TCP via WiFi Shield

by skyscan on Tue Dec 02, 2014 10:26 pm

Could you post the complete library?

skyscan
 
Posts: 2
Joined: Thu Mar 20, 2014 8:22 pm

Re: MODBUS TCP via WiFi Shield

by franklin97355 on Wed Dec 03, 2014 12:00 am

lloyd the link is two posts above yours. https://code.google.com/p/mudbus/downloads/list.

franklin97355
 
Posts: 16661
Joined: Mon Apr 21, 2008 2:33 pm
Location: Lacomb, OR.

Re: MODBUS TCP via WiFi Shield

by skyscan on Wed Dec 03, 2014 9:34 pm

I was hoping to get the modified modbus library for the WiFi shield CC3000.

I was unclear on ductsoup's edit in last post

skyscan
 
Posts: 2
Joined: Thu Mar 20, 2014 8:22 pm

Re: MODBUS TCP via WiFi Shield

by ductsoup on Thu Dec 04, 2014 7:05 am

The plan is to make it available on Github this weekend.

ductsoup
 
Posts: 160
Joined: Sun Oct 12, 2014 7:26 am

Re: MODBUS TCP via WiFi Shield

by ductsoup on Sun Dec 07, 2014 8:21 am

@lloyd,

Should be good to go, enjoy.

http://github.com/ductsoup

ductsoup
 
Posts: 160
Joined: Sun Oct 12, 2014 7:26 am

Re: MODBUS TCP via WiFi Shield

by frank_dunn1 on Fri Apr 24, 2015 4:33 pm

I have modified this library to work on a ESP8266 with arduino 1.6.1p , It works but I get no response every second modbus frame . Would anybody be interested to
take a look at my code .

frank_dunn1
 
Posts: 7
Joined: Fri Apr 24, 2015 4:26 pm

Re: MODBUS TCP via WiFi Shield

by aniston on Wed May 13, 2015 4:41 am

Hello Frank, I am interested in trying your code , can you post the modified library with the problems you see already or any output messages, also what is your setup or rather how is the ESP8266 connected to your ATmega328P.

regards,
aniston.

aniston
 
Posts: 1
Joined: Wed May 13, 2015 4:37 am

Re: MODBUS TCP via WiFi Shield

by frank_dunn1 on Wed May 13, 2015 5:48 am

The ESP8266 is not connected to ATmega328P . I am using Arduino 1.6.1-p1 to program ESP8266 directly .
Code: Select all | TOGGLE FULL SIZE
/*

 Simple Test
 
 */

//
// Note: The Arduino IDE does not respect conditional included
// header files in the main sketch so you have to select your
// hardware here, and in ModbusTCP.h.
//
// If you want to use both wired and wireless in different
// projects copy ModbusTCP.h and ModbusTCP.cpp to the individual
// sketch folders instead of installing the library.
//

//#include <Ethernet.h>
//#include <Adafruit_CC3000.h>
#include<ESP8266WiFi.h>
//#include <SPI.h>
#include "ModbusTCP.h"

// Register map for this example
#define S1_FloatConstant 40001 // modpoll -m tcp -t 4:float -r 40001 [ip_addr]
#define S1_CurrentMillis 40003 // modpoll -m tcp -t 4:int -r 40003 [ip_addr]
#define S1_FeetPerMile   40005 // modpoll -m tcp -t 4 -r 40005 [ip_addr]

ModbusTCP m;

const char* myssid     = "SSID";
const char* mypassword = "password";

void setup(void)
{
  Serial.begin(115200);
 
  // set some initial values
  //m.setFloat(S1_FloatConstant, PI);
  //m.setU32(S1_CurrentMillis, millis());
  //m.setU16(S1_FeetPerMile, 5280);
 
  //uint8_t mac[]     = { 0x70, 0xFF, 0x76, 0x00, 0xDF, 0x25 };
  //m.begin(mac);
  m.begin(myssid,mypassword);
}

void loop(void)
{
  // Process MODBUS requests on every scan
  m.run();
  //Serial.println(WiFi.localIP());
  delay(40);
  // Update the MODBUS registers 
  //m.setU32(S1_CurrentMillis, millis());
}
Attachments
ModbusTCP.h
(6.72 KiB) Downloaded 186 times
ModbusTCP.cpp
(8.61 KiB) Downloaded 182 times
Last edited by franklin97355 on Wed May 13, 2015 3:01 pm, edited 1 time in total.
Reason: Added missing [code] tags.

frank_dunn1
 
Posts: 7
Joined: Fri Apr 24, 2015 4:26 pm

Re: MODBUS TCP via WiFi Shield

by sree741 on Wed Jul 15, 2015 4:37 am

Hi frank, your motive was appreciating.are you done the modbus tcp wifi slave using arduino and ESP8266.Iam trying it for past 10 days.still not succeeded.If you have the currect code please explain

sree741
 
Posts: 1
Joined: Wed Jul 15, 2015 4:32 am

Re: MODBUS TCP via WiFi Shield

by crazyharold on Fri Jul 31, 2015 9:03 am

I modified the modbusTCP library for ESP8266 use.
Currently it works, but the connection drops after each request.
I think it has to do with the use of "WiFiClient clientrequest = mb_server.available();"

Can someone have a look at it ?
Just unzip the file and open in Arduino 1.6.5

Regards, Harold.

I added a second zipfile,
The first one creates a ESP8266 access point.
The second one connects to the specified SSID/Password.
Attachments
simpletest_1.zip
(6.31 KiB) Downloaded 224 times
simpletest_1.zip
(6.25 KiB) Downloaded 210 times

crazyharold
 
Posts: 1
Joined: Fri Jul 31, 2015 9:00 am

Re: MODBUS TCP via WiFi Shield

by frank_dunn1 on Mon Aug 03, 2015 2:29 pm

Hi Harold

I had the same behaviour from the code I posted a while ago , sorry I dont know where to start looking .

frank_dunn1
 
Posts: 7
Joined: Fri Apr 24, 2015 4:26 pm

Please be positive and constructive with your questions and comments.