MODBUS TCP via WiFi Shield

Adafruit Ethernet, Motor, Proto, Wave, Datalogger, GPS Shields - etc!

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
User avatar
Franklin97355
 
Posts: 23938
Joined: Mon Apr 21, 2008 2:33 pm

Re: MODBUS TCP via WiFi Shield

Post by Franklin97355 »

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

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

Re: MODBUS TCP via WiFi Shield

Post by skyscan »

Could you post the complete library?

User avatar
Franklin97355
 
Posts: 23938
Joined: Mon Apr 21, 2008 2:33 pm

Re: MODBUS TCP via WiFi Shield

Post by Franklin97355 »

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

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

Re: MODBUS TCP via WiFi Shield

Post by skyscan »

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

I was unclear on ductsoup's edit in last post

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

Re: MODBUS TCP via WiFi Shield

Post by frank_dunn1 »

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 .

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

Re: MODBUS TCP via WiFi Shield

Post by frank_dunn1 »

The ESP8266 is not connected to ATmega328P . I am using Arduino 1.6.1-p1 to program ESP8266 directly .

Code: Select all

/*

 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 523 times
ModbusTCP.cpp
(8.61 KiB) Downloaded 503 times
Last edited by Franklin97355 on Wed May 13, 2015 3:01 pm, edited 1 time in total.
Reason: Added missing [code] tags.

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

Re: MODBUS TCP via WiFi Shield

Post by sree741 »

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

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

Re: MODBUS TCP via WiFi Shield

Post by crazyharold »

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 318 times
simpletest_1.zip
(6.25 KiB) Downloaded 295 times

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

Re: MODBUS TCP via WiFi Shield

Post by frank_dunn1 »

Hi Harold

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

User avatar
ibbba
 
Posts: 4
Joined: Tue Aug 25, 2015 5:31 pm

Re: MODBUS TCP via WiFi Shield

Post by ibbba »

Hello,I just finished a working Modbus TCP library that works with standard Arduino Ethernet shield,Sparkfun Thing (Esp8266 based board) and should work with Adafruit CC3000 Wifi shield.
I don't have the Adafruit shield,so if somebody can give it a try and report will be very useful.
The used board must me defined in the supplied header file.
ModbusTCPSlave.zip
(12.28 KiB) Downloaded 2179 times

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

Re: MODBUS TCP via WiFi Shield

Post by frank_dunn1 »

hi ibbba

I tested your library on a olimex esp8266 board , it seems to work fine. With a 200msec poll delay it runs, with a 100msec delay i get reboots .
The olimex board have gpio5 connected to a relay , how can I change this without changing the header file ?

User avatar
ibbba
 
Posts: 4
Joined: Tue Aug 25, 2015 5:31 pm

Re: MODBUS TCP via WiFi Shield

Post by ibbba »

I personally use to poll not less than one second,so I take your test like a speed test... Ok good.... Regarding The output led that I use to monitor can be ridefined in the header file,or you can delete every call to digitalWrite in The cpp file... Up to you... I hope somebody can test it with The Adafruit shield

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

Re: MODBUS TCP via WiFi Shield

Post by frank_dunn1 »

Hi ibbba

I notice when I test your library with modbusmaster that stays connected , the code in the main loop never executes until I disconnect the modbusmaster .

User avatar
ibbba
 
Posts: 4
Joined: Tue Aug 25, 2015 5:31 pm

Re: MODBUS TCP via WiFi Shield

Post by ibbba »

frank_dunn1 wrote:Hi ibbba

I notice when I test your library with modbusmaster that stays connected , the code in the main loop never executes until I disconnect the modbusmaster .
Yes this is an issue due to the Wifi library...if you check with the standard ethernet shield you will notice that the loop is excuted normally...to avoid this you have to close the connection after each request...I use a Rasperry PI to poll with minimalmodbus python library and closing the connection after each request do the job.

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

Re: MODBUS TCP via WiFi Shield

Post by frank_dunn1 »

hi ibbba

I tested the code using the Ticker library to call functions in the main loop and this works fine while the client stays connected .

Locked
Please be positive and constructive with your questions and comments.

Return to “Arduino Shields from Adafruit”