Notifications
Clear all

Sending data over the ethernet using server.write()

74 Posts
6 Users
7 Reactions
6,956 Views
Ron
 Ron
(@zander)
Father of a miniature Wookie
Joined: 4 years ago
Posts: 7714
 

@inq No need to get tricky, the doc'n I am looking at says it can write strings and there is a ReadString listed in the API contents. By. making use of sprintf he can format with a decimal and round 3 digits to two if that is what he wants.

Screen Shot 2022 07 30 at 16.40.29

 

First computer 1959. Retired from my own computer company 2004.
Hardware - Expert in 1401, and 360, fairly knowledge in PC plus numerous MPU's and MCU's
Major Languages - Machine language, 360 Macro Assembler, Intel Assembler, PL/I and PL1, Pascal, Basic, C plus numerous job control and scripting languages.
My personal scorecard is now 1 PC hardware fix (circa 1982), 1 open source fix (at age 82), and 2 zero day bugs in a major OS.


   
ReplyQuote
Ron
 Ron
(@zander)
Father of a miniature Wookie
Joined: 4 years ago
Posts: 7714
 

@inq I may be misreading his setup, but his OP said

I am using server.write() to send the battery voltage from the Mega and Myclient.read() to read it on the Processing side. Server.write() allows data to be sent in bytes or char form.

At that point and I have NO evidence he yet knows better despite at least 3 of us telling him otherwise that he can write a string and if the attached pic is accurate can also read a string.

I just found something interesting, the API calls I just showed only run on Win, MacOS, *nix, nothing for Arduino so the question is what does he use on the Arduino? I suspect it is another library. I know he is using ethernet.h and here is what I found there. Here is the highlighted part of interest.

// Write size bytes from buffer into the packet
virtual size_t write(const uint8_t *buffer, size_t size);

Isn't that what is needed? Can't we look fairly quickly and superficially at both the ethernet api and the processing api to see that what is needed is there? Am I missing something?

Screen Shot 2022 07 30 at 17.02.53
Screen Shot 2022 07 30 at 16.49.18

 

 

 

First computer 1959. Retired from my own computer company 2004.
Hardware - Expert in 1401, and 360, fairly knowledge in PC plus numerous MPU's and MCU's
Major Languages - Machine language, 360 Macro Assembler, Intel Assembler, PL/I and PL1, Pascal, Basic, C plus numerous job control and scripting languages.
My personal scorecard is now 1 PC hardware fix (circa 1982), 1 open source fix (at age 82), and 2 zero day bugs in a major OS.


   
ReplyQuote
Inq
 Inq
(@inq)
Member
Joined: 3 years ago
Posts: 1904
 
Posted by: @zander

@inq I may be misreading his setup, but his OP said

I am using server.write() to send the battery voltage from the Mega and Myclient.read() to read it on the Processing side. Server.write() allows data to be sent in bytes or char form.

At that point and I have NO evidence he yet knows better despite at least 3 of us telling him otherwise that he can write a string and if the attached pic is accurate can also read a string.

... and he also wrote this,

Posted by: @gameworn

Here is what Arduino says about server.write()

Syntax


server.write(data)
server.write(buffer)
server.write(buffer, size)

Parameters

data: the value to write (byte or char) buffer : an array of data (byte or char) to write size : size of the buffer to write (byte)

Ron, I hear what you are saying, but don't now how to split the voltage into 4 bytes and send then over. I don't know the proper syntax. I scoured the web, but my brain pan had too much teflon in it and nothing stuck. I tried this: I multiplied the voltage by 100 to eliminate the decimal point, then did this:

... which is exactly the three overload possibilities for the Stream object that I contend is the basis for this "server" object he uses as well as file handling, I/O handling, etc.  It is very common for many things to use the Stream class as a basis. 

All that being said... he should be able to send ANY type of data... byte, string, integer, float, double or even a struct full of these variable types that I showed in an example at the beginning.  https://forum.dronebotworkshop.com/arduino/sending-data-over-the-ethernet-using-server-write/#post-31876

