I wrote an app which sends an UDP datagram. If I try it on a Computer with Windows 10 on, it works, the other device (a Commercial one) responds correctly. If I execute the same app on an Windows 10 IoT (Raspberry Pi2), the device does not respond. First tought was a Firewall Problem. Thus I had a look on traffic with WireShark. In both cases the datagrams send over the WLAN, are the same. In case of Windows 10 I see the response from the device, in case of IoT there is no response.
Here is the method I use to send the datagram:
private async void FindDevice()
{
DatagramSocket socket = new DatagramSocket();
socket.MessageReceived += Socket_MessageReceived;
IPAddress ipAddressOfSender;
// device must be in the same network
if (IPAddress.TryParse("192.168.0.1", out ipAddressOfSender))
{
byte[] broadcastIpAddress = ipAddressOfSender.GetAddressBytes();
// Assuming to work with a class C IP address, so broadcast address looks like a.b.c.255
broadcastIpAddress[3] = 255;
using (var stream = await socket.GetOutputStreamAsync(new HostName(new IPAddress(broadcastIpAddress).ToString()), SendingPort.ToString()))
{
using (var writer = new DataWriter(stream))
{
byte[] helloSmartPlugs = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x45, 0x44, 0x49, 0x4d, 0x41,
0x58, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xa1, 0xff, 0x5e };
writer.WriteBytes(helloSmartPlugs);
await writer.StoreAsync();
}
}
}
}
In some samples there is also bound the listener port. It doesn't matter, if I do that or not, it still works on Windows, but not IoT. Can that someone explain me? I assumed I Need the listener port.
What could be the reason, the device does not answer in case of IoT? Are there Settings I have to provide with the socket?
Related
I am using a PIC16F1455 to collect data and send to a computer.
I used existing code for simple testing, which uses one end point only. Szymons code is my base, which I have expanded a bit.
I would like to use 3 endpoints for my application.
I have tried to set up the system to have 2 endpoints, but my second endpoint is not working.
I can add that
I have my configuration descriptor as below
The host will ask for Report Descriptor 1, but not for the 2nd one
when trying to send something from Endpoint 2, I can only see that UEP2 is owned by the SIE (Serial Interface Engine)
When I try to alter code so UEP1 should use UEP2 hardware, then it does not work. I did this by changing addresses from 01 to 02 and 81 to 82. Doing this with just one will make it work one way only.
Below my code, which I had with 2 endpoints, which gave no error. Just UEP2 does not work. Missing up interface count and message size will give an error. The comments will tell what changes can be done
I guess that if but channels should be the same, then the same configurations for both end points should be fine, only the endpoint number and addresses need change. Am I right?
I also understand, that UEP0 is used by the system and cannot be used for custom messages.
I need some ideas what could be wrong - how to get a second end point to work. I am out of ideas and I find it hard to google much on this. It should ask for both reports when using 2 end points, right?
// Configuration descriptor
const ConfigStruct ConfigurationDescriptor =
{
{
// Configuration descriptor
0x09, // Size of this descriptor in bytes
0x02, // CONFIGURATION descriptor type
0x29, // Total length of data for this cfg LSB // was 29 // 49 for 2 end points
0x00, // Total length of data for this cfg MSB
1,//INTF, // Number of interfaces in this cfg
0x01, // Index value of this configuration
SCON, // Configuration string index
0xA0, // Attributes (USB powered, wake-up))
0x32, // Max power consumption (in 2 mA steps)
},
{
// Generic HID Interface descriptor
0x09, // Size of this descriptor in bytes
0x04, // INTERFACE descriptor type
IHID, // Interface Number //<- I assume that it stays 1 just using UEP2. Cannot start from 2
0x00, // Alternate Setting Number
0x02, // Number of endpoints in this interface
0x03, // Class code (HID)
0x00, // Subclass code
0x00, // Protocol code 0-none, 1-Keyboard, 2- Mouse
0x00, // Interface string index
// Generic Hid Class-Specific descriptor
0x09, // Size of this descriptor in bytes
0x21, // HID descriptor type
0x11, // HID Spec Release Number in BCD format (1.11) LSB
0x01, // HID Spec Release Number in BCD format (1.11) MSB
0x00, // Country Code (0x00 for Not supported)
0x01, // Number of class descriptors
0x22, // Report descriptor type
0x2F, // Report Size LSB (47 bytes)
0x00, // Report Size MSB
// Generic HID Endpoint 1 In
0x07, // Size of this descriptor in bytes
0x05, // ENDPOINT descriptor type
0x81, // Endpoint Address //<----- changing to 82 will not work
0x03, // Attributes (Interrupt)
HRBC, // Max Packet Size LSB
0x00, // Max Packet Size MSB
0x01, // Interval (1 millisecond)
// Generic HID Endpoint 1 Out
0x07, // Size of this descriptor in bytes
0x05, // ENDPOINT descriptor type
0x01, // Endpoint Address //<--------changing on 02 will not work
0x03, // Attributes (Interrupt)
HRBC, // Max Packet Size LSB
0x00, // Max Packet Size MSB
0x01, // Interval (1 millisecond)
I found the mistake to be in the reply of reports - or descriptors. It would only allow to reply for endpoint 0 (endpoint 1 in hw), meaning when the host would ask for next descriptor, it would not get answer.
if((SetupPacket.bmRequestType & 0x1F) != 0x01 || (SetupPacket.wIndex0 != 0x00)) return;
needs to be
if((SetupPacket.bmRequestType & 0x1F) != 0x01 || (SetupPacket.wIndex0 > (InterfaceCount - 1))) return;
Then it works
Next step is that in PC host side, every end point is a connection by itself
I am hosting the WebBrowser control (using ATL), and I'm looking for a way to block a specific ActiveX control (by CLSID) from loading.
I know ProcessUrlAction can block ActiveX controls, but that's for the entire URL, it doesn't appear to allow you to block a specific ActiveX control by CLSID.
I don't see any specific event interfaces that get notified in MSHTML or the WebBrowser control.
Right now the only solution I can think of is to hook CoCreateInstanceEx and try to block it there.
Any simpler ideas?
ProcessUrlAction can block individual controls as well, you need to check if dwAction=URLACTION_ACTIVEX_RUN, if so then pContext will have the CLSID of the control that is about to run. If it's the one you want to block then set pPolicy to URLPOLICY_DISALLOW and return S_FALSE:
static CLSID CLSID_BAD = {0x00000000, 0x0000, 0x0000, {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}};
STDMETHOD(ProcessUrlAction)(LPCWSTR pwszUrl, DWORD dwAction, BYTE *pPolicy, DWORD cbPolicy, BYTE *pContext, DWORD cbContext, DWORD dwFlags, DWORD dwReserved)
{
if(URLACTION_ACTIVEX_RUN == dwAction && CLSID_BAD == *(CLSID *)pContext)
{
*pPolicy = URLPOLICY_DISALLOW;
return S_FALSE;
}
return INET_E_DEFAULT_ACTION;
}
I've been having problems configuring my STM32 device to function with receiving HID Interrupt OUT transactions, where PC is host device.
I use the standard STM32 CubeMX provided USB Middleware, with edits to allow 2 endpoints, one OUT and one IN. Along with a customized HID report descriptor:
__ALIGN_BEGIN static uint8_t HID_ReportDesc[HID_REPORT_DESC_SIZE] __ALIGN_END =
{
0x06, 0x00, 0xFF, // Usage Page (Vendor Defined 0xFF00)
0x09, 0x01, // Usage (0x01)
0xA1, 0x01, // Collection (Application)
0x15, 0x00, // Logical Minimum (0)
0x26, 0xFF, 0x00, // Logical Maximum (255)
0x75, 0x08, // Report Size (8)
0x95, 0x40, // Report Count (64)
0x09, 0x02, // Usage (0x02)
0x81, 0x00, // Input (Data,Array,Abs,No Wrap,Linear,Preferred State,No Null Position)
0x95, 0x40, // Report Count (64)
0x09, 0x02, // Usage (0x02)
0x91, 0x00, // Output (Data,Array,Abs,No Wrap,Linear,Preferred State,No Null Position,Non-volatile)
0xC0, // End Collection
};
With the use of the USBD HID provided input report transaction function USBD_HID_SendReport, I can then observe the behavior of my device.
On the PC side, using USBLyzer software, I can confirm that the device is recognized by Windows, and configured accordingly, reporting back the descriptors with no errors. I then use HIDAPI to open the device, and read the reported values. This implementation works as expected, giving me communication of data from my device to the host.
However, there is no provided HID Output Report function, leaving me to implement this myself:
uint8_t USBD_HID_ReceiveReport (USBD_HandleTypeDef *pdev, uint8_t *report, uint16_t len){
USBD_HID_HandleTypeDef *hhid = (USBD_HID_HandleTypeDef*)pdev->pClassData;
if(pdev->dev_state == USBD_STATE_CONFIGURED){
if(hhid->state == HID_IDLE){
hhid->state = HID_BUSY;
USBD_LL_PrepareReceive(pdev, HID_EPOUT_ADDR, report, len);
}
}
return USBD_OK;
}
This function makes use of the same structure as the provided USBD_HID_SendReport function, instead using the USBD_LL_PrepareReceive function to prepare the EPOUT address to receive transaction, and then handling transmission through PCD.
After device initialization, I use my implemented USBD_HID_ReceiveReport function in an endless loop, being called repeatedly. I use hid_write in HIDAPI to transfer data to the device once. On debug, the device iterates through the loop, and enters the PCD endpoint transmission on every call. hid_write seemingly doesn't cause an update to my buffer as expected on the device, and USBlyzer reports a 'transaction error' on the OUT report.
Does anyone know the error in my implementation?
i am new to this forum and the whole thing with Processing.
I have a specific question to ask and thanks a lot for your time and thoughts!
How can i connect my Arduino with Ethernet Shield, getting temperature values from a sensor so they can be seen to a processing script?
In a straight Arduino script, one gets the value, connects from the ethernet shield to a server and does what one likes. I have accomplished that.
In my case i want Arduino to just run the script of reading an analog input value from the sensor.
Is it possible?
I have made the serial connection work and read the values alright through the usb, but with ethernet shield? How can i get the value that arduino reads WITHOUT USB/Serial connection?
ps. i am using WAMP server etc, Windows 7
I am trying the UDP connection script example for both arduino and processing from http://arduino.cc/en/Tutorial/UDPSendReceiveString, but
1)i ain't sure if that's what i need,
2)i have excluded from firewall ports 6000, 8888 for my tests and have put the IP address of my Arduino at the Arduino script and "localhost" at the Processing script
THE CODE COPIED FOR BETTER USE HERE
/*
UDPSendReceive.pde:
This sketch receives UDP message strings, prints them to the serial port
and sends an "acknowledge" string back to the sender
A Processing sketch is included at the end of file that can be used to send
and received messages for testing with a computer.
created 21 Aug 2010
by Michael Margolis
This code is in the public domain.
*/
#include <SPI.h> // needed for Arduino versions later than 0018
#include <Ethernet.h>
#include <EthernetUdp.h> // UDP library from: bjoern#cs.stanford.edu 12/30/2008
// Enter a MAC address and IP address for your controller below.
// The IP address will be dependent on your local network:
byte mac[] = {
0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
IPAddress ip(192, 168, 1, 177);
unsigned int localPort = 8888; // local port to listen on
// buffers for receiving and sending data
char packetBuffer[UDP_TX_PACKET_MAX_SIZE]; //buffer to hold incoming packet,
char ReplyBuffer[] = "acknowledged"; // a string to send back
// An EthernetUDP instance to let us send and receive packets over UDP
EthernetUDP Udp;
void setup() {
// start the Ethernet and UDP:
Ethernet.begin(mac,ip);
Udp.begin(localPort);
Serial.begin(9600);
}
void loop() {
// if there's data available, read a packet
int packetSize = Udp.parsePacket();
if(packetSize)
{
Serial.print("Received packet of size ");
Serial.println(packetSize);
Serial.print("From ");
IPAddress remote = Udp.remoteIP();
for (int i =0; i < 4; i++)
{
Serial.print(remote[i], DEC);
if (i < 3)
{
Serial.print(".");
}
}
Serial.print(", port ");
Serial.println(Udp.remotePort());
// read the packet into packetBufffer
Udp.read(packetBuffer,UDP_TX_PACKET_MAX_SIZE);
Serial.println("Contents:");
Serial.println(packetBuffer);
// send a reply, to the IP address and port that sent us the packet we received
Udp.beginPacket(Udp.remoteIP(), Udp.remotePort());
Udp.write(ReplyBuffer);
Udp.endPacket();
}
delay(10);
}
/*
Processing sketch to run with this example
=====================================================
// Processing UDP example to send and receive string data from Arduino
// press any key to send the "Hello Arduino" message
*/
import hypermedia.net.*;
UDP udp; // define the UDP object
void setup() {
udp = new UDP( this, 6000 ); // create a new datagram connection on port 6000
//udp.log( true ); // <-- printout the connection activity
udp.listen( true ); // and wait for incoming message
}
void draw()
{
}
void keyPressed() {
String ip = "192.168.1.177"; // the remote IP address
int port = 8888; // the destination port
udp.send("Hello World", ip, port ); // the message to send
}
void receive( byte[] data ) { // <-- default handler
//void receive( byte[] data, String ip, int port ) { // <-- extended handler
for(int i=0; i < data.length; i++)
print(char(data[i]));
println();
}
Read those values into a file and use that file to send data to processing. http://py.processing.org/reference/createReader.html
Great scheme. Only one problem. It works perfectly on my system. I loaded my Arudino Uno R3 with your Arduino sketch and loaded the Processing sketch as well. Worked like a charm, first try. Didn't change anything on my Arduino, Windows system, Processing (2.0.3), network, etc.
Could be you have a Arduino board problem (unlikely) or an Ethernet shield problem (sadly, more likely). You could have a network problem (even more likely).
Try Wireshark. You will really just be guessing until you take a look at the Wireshark output. Note that Wireshark has filters. You will need them. Filter out all of the non-UDP traffic.
The UDPSendReceive.pde example bundled with the IDE works fine out of the box and displays the correct output on the serial monitor when it receives UDP packets, but seems to disable all the pinOutputs?
#include <SPI.h> // needed for Arduino versions later than 0018
#include <Ethernet.h>
#include <EthernetUdp.h> // UDP library from: bjoern#cs.stanford.edu 12/30/2008
// Enter a MAC address and IP address for your controller below.
// The IP address will be dependent on your local network:
byte mac[] = {
0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
IPAddress ip(192, 168, 1, 177);
unsigned int localPort = 8888; // local port to listen on
// buffers for receiving and sending data
char packetBuffer[UDP_TX_PACKET_MAX_SIZE]; //buffer to hold incoming packet,
char ReplyBuffer[] = "acknowledged"; // a string to send back
// An EthernetUDP instance to let us send and receive packets over UDP
EthernetUDP Udp;
void setup() {
// start the Ethernet and UDP:
Ethernet.begin(mac,ip);
Udp.begin(localPort);
Serial.begin(9600);
pinMode(12, OUTPUT);
}
void loop() {
// if there's data available, read a packet
int packetSize = Udp.parsePacket();
if(packetSize)
{
Serial.print("Received packet of size ");
Serial.println(packetSize);
Serial.print("From ");
IPAddress remote = Udp.remoteIP();
for (int i =0; i < 4; i++)
{
Serial.print(remote[i], DEC);
if (i < 3)
{
Serial.print(".");
}
}
Serial.print(", port ");
Serial.println(Udp.remotePort());
// read the packet into packetBufffer
Udp.read(packetBuffer,UDP_TX_PACKET_MAX_SIZE);
Serial.println("Contents:");
Serial.println(packetBuffer);
// send a reply, to the IP address and port that sent us the packet we received
Udp.beginPacket(Udp.remoteIP(), Udp.remotePort());
Udp.write(ReplyBuffer);
Udp.endPacket();
digitalWrite(12, HIGH); // set the LED on
}
delay(10);
}
Even just changing the loop to be
void loop() {
// if there's data available, read a packet
int packetSize = Udp.parsePacket();
if(packetSize)
{
digitalWrite(12, HIGH);
}
means nothing happens on my outputs (in this case an LED)
Update - Just noticed the SPI include in your code.The SPI library uses pin 12 (for MOSI) so its already reserved.
Previous:
Not sure which Ethernet shield/board you are using, but typically they use SPI protocol to communicate over pins 10-13. Pin 12 is used for MISO. (That's Master In, Slave Out - so its used by the Ethernet device (Slave) as output to the Aurduino's in (Master).
So pins 1 thru 9 should be fine to use as an LED indicator.
The information provided by JDH is correct. Ethernet/SPI uses several pins to communicate with the Ethernet shield. The rest are free for your use. See http://arduino.cc/en/Reference/SPI for some details. The Connections section shows what pins are used by several common Arduino boards. For the Uno and Duemilanove it's pins 10-13.