The question is... how to receive them.  There should be examples in his documentation on the "Processing" Myclient side.  I believe that anything worth claiming to be a repository server MUST have this capability.  Sending a single byte and string only is WAY to limiting.

 

3 lines of code = InqPortal = Complete IoT, App, Web Server w/ GUI Admin Client, WiFi Manager, Drag & Drop File Manager, OTA, Performance Metrics, Web Socket Comms, Easy App API, All running on ESP8266...
Even usable on ESP-01S - Quickest Start Guide


   
ReplyQuote
Ron
 Ron
(@zander)
Father of a miniature Wookie
Joined: 4 years ago
Posts: 7714
 

@inq Of course you are right, there is a Client side ReadString. He has everything he needs, for some reason he can't see that.

Screen Shot 2022 07 30 at 18.13.48

First computer 1959. Retired from my own computer company 2004.
Hardware - Expert in 1401, and 360, fairly knowledge in PC plus numerous MPU's and MCU's
Major Languages - Machine language, 360 Macro Assembler, Intel Assembler, PL/I and PL1, Pascal, Basic, C plus numerous job control and scripting languages.
My personal scorecard is now 1 PC hardware fix (circa 1982), 1 open source fix (at age 82), and 2 zero day bugs in a major OS.


   
ReplyQuote
Inq
 Inq
(@inq)
Member
Joined: 3 years ago
Posts: 1904
 

Well, it sounds like you were willing to go read the manual for him.  I hope he appreciates your efforts.  

Is there a nut-shell version of what this Processing does with the data once it is received?  If you don't already know, don't go reading about it on my account.  It is idle curiosity.  I'd never use something like that.

VBR,

Inq

3 lines of code = InqPortal = Complete IoT, App, Web Server w/ GUI Admin Client, WiFi Manager, Drag & Drop File Manager, OTA, Performance Metrics, Web Socket Comms, Easy App API, All running on ESP8266...
Even usable on ESP-01S - Quickest Start Guide


   
ReplyQuote
Ron
 Ron
(@zander)
Father of a miniature Wookie
Joined: 4 years ago
Posts: 7714
 

@inq I didn't get that into it, I think it might be a Python shell around normal stuff. 

First computer 1959. Retired from my own computer company 2004.
Hardware - Expert in 1401, and 360, fairly knowledge in PC plus numerous MPU's and MCU's
Major Languages - Machine language, 360 Macro Assembler, Intel Assembler, PL/I and PL1, Pascal, Basic, C plus numerous job control and scripting languages.
My personal scorecard is now 1 PC hardware fix (circa 1982), 1 open source fix (at age 82), and 2 zero day bugs in a major OS.


   
ReplyQuote
robotBuilder
(@robotbuilder)
Member
Joined: 5 years ago
Posts: 2230
 
Posted by: @inq   

Is there a nut-shell version of what this Processing does with the data once it is received?  If you don't already know, don't go reading about it on my account.  It is idle curiosity.  I'd never use something like that.

Processing is a great language with lots of library support to write fast code much easier than using Java itself for a casual part time hobby programmer without any formal training like myself.  I have played with OpenCV and Processing. There are great tutorials from a hyped up presenter on using Processing.

Has @gameworn given the source of the code he is using?  He didn't respond to my request for the source and it kind of kills any interest in helping when given incomplete information.  I have only exchanged data between the computer and an Arduino via the USB cable so using the ethernet library might be different.

 


   
Inq reacted
ReplyQuote
frogandtoad
(@frogandtoad)
Member
Joined: 5 years ago
Posts: 1458
 

@robotbuilder, et, al...

Posted by: @robotbuilder
Posted by: @inq   

Is there a nut-shell version of what this Processing does with the data once it is received?  If you don't already know, don't go reading about it on my account.  It is idle curiosity.  I'd never use something like that.

Processing is a great language with lots of library support to write fast code much easier than using Java itself for a casual part time hobby programmer without any formal training like myself.  I have played with OpenCV and Processing. There are great tutorials from a hyped up presenter on using Processing.

Has @gameworn given the source of the code he is using?  He didn't respond to my request for the source and it kind of kills any interest in helping when given incomplete information.  I have only exchanged data between the computer and an Arduino via the USB cable so using the ethernet library might be different.

 

I wouldn't call Processing a language, as it's really just a programming environment/platform supporting a wide range of libraries and a few languages, using it's own IDE based on the Arduino IDE.  The default language is Java (as per my previous examples).  Python is also available, as are a few others.

I also think that hyped up quirky presenter "Mr Shiffman" is very entertaining and a good teacher 🙂

Getting back to the problem the OP is having, I thought my example was sufficient enough for the OP to solve their issue, but reading back through the OP's responses, it sounds to me that all this talk of pointers, bytes, byte* and sizeof examples etc... and I even saw somewhere mentioned that a byte was "127 to -128", which is true for a Java byte, but not for an Arduino byte which is "0 to 255".  So I think this may have really confused the OP even more, hence why I always advocate using C++ strings in Arduino, *UNLESS* there is a reason not to do so.

So, IMO, I would totally avoid C style programming concepts, and work with the C++ language and it's built in classes as it was intended to be used - For example, from the Arduino side:

String voltage = "14.755";
// ...
server.write(voltage.c_str(), voltage.length());

- Being a string, voltage can be dynamically updated easily from any input source
- Offers built in member functions (convert to a C string array, and obviously length)
- No playing with pointers or the need for type casting

Arduino Language Reference for String

Understanding how to work with classes cannot be underestimated, as they were designed to make a programmers life easier.

Cheers


   
robotBuilder reacted
ReplyQuote
robotBuilder
(@robotbuilder)
Member
Joined: 5 years ago
Posts: 2230
 

@frogandtoad

... and I even saw somewhere mentioned that a byte was "127 to -128", which is true for a Java byte, but not for an Arduino byte which is "0 to 255"

That was me referencing the Processing docs, sorry if it confused anyone.

Thanks for the clarification.  It is good to have someone with your knowledge on the forum.

 


   
ReplyQuote
(@gameworn)
Member
Joined: 4 years ago
Posts: 30
Topic starter  

Hi robotbuilder

I see you asked if I gave the source of the code. I was not sure what you wanted, and I sent processing.org as that is  what I thought you were looking for. Is there anything I can send to help you guys out. I offered the arduino and Processing sketches, but saw no offers.


   
ReplyQuote
robotBuilder
(@robotbuilder)
Member
Joined: 5 years ago
Posts: 2230
 

@gameworn 

I haven't done what you want to do and don't have the hardware anyway for that task so I haven't been following this thread closely. You need to search the net for a working solution that used the Processing language and an Arduino.

The question I did ask was for the source of the code not the source code itself.

 

 


   
ReplyQuote
frogandtoad
(@frogandtoad)
Member
Joined: 5 years ago
Posts: 1458
 

@robotbuilder

Posted by: @robotbuilder

@frogandtoad

... and I even saw somewhere mentioned that a byte was "127 to -128", which is true for a Java byte, but not for an Arduino byte which is "0 to 255"

That was me referencing the Processing docs, sorry if it confused anyone.

Thanks for the clarification.  It is good to have someone with your knowledge on the forum.

 

Thanks, but I'm nothing special, and not a software engineer like many others here... I just love to teach C++ programming as best I know how! 😉

Cheers


   
ReplyQuote
frogandtoad
(@frogandtoad)
Member
Joined: 5 years ago
Posts: 1458
 

@gameworn

Posted by: @gameworn

Hi robotbuilder

I see you asked if I gave the source of the code. I was not sure what you wanted, and I sent processing.org as that is  what I thought you were looking for. Is there anything I can send to help you guys out. I offered the arduino and Processing sketches, but saw no offers.

Are you still stuck on this basic issue, even when many versions of implementing it have been presented to you?  If so, it's about time you show your code if you really want some help.

Cheers


   
ReplyQuote
(@gameworn)
Member
Joined: 4 years ago
Posts: 30
Topic starter  

Hi frogandtoad. here is my Arduino and processing sketch. When I tried to attach the Processing file, I got an error saying this file type was not allowed, so I put it in a text editor

 

 


   
ReplyQuote
Page 5 / 